Bug: Branch Deletion Doesn't Clean Up
- From
- Karl Moskowski <kmoskowski@me.com>
- Date
- Jan 7, 2016, 19:24 UTC
- Message-ID
- <4AC354E1-9E78-42A8-9828-BF1C084A6CBB@me.com>
Apologies if this is a known issue; I was unable to find anything similar in the archive.
The problem is, deleting a branch whose name contains slashes doesn’t delete the directories in .git/refs/heads/.
I’ve tried both git 2.5.4 and 2.6.4 on OS X 10.11 with HFS+ (case-insensitive, case-preserving). Here’s the sequence of commands:
% mkdir Foobar % cd Foobar/ % git init % git checkout -b master % touch file.txt % git add file.txt % git commit -m "add a file" % git checkout -b another/branch
At this point, there's file .git/refs/heads/another/branch
% git checkout master % git branch -d another/branch
At this point, there's an empty directory .git/refs/heads/another/. Only the “leaf” file noted above is deleted, not the directory above it.
% git checkout -b Another/branch
At this point, the file .git/refs/heads/another/branch is re-created. Note the case of its enclosing directory.
% git status On branch Another/branch nothing to commit, working directory clean
% git branch -l another/branch master
Note the difference in case between the last two commands' output. In addition, there's no asterisk next to another/branch indicating it's current.
Because the first branch deletion didn't also delete the enclosing directory tree below .git/refs/heads/, the new branch gets created beneath it. However, there's inconsistent info between the file system and the git database.
It seems like git branch -d ascend the hierarchy (up to .git/refs/heads/), deleting any empty directories.
---- Karl Moskowski <kmoskowski@me.com> <https://about.me/kolpanic>