{"thread":{"id":"5675","subject":"[PATCH] Remove empty ref directories that prevent creating a ref.","startedAt":"2006-09-24T20:33:17Z","lastAt":"2006-09-24T20:46:09Z","messageCount":2,"participants":["Christian Couder","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"27577","messageId":"20060924223317.caf467a3.chriscool@tuxfamily.org","threadId":"5675","inReplyTo":null,"subject":"[PATCH] Remove empty ref directories that prevent creating a ref.","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2006-09-24T20:33:17Z","receivedAt":"2006-09-24T20:33:17Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"Junio wrote:\n\"BTW, the second issue exists without packed ref; currently we\ncannot do\n\n    git branch foo/bar\n    git branch -d foo/bar\n    git branch foo\"\n\nThis patch also add some test cases from Linus and Junio.\n\nSigned-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\n\nThis patch applies to master, that's why it doesn't contain\ntest cases using \"git pack-refs\". I will send a separate patch\nfor them latter. \n\n git-branch.sh     |   10 ++++++++++\n t/t3200-branch.sh |   12 ++++++++++++\n 2 files changed, 22 insertions(+), 0 deletions(-)\n\ndiff --git a/git-branch.sh b/git-branch.sh\nindex e0501ec..9f7ff80 100755\n--- a/git-branch.sh\n+++ b/git-branch.sh\n@@ -112,6 +112,16 @@ rev=$(git-rev-parse --verify \"$head\") ||\n git-check-ref-format \"heads/$branchname\" ||\n \tdie \"we do not like '$branchname' as a branch name.\"\n \n+if [ -d \"$GIT_DIR/refs/heads/$branchname\" ]\n+then\n+\tfor refdir in `find \"$GIT_DIR/refs/heads/$branchname\" -type d | sort -r`\n+\tdo\n+\t\trmdir \"$refdir\" || \\\n+\t\t    die \"Could not delete '$refdir', \" \\\n+\t\t    \"there may still be a ref there.\"\n+\tdone\n+fi\n+\n if [ -e \"$GIT_DIR/refs/heads/$branchname\" ]\n then\n \tif test '' = \"$force\"\ndiff --git a/t/t3200-branch.sh b/t/t3200-branch.sh\nindex 5b04efc..6907cbc 100755\n--- a/t/t3200-branch.sh\n+++ b/t/t3200-branch.sh\n@@ -61,4 +61,16 @@ test_expect_success \\\n \t test -f .git/logs/refs/heads/g/h/i &&\n \t diff expect .git/logs/refs/heads/g/h/i'\n \n+test_expect_success \\\n+    'git branch j/k should work after branch j has been deleted' \\\n+       'git-branch j &&\n+        git-branch -d j &&\n+        git-branch j/k'\n+\n+test_expect_success \\\n+    'git branch l should work after branch l/m has been deleted' \\\n+       'git-branch l/m &&\n+        git-branch -d l/m &&\n+        git-branch l'\n+\n test_done\n-- \n1.4.2.1.g80823-dirty\n"},{"id":"27579","messageId":"7vy7s96lim.fsf@assigned-by-dhcp.cox.net","threadId":"5675","inReplyTo":"20060924223317.caf467a3.chriscool@tuxfamily.org","subject":"Re: [PATCH] Remove empty ref directories that prevent creating a ref.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-09-24T20:46:09Z","receivedAt":"2006-09-24T20:46:09Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Christian Couder <chriscool@tuxfamily.org> writes:\n\n> +if [ -d \"$GIT_DIR/refs/heads/$branchname\" ]\n> +then\n> +\tfor refdir in `find \"$GIT_DIR/refs/heads/$branchname\" -type d | sort -r`\n> +\tdo\n> +\t\trmdir \"$refdir\" || \\\n> +\t\t    die \"Could not delete '$refdir', \" \\\n> +\t\t    \"there may still be a ref there.\"\n> +\tdone\n> +fi\n\nI do not think this loop is safe when $GIT_DIR contains any $IFS\ncharacter.\n"}]}