threads / patch / 5730

patch, 3 partsWhen creating branch c/d check that branch c does not already exists.

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

## tl;dr

One message between Sep 28, 2006 and Sep 28, 2006. Diffs are folded; open one to read it.

replies: 0people: 1as markdown or json

Christian Couder· Sep 28, 2006, 05:00 UTC · lore

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(-)
Show changes to git-branch.sh +10 −0
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

← back to recent threads