Skip to content

Commit 566c770

Browse files
René Scharfegitster
authored andcommitted
branch: delete symref branch, not its target
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 22ed792 commit 566c770

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

builtin/branch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
239239
continue;
240240
}
241241

242-
if (delete_ref(name, sha1, 0)) {
242+
if (delete_ref(name, sha1, REF_NODEREF)) {
243243
error(remote_branch
244244
? _("Error deleting remote branch '%s'")
245245
: _("Error deleting branch '%s'"),

t/t3200-branch.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,17 @@ test_expect_success 'config information was renamed, too' \
262262
"test $(git config branch.s.dummy) = Hello &&
263263
test_must_fail git config branch.s/s/dummy"
264264

265+
test_expect_success 'deleting a symref' '
266+
git branch target &&
267+
git symbolic-ref refs/heads/symref refs/heads/target &&
268+
sha1=$(git rev-parse symref | cut -c 1-7) &&
269+
echo "Deleted branch symref (was $sha1)." >expect &&
270+
git branch -d symref >actual &&
271+
test_path_is_file .git/refs/heads/target &&
272+
test_path_is_missing .git/refs/heads/symref &&
273+
test_i18ncmp expect actual
274+
'
275+
265276
test_expect_success 'renaming a symref is not allowed' \
266277
'
267278
git symbolic-ref refs/heads/master2 refs/heads/master &&

0 commit comments

Comments
 (0)