Skip to content

Commit bda324c

Browse files
author
Junio C Hamano
committed
git-status: show detached HEAD
This makes git-status to state when you are not on any branch. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4083c2f commit bda324c

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

wt-status.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,18 @@ void wt_status_print(struct wt_status *s)
288288
unsigned char sha1[20];
289289
s->is_initial = get_sha1(s->reference, sha1) ? 1 : 0;
290290

291-
if (s->branch)
291+
if (s->branch) {
292+
const char *on_what = "On branch ";
293+
const char *branch_name = s->branch;
294+
if (!strncmp(branch_name, "refs/heads/", 11))
295+
branch_name += 11;
296+
else if (!strcmp(branch_name, "HEAD")) {
297+
branch_name = "";
298+
on_what = "Not currently on any branch.";
299+
}
292300
color_printf_ln(color(WT_STATUS_HEADER),
293-
"# On branch %s", s->branch);
301+
"# %s%s", on_what, branch_name);
302+
}
294303

295304
if (s->is_initial) {
296305
color_printf_ln(color(WT_STATUS_HEADER), "#");

0 commit comments

Comments
 (0)