From 9c7b0b3fc46e552bde1a65cd1950c3634854332b Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Tue, 26 Sep 2006 07:23:37 +0200 Subject: [PATCH] Remove empty ref directories that prevent creating a ref. This patch also adds test cases from Linus and Junio. Signed-off-by: Christian Couder Signed-off-by: Junio C Hamano --- git-branch.sh | 10 ++++++++++ t/t3200-branch.sh | 12 ++++++++++++ 2 files changed, 22 insertions(+) diff --git a/git-branch.sh b/git-branch.sh index e0501ec23..4f31903d6 100755 --- a/git-branch.sh +++ b/git-branch.sh @@ -112,6 +112,16 @@ rev=$(git-rev-parse --verify "$head") || exit 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 `cd "$GIT_DIR" && \ + find "refs/heads/$branchname" -type d | sort -r` + do + rmdir "$GIT_DIR/$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 5b04efc89..6907cbcd2 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 -- 2.30.2