Skip to content

Commit f8fcb57

Browse files
committed
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 <[email protected]>
1 parent a2f5be5 commit f8fcb57

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

builtin-show-branch.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -782,8 +782,8 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
782782
has_head++;
783783
}
784784
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);
787787
}
788788
}
789789

0 commit comments

Comments
 (0)