branch: delete symref branch, not its target
authorRené Scharfe <rene.scharfe@lsrfire.ath.cx>
Thu, 18 Oct 2012 12:05:17 +0000 (14:05 +0200)
committerJunio C Hamano <gitster@pobox.com>
Thu, 18 Oct 2012 21:36:16 +0000 (14:36 -0700)
If a branch that is to be deleted happens to be a symref to another
branch, the current code removes the targeted branch instead of the
one it was called for.

Change this surprising behaviour and delete the symref branch
instead.

Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/branch.c
t/t3200-branch.sh

index 97c736115f6cadfde094228c6258ad19e3e6b06f..5e1e5b4d68d30e7287e94ff48ecea0b076722b4a 100644 (file)
@@ -239,7 +239,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
                        continue;
                }
 
-               if (delete_ref(name, sha1, 0)) {
+               if (delete_ref(name, sha1, REF_NODEREF)) {
                        error(remote_branch
                              ? _("Error deleting remote branch '%s'")
                              : _("Error deleting branch '%s'"),
index 79c8d0142ea72d25a2c403738312a01d0ace50cb..ec5f70eebae65bd5e3b3c7e621ec376e7a31474b 100755 (executable)
@@ -262,6 +262,17 @@ test_expect_success 'config information was renamed, too' \
        "test $(git config branch.s.dummy) = Hello &&
         test_must_fail git config branch.s/s/dummy"
 
+test_expect_success 'deleting a symref' '
+       git branch target &&
+       git symbolic-ref refs/heads/symref refs/heads/target &&
+       sha1=$(git rev-parse symref | cut -c 1-7) &&
+       echo "Deleted branch symref (was $sha1)." >expect &&
+       git branch -d symref >actual &&
+       test_path_is_file .git/refs/heads/target &&
+       test_path_is_missing .git/refs/heads/symref &&
+       test_i18ncmp expect actual
+'
+
 test_expect_success 'renaming a symref is not allowed' \
 '
        git symbolic-ref refs/heads/master2 refs/heads/master &&