git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] Updated status to show 'Not currently on any branch' in red

From
CPChris Parsons <chris@edendevelopment.co.uk>
Date
May 15, 2008, 19:37 UTC
Message-ID
<612A0CE5-9482-4D27-B2E4-D55F7511A1C2@edendevelopment.co.uk>
Hi all, first post and patch, please be gentle :)

I'm a fairly new user to git and have more than once been burnt by checking out an arbitrary commit and then checking in code on top of that commit. If you realise your mistake quickly, you can reset and reapply the commit to a branch, but if you checkout another branch your commit can disappear and become hard to find.

Therefore as a help to new users I've turned the 'Not currently on any branch' red on 'git status' so that it's harder to miss the fact.

Perhaps git should not allow commits in this case? I'm too much of a novice to know whether that's ever needed, but perhaps someone has a good reason for allowing it.

Thanks and regards Chris

Signed-off-by: Chris Parsons <chris@edendevelopment.co.uk>
---
  wt-status.c |    7 +++++--
  wt-status.h |    1 +
  2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/wt-status.c b/wt-status.c
index a44c543..42a1ff8 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -18,6 +18,7 @@ static char wt_status_colors[][COLOR_MAXLEN] = {
  	"\033[32m", /* WT_STATUS_UPDATED: green */
  	"\033[31m", /* WT_STATUS_CHANGED: red */
  	"\033[31m", /* WT_STATUS_UNTRACKED: red */
+	"\033[31m", /* WT_STATUS_NOBRANCH: red */
  };

  static const char use_add_msg[] =
@@ -315,7 +316,8 @@ void wt_status_print(struct wt_status *s)
  {
  	unsigned char sha1[20];
  	s->is_initial = get_sha1(s->reference, sha1) ? 1 : 0;
-
+  const char* branch_color = color(WT_STATUS_HEADER);
+
  	if (s->branch) {
  		const char *on_what = "On branch ";
  		const char *branch_name = s->branch;
@@ -323,9 +325,10 @@ void wt_status_print(struct wt_status *s)
  			branch_name += 11;
  		else if (!strcmp(branch_name, "HEAD")) {
  			branch_name = "";
+			branch_color = color(WT_STATUS_NOBRANCH);
  			on_what = "Not currently on any branch.";
  		}
-		color_fprintf_ln(s->fp, color(WT_STATUS_HEADER),
+		color_fprintf_ln(s->fp, branch_color,
  			"# %s%s", on_what, branch_name);
  	}

diff --git a/wt-status.h b/wt-status.h
index 7d61410..f0675fd 100644
--- a/wt-status.h
+++ b/wt-status.h
@@ -8,6 +8,7 @@ enum color_wt_status {
  	WT_STATUS_UPDATED,
  	WT_STATUS_CHANGED,
  	WT_STATUS_UNTRACKED,
+	WT_STATUS_NOBRANCH,
  };

  struct wt_status {
-- 
1.5.5.1.249.g3fdb.dirty
Next: Miklos Vajna
Message 1 of 3 in “Updated status to show 'Not currently on any branch' in red”
  1. Updated status to show 'Not currently on any branch' in redChris Parsons, May 15, 2008
  2. Miklos VajnaMay 15, 2008
  3. Jeff KingMay 16, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.