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 <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
René Scharfe committed
Oct 18, 2012 at 14:08 UTC
13baa9fe866f63311af5a5ee318beddb16eb5df4
2 files changed
+13
-11
builtin/branch.c
+11
-8
@@ -251,15 +251,18 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
251
: _("Error deleting branch '%s'"),
252
bname.buf);
253
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));
264
}
265
+ delete_branch_config(bname.buf);
266
}
267
268
free(name);
t/t3200-branch.sh
+2
-3
@@ -265,8 +265,7 @@ test_expect_success 'config information was renamed, too' \
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 &&
268
+ echo "Deleted branch symref (was refs/heads/target)." >expect &&
269
git branch -d symref >actual &&
270
test_path_is_file .git/refs/heads/target &&
271
test_path_is_missing .git/refs/heads/symref &&
@@ -276,7 +275,7 @@ test_expect_success 'deleting a symref' '
275
test_expect_success 'deleting a dangling symref' '
276
git symbolic-ref refs/heads/dangling-symref nowhere &&
277
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 &&
279
git branch -d dangling-symref >actual &&
280
test_path_is_missing .git/refs/heads/dangling-symref &&
281
test_i18ncmp expect actual