git/list[1] front-page[2] threads[3] people[4] search[5] about
 

allow git-update-ref create refs with slashes in names

From
Alex Riesen <raa.lkml@gmail.com>
Date
Nov 14, 2005, 21:59 UTC
Message-ID
<20051114215905.GA5714@steel.home>

Make git-update-ref create references with slashes in them. git-branch and git-checkout already support such reference names.

git-branch can use git-update-ref to create the references in a more formal manner now.

---

the patch also adds to trivial test cases (just to notice regression, even if I don't believe that is possible for such a trivial thing).

diff --git a/git-branch.sh b/git-branch.sh
index 67f113a..11d52fd 100755
--- a/git-branch.sh
+++ b/git-branch.sh
@@ -102,6 +102,5 @@ rev=$(git-rev-parse --verify "$head") ||
 git-check-ref-format "heads/$branchname" ||
 	die "we do not like '$branchname' as a branch name."
 
-leading=`expr "refs/heads/$branchname" : '\(.*\)/'` &&
-mkdir -p "$GIT_DIR/$leading" &&
-echo $rev > "$GIT_DIR/refs/heads/$branchname"
+git update-ref "refs/heads/$branchname" $rev
+
diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh
index 5f98f64..36f7749 100755
--- a/t/t3200-branch.sh
+++ b/t/t3200-branch.sh
@@ -24,4 +24,12 @@ test_expect_failure \
     'git branch --help should not have created a bogus branch' \
     'test -f .git/refs/heads/--help'
 
+test_expect_success \
+    'git branch abc should create a branch' \
+    'git-branch abc && test -f .git/refs/heads/abc'
+
+test_expect_success \
+    'git branch a/b/c should create a branch' \
+    'git-branch a/b/c && test -f .git/refs/heads/a/b/c'
+
 test_done
diff --git a/update-ref.c b/update-ref.c
index d79dc52..aac04e6 100644
--- a/update-ref.c
+++ b/update-ref.c
@@ -49,6 +49,8 @@ int main(int argc, char **argv)
 	}
 	path = strdup(path);
 	lockpath = mkpath("%s.lock", path);
+	if (safe_create_leading_directories(lockpath) < 0)
+		die("Unable to create all of %s", lockpath);
 
 	fd = open(lockpath, O_CREAT | O_EXCL | O_WRONLY, 0666);
 	if (fd < 0)
Next: Alex Riesen
Message 1 of 2 in “allow git-update-ref create refs with slashes in names”
  1. Alex RiesenNov 14, 2005
  2. Alex RiesenNov 14, 2005

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.