Git development
 help / color / mirror / Atom feed
* [PATCH] Remove empty ref directories that prevent creating a ref.
@ 2006-09-24 20:33 Christian Couder
  2006-09-24 20:46 ` Junio C Hamano
  0 siblings, 1 reply; 4+ messages in thread
From: Christian Couder @ 2006-09-24 20:33 UTC (permalink / raw)
  To: Junio Hamano; +Cc: git

Junio wrote:
"BTW, the second issue exists without packed ref; currently we
cannot do

    git branch foo/bar
    git branch -d foo/bar
    git branch foo"

This patch also add some test cases from Linus and Junio.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---

This patch applies to master, that's why it doesn't contain
test cases using "git pack-refs". I will send a separate patch
for them latter. 

 git-branch.sh     |   10 ++++++++++
 t/t3200-branch.sh |   12 ++++++++++++
 2 files changed, 22 insertions(+), 0 deletions(-)

diff --git a/git-branch.sh b/git-branch.sh
index e0501ec..9f7ff80 100755
--- a/git-branch.sh
+++ b/git-branch.sh
@@ -112,6 +112,16 @@ rev=$(git-rev-parse --verify "$head") ||
 git-check-ref-format "heads/$branchname" ||
 	die "we do not like '$branchname' as a branch name."
 
+if [ -d "$GIT_DIR/refs/heads/$branchname" ]
+then
+	for refdir in `find "$GIT_DIR/refs/heads/$branchname" -type d | sort -r`
+	do
+		rmdir "$refdir" || \
+		    die "Could not delete '$refdir', " \
+		    "there may still be a ref there."
+	done
+fi
+
 if [ -e "$GIT_DIR/refs/heads/$branchname" ]
 then
 	if test '' = "$force"
diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh
index 5b04efc..6907cbc 100755
--- a/t/t3200-branch.sh
+++ b/t/t3200-branch.sh
@@ -61,4 +61,16 @@ test_expect_success \
 	 test -f .git/logs/refs/heads/g/h/i &&
 	 diff expect .git/logs/refs/heads/g/h/i'
 
+test_expect_success \
+    'git branch j/k should work after branch j has been deleted' \
+       'git-branch j &&
+        git-branch -d j &&
+        git-branch j/k'
+
+test_expect_success \
+    'git branch l should work after branch l/m has been deleted' \
+       'git-branch l/m &&
+        git-branch -d l/m &&
+        git-branch l'
+
 test_done
-- 
1.4.2.1.g80823-dirty

^ permalink raw reply related	[flat|nested] 4+ messages in thread
* [PATCH] Remove empty ref directories that prevent creating a ref.
@ 2006-09-26  5:23 Christian Couder
  2006-09-26  5:27 ` Junio C Hamano
  0 siblings, 1 reply; 4+ messages in thread
From: Christian Couder @ 2006-09-26  5:23 UTC (permalink / raw)
  To: Junio Hamano; +Cc: git

Junio wrote:
"BTW, the second issue exists without packed ref; currently we
cannot do

    git branch foo/bar
    git branch -d foo/bar
    git branch foo"

This patch also add Linus and Junio test cases.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---

This fixed patch also applies to master, that's why it doesn't
contain test cases using "git pack-refs". I will send a separate
patch for them latter.

 git-branch.sh     |   16 ++++++++++++++++
 t/t3200-branch.sh |   12 ++++++++++++
 2 files changed, 28 insertions(+), 0 deletions(-)

diff --git a/git-branch.sh b/git-branch.sh
index e0501ec..834888d 100755
--- a/git-branch.sh
+++ b/git-branch.sh
@@ -112,6 +112,22 @@ rev=$(git-rev-parse --verify "$head") ||
 git-check-ref-format "heads/$branchname" ||
 	die "we do not like '$branchname' as a branch name."
 
+LF='
+'
+
+if [ -d "$GIT_DIR/refs/heads/$branchname" ]
+then
+	OLD_IFS="$IFS"
+	IFS="$LF"
+	for refdir in `find "$GIT_DIR/refs/heads/$branchname" -type d | sort -r`
+	do
+		rmdir "$refdir" || \
+		    die "Could not delete '$refdir'," \
+		    "there may still be a ref there."
+	done
+	IFS="$OLD_IFS"
+fi
+
 if [ -e "$GIT_DIR/refs/heads/$branchname" ]
 then
 	if test '' = "$force"
diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh
index 5b04efc..6907cbc 100755
--- a/t/t3200-branch.sh
+++ b/t/t3200-branch.sh
@@ -61,4 +61,16 @@ test_expect_success \
 	 test -f .git/logs/refs/heads/g/h/i &&
 	 diff expect .git/logs/refs/heads/g/h/i'
 
+test_expect_success \
+    'git branch j/k should work after branch j has been deleted' \
+       'git-branch j &&
+        git-branch -d j &&
+        git-branch j/k'
+
+test_expect_success \
+    'git branch l should work after branch l/m has been deleted' \
+       'git-branch l/m &&
+        git-branch -d l/m &&
+        git-branch l'
+
 test_done
-- 
1.4.2.1.ged17-dirty

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2006-09-26  5:27 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-09-24 20:33 [PATCH] Remove empty ref directories that prevent creating a ref Christian Couder
2006-09-24 20:46 ` Junio C Hamano
  -- strict thread matches above, loose matches on Subject: below --
2006-09-26  5:23 Christian Couder
2006-09-26  5:27 ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox