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

[PATCH 2/3] When creating branch c/d check that branch c does not already exists.

From
Christian Couder <chriscool@tuxfamily.org>
Date
Mar 24, 2007, 05:30 UTC
Message-ID
<20070324063010.a114722e.chriscool@tuxfamily.org>
In-Reply-To
<20060928065803.2774a63c.chriscool@tuxfamily.org>

With packed refs, there may not be a ".git/refs/heads/c" file when branch c exists. And currently in this case, there is no check to prevent creation of branch c/d.

This should probably be rewritten in C and done after the ref lock has been taken to make sure no race exists though.

This is mainly to make all test cases in "t3210-pack-refs.sh" work.
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 git-branch.sh |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)
diff --git a/git-branch.sh b/git-branch.sh
index 4826c75..4a1e7d9 100755
--- a/git-branch.sh
+++ b/git-branch.sh
@@ -122,6 +122,16 @@ then
 	done
 fi
 
+branchdir=$(dirname $branchname)
+while test "$branchdir" != "."
+do
+	if git-show-ref --verify --quiet -- "refs/heads/$branchdir"
+	then
+		die "$branchdir already exists."
+	fi
+	branchdir=$(dirname $branchdir)
+done
+
 if git-show-ref --verify --quiet -- "refs/heads/$branchname"
 then
 	if test '' = "$force"
-- 
1.4.2.1.g3bab
Previous: Christian CouderNext: Christian Couder
Message 2 of 3 in “Add pack-refs and show-ref test cases.”
  1. 1/3 Add pack-refs and show-ref test cases.Christian Couder, Sep 28, 2006
  2. 2/3 When creating branch c/d check that branch c does not already exists.Christian Couder, Mar 24, 2007
  3. Christian CouderMar 24, 2007

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.