show-branch --current: do not barf on detached HEAD
The code assumed that there always is the current branch, but the result from resolve_ref() on detached HEAD does not even start with "refs/heads/". Originally noticed and fixed by Stephan Beyer. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
May 26, 2008 at 15:09 UTC
f8fcb57bb45e8d3d8f7921377d6c2503590efc3c
1 file changed
+2
-2
builtin-show-branch.c
+2
-2
@@ -782,8 +782,8 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
782
has_head++;
783
}
784
if (!has_head) {
785
- int pfxlen = strlen("refs/heads/");
786
- append_one_rev(head + pfxlen);
785
+ int offset = !prefixcmp(head, "refs/heads/") ? 11 : 0;
786
+ append_one_rev(head + offset);
787
}
788
}
789