{"thread":{"id":"2510","subject":"allow git-update-ref create refs with slashes in names","startedAt":"2005-11-14T21:59:05Z","lastAt":"2005-11-14T22:10:59Z","messageCount":2,"participants":["Alex Riesen"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"11845","messageId":"20051114215905.GA5714@steel.home","threadId":"2510","inReplyTo":null,"subject":"allow git-update-ref create refs with slashes in names","fromName":"Alex Riesen","fromEmail":"raa.lkml@gmail.com","sentAt":"2005-11-14T21:59:05Z","receivedAt":"2005-11-14T21:59:05Z","isPatch":false,"sender":{"key":"raa.lkml@gmail.com","avatar":"https://avatars.githubusercontent.com/u/324101?v=4"},"body":"Make git-update-ref create references with slashes in them. git-branch\nand git-checkout already support such reference names.\n\ngit-branch can use git-update-ref to create the references in a more\nformal manner now.\n\n---\n\nthe patch also adds to trivial test cases (just to notice regression,\neven if I don't believe that is possible for such a trivial thing).\n\ndiff --git a/git-branch.sh b/git-branch.sh\nindex 67f113a..11d52fd 100755\n--- a/git-branch.sh\n+++ b/git-branch.sh\n@@ -102,6 +102,5 @@ rev=$(git-rev-parse --verify \"$head\") ||\n git-check-ref-format \"heads/$branchname\" ||\n \tdie \"we do not like '$branchname' as a branch name.\"\n \n-leading=`expr \"refs/heads/$branchname\" : '\\(.*\\)/'` &&\n-mkdir -p \"$GIT_DIR/$leading\" &&\n-echo $rev > \"$GIT_DIR/refs/heads/$branchname\"\n+git update-ref \"refs/heads/$branchname\" $rev\n+\ndiff --git a/t/t3200-branch.sh b/t/t3200-branch.sh\nindex 5f98f64..36f7749 100755\n--- a/t/t3200-branch.sh\n+++ b/t/t3200-branch.sh\n@@ -24,4 +24,12 @@ test_expect_failure \\\n     'git branch --help should not have created a bogus branch' \\\n     'test -f .git/refs/heads/--help'\n \n+test_expect_success \\\n+    'git branch abc should create a branch' \\\n+    'git-branch abc && test -f .git/refs/heads/abc'\n+\n+test_expect_success \\\n+    'git branch a/b/c should create a branch' \\\n+    'git-branch a/b/c && test -f .git/refs/heads/a/b/c'\n+\n test_done\ndiff --git a/update-ref.c b/update-ref.c\nindex d79dc52..aac04e6 100644\n--- a/update-ref.c\n+++ b/update-ref.c\n@@ -49,6 +49,8 @@ int main(int argc, char **argv)\n \t}\n \tpath = strdup(path);\n \tlockpath = mkpath(\"%s.lock\", path);\n+\tif (safe_create_leading_directories(lockpath) < 0)\n+\t\tdie(\"Unable to create all of %s\", lockpath);\n \n \tfd = open(lockpath, O_CREAT | O_EXCL | O_WRONLY, 0666);\n \tif (fd < 0)\n"},{"id":"11846","messageId":"20051114221059.GA20233@steel.home","threadId":"2510","inReplyTo":"20051114215905.GA5714@steel.home","subject":"allow git-update-ref create refs with slashes in names","fromName":"Alex Riesen","fromEmail":"raa.lkml@gmail.com","sentAt":"2005-11-14T22:10:59Z","receivedAt":"2005-11-14T22:10:59Z","isPatch":false,"sender":{"key":"raa.lkml@gmail.com","avatar":"https://avatars.githubusercontent.com/u/324101?v=4"},"body":"Sorry for the previuos untested patch, the tradition seem to be\ncatching... This one is actualy tested.\n\nMake git-update-ref create references with slashes in them. git-branch\nand git-checkout already support such reference names.\n\ngit-branch can use git-update-ref to create the references in a more\nformal manner now.\n\n---\n\nthe patch also adds to trivial test cases (just to notice regression,\neven if I don't believe that is possible for such a trivial thing).\n\ndiff --git a/git-branch.sh b/git-branch.sh\nindex 67f113a..11d52fd 100755\n--- a/git-branch.sh\n+++ b/git-branch.sh\n@@ -102,6 +102,5 @@ rev=$(git-rev-parse --verify \"$head\") ||\n git-check-ref-format \"heads/$branchname\" ||\n \tdie \"we do not like '$branchname' as a branch name.\"\n \n-leading=`expr \"refs/heads/$branchname\" : '\\(.*\\)/'` &&\n-mkdir -p \"$GIT_DIR/$leading\" &&\n-echo $rev > \"$GIT_DIR/refs/heads/$branchname\"\n+git update-ref \"refs/heads/$branchname\" $rev\n+\ndiff --git a/t/t3200-branch.sh b/t/t3200-branch.sh\nindex 5f98f64..36f7749 100755\n--- a/t/t3200-branch.sh\n+++ b/t/t3200-branch.sh\n@@ -24,4 +24,12 @@ test_expect_failure \\\n     'git branch --help should not have created a bogus branch' \\\n     'test -f .git/refs/heads/--help'\n \n+test_expect_success \\\n+    'git branch abc should create a branch' \\\n+    'git-branch abc && test -f .git/refs/heads/abc'\n+\n+test_expect_success \\\n+    'git branch a/b/c should create a branch' \\\n+    'git-branch a/b/c && test -f .git/refs/heads/a/b/c'\n+\n test_done\ndiff --git a/update-ref.c b/update-ref.c\nindex d79dc52..e6fbddb 100644\n--- a/update-ref.c\n+++ b/update-ref.c\n@@ -19,7 +19,8 @@ static int re_verify(const char *path, u\n int main(int argc, char **argv)\n {\n \tchar *hex;\n-\tconst char *refname, *value, *oldval, *path, *lockpath;\n+\tconst char *refname, *value, *oldval, *path;\n+\tchar *lockpath;\n \tunsigned char sha1[20], oldsha1[20], currsha1[20];\n \tint fd, written;\n \n@@ -49,6 +50,8 @@ int main(int argc, char **argv)\n \t}\n \tpath = strdup(path);\n \tlockpath = mkpath(\"%s.lock\", path);\n+\tif (safe_create_leading_directories(lockpath) < 0)\n+\t\tdie(\"Unable to create all of %s\", lockpath);\n \n \tfd = open(lockpath, O_CREAT | O_EXCL | O_WRONLY, 0666);\n \tif (fd < 0)\n"}]}