Skip to content

Commit 13baa9f

Browse files
René Scharfegitster
authored andcommitted
branch: show targets of deleted symrefs, not sha1s
git branch reports the abbreviated hash of the head commit of a deleted branch to make it easier for a user to undo the operation. For symref branches this doesn't help. Print the symref target instead for them. Signed-off-by: Rene Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0fe700e commit 13baa9f

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

builtin/branch.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -251,15 +251,18 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
251251
: _("Error deleting branch '%s'"),
252252
bname.buf);
253253
ret = 1;
254-
} else {
255-
if (!quiet)
256-
printf(remote_branch
257-
? _("Deleted remote branch %s (was %s).\n")
258-
: _("Deleted branch %s (was %s).\n"),
259-
bname.buf,
260-
find_unique_abbrev(sha1, DEFAULT_ABBREV));
261-
delete_branch_config(bname.buf);
254+
continue;
255+
}
256+
if (!quiet) {
257+
printf(remote_branch
258+
? _("Deleted remote branch %s (was %s).\n")
259+
: _("Deleted branch %s (was %s).\n"),
260+
bname.buf,
261+
(flags & REF_ISSYMREF)
262+
? target
263+
: find_unique_abbrev(sha1, DEFAULT_ABBREV));
262264
}
265+
delete_branch_config(bname.buf);
263266
}
264267

265268
free(name);

t/t3200-branch.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,7 @@ test_expect_success 'config information was renamed, too' \
265265
test_expect_success 'deleting a symref' '
266266
git branch target &&
267267
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 &&
268+
echo "Deleted branch symref (was refs/heads/target)." >expect &&
270269
git branch -d symref >actual &&
271270
test_path_is_file .git/refs/heads/target &&
272271
test_path_is_missing .git/refs/heads/symref &&
@@ -276,7 +275,7 @@ test_expect_success 'deleting a symref' '
276275
test_expect_success 'deleting a dangling symref' '
277276
git symbolic-ref refs/heads/dangling-symref nowhere &&
278277
test_path_is_file .git/refs/heads/dangling-symref &&
279-
echo "Deleted branch dangling-symref (was 0000000)." >expect &&
278+
echo "Deleted branch dangling-symref (was nowhere)." >expect &&
280279
git branch -d dangling-symref >actual &&
281280
test_path_is_missing .git/refs/heads/dangling-symref &&
282281
test_i18ncmp expect actual

0 commit comments

Comments
 (0)