[PATCH 1/1] status: display "doing what" information in git status

Subsystems: the rest

DORMANTno replies

5 messages, 3 authors, 2016-06-15 · open the first message on its own page

[PATCH 1/1] status: display "doing what" information in git status

From: Pierre Habouzit <hidden>
Date: 2016-06-15 22:51:10

This provides the same information as the git bash prompt about the
current operation that is going on: rebase, merge, am, cherry-pick or
bisect.

This is very useful for "beginners" who don't have their shell prompt set
up for git.

The logic has been largely borrowed from
contrib/completion/git-completion.bash

Signed-off-by: Pierre Habouzit <redacted>
---
 wt-status.c |   74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 74 insertions(+), 0 deletions(-)
diff --git a/wt-status.c b/wt-status.c
index 9f4e0ba..aad0f7f 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -527,6 +527,79 @@ static void wt_status_print_unmerged(struct wt_status *s)
 
 }
 
+static int wt_has_file(const char *what)
+{
+	char path[PATH_MAX];
+
+	return access(git_snpath(path, sizeof(path), "%s", what), F_OK) == 0;
+}
+
+static void wt_status_print_doingwhat(struct wt_status *s)
+{
+	const char *status_header   = color(WT_STATUS_HEADER, s);
+	const char *status_nobranch = color(WT_STATUS_NOBRANCH, s);
+	struct strbuf sb = STRBUF_INIT;
+	char path[PATH_MAX];
+
+	if (wt_has_file("rebase-merge/interactive")) {
+		status_printf(s, status_header, "");
+
+		git_snpath(path, sizeof(path), "%s", "rebase-merge/head-name");
+		strbuf_read_file(&sb, path, 0);
+		strbuf_rtrim(&sb);
+
+		status_printf_more(s, status_nobranch,
+				   _("in the middle of a git rebase -i of %s"),
+				   prefixcmp(sb.buf, "refs/heads/") == 0 ?
+				   sb.buf + 11 : sb.buf);
+	} else if (wt_has_file("rebase-merge")) {
+		status_printf(s, status_header, "");
+
+		git_snpath(path, sizeof(path), "%s", "rebase-merge/head-name");
+		strbuf_read_file(&sb, path, 0);
+		strbuf_rtrim(&sb);
+
+		status_printf_more(s, status_nobranch,
+				   _("in the middle of a git rebase -m on %s"),
+				   prefixcmp(sb.buf, "refs/heads/") == 0 ?
+				   sb.buf + 11 : sb.buf);
+	} else {
+		if (wt_has_file("rebase-apply")) {
+			status_printf(s, status_header, "");
+
+			if (wt_has_file("rebase-apply/rebasing")) {
+				status_printf_more(s, status_nobranch,
+						   _("in the middle of a git rebase"));
+			} else if (wt_has_file("rebase-apply/applying")) {
+				status_printf_more(s, status_nobranch,
+						   _("in the middle of a git am"));
+			} else {
+				status_printf_more(s, status_nobranch,
+						   _("in the middle of a git rebase or am"));
+			}
+		} else if (wt_has_file("MERGE_HEAD")) {
+			status_printf(s, status_header, "");
+
+			status_printf_more(s, status_nobranch,
+					   _("in the middle of a git merge"));
+		} else if (wt_has_file("CHERRY_PICK_HEAD")) {
+			status_printf(s, status_header, "");
+
+			status_printf_more(s, status_nobranch,
+					   _("in the middle of a git cherry-pick"));
+		} else if (wt_has_file("BISECT_LOG")) {
+			status_printf(s, status_header, "");
+
+			status_printf_more(s, status_nobranch,
+					   _("in the middle of a git bisect"));
+		} else {
+			return;
+		}
+	}
+	status_printf_more(s, status_header, "\n");
+	strbuf_release(&sb);
+}
+
 static void wt_status_print_updated(struct wt_status *s)
 {
 	int shown_header = 0;
@@ -732,6 +805,7 @@ void wt_status_print(struct wt_status *s)
 		status_printf_ln(s, color(WT_STATUS_HEADER, s), "");
 	}
 
+	wt_status_print_doingwhat(s);
 	wt_status_print_updated(s);
 	wt_status_print_unmerged(s);
 	wt_status_print_changed(s);
-- 
1.7.5.1.289.g76e37.dirty

Re: [PATCH 1/1] status: display "doing what" information in git status

From: Sverre Rabbelier <hidden>
Date: 2016-06-15 22:51:10

Heya,

On Thu, May 5, 2011 at 23:48, Pierre Habouzit [off-list ref] wrote:
This provides the same information as the git bash prompt about the
current operation that is going on: rebase, merge, am, cherry-pick or
bisect.
Can you show how this will look like?

-- 
Cheers,

Sverre Rabbelier

Re: [PATCH 1/1] status: display "doing what" information in git status

From: Pierre Habouzit <hidden>
Date: 2016-06-15 22:51:10

On Fri, May 06, 2011 at 01:06:45AM +0200, Sverre Rabbelier wrote:
Heya,

On Thu, May 5, 2011 at 23:48, Pierre Habouzit [off-list ref] wrote:
quoted
This provides the same information as the git bash prompt about the
current operation that is going on: rebase, merge, am, cherry-pick or
bisect.
Can you show how this will look like?
Sure, it adds a line on the top with the same color as "not on any
branch" iff there is an ongoing operation.

Of course in this setup it makes no sense since my shell shows it
already, but I'm frustrated when I use git on a remote machine where I
don't have zsh installed or configured, and at work many people would
like to know where they left stuff before they grabbed coffee and talked
for 1h instead of taking 5 minutes ;)
-- 
·O·  Pierre Habouzit
··O                                                madcoder@debian.org
OOO                                                http://www.madism.org

Re: [PATCH 1/1] status: display "doing what" information in git status

From: Michael J Gruber <hidden>
Date: 2016-06-15 22:51:10

Pierre Habouzit venit, vidit, dixit 06.05.2011 01:26:
On Fri, May 06, 2011 at 01:06:45AM +0200, Sverre Rabbelier wrote:
quoted
Heya,

On Thu, May 5, 2011 at 23:48, Pierre Habouzit [off-list ref] wrote:
quoted
This provides the same information as the git bash prompt about the
current operation that is going on: rebase, merge, am, cherry-pick or
bisect.
Can you show how this will look like?
Sure, it adds a line on the top with the same color as "not on any
branch" iff there is an ongoing operation.

Of course in this setup it makes no sense since my shell shows it
already, but I'm frustrated when I use git on a remote machine where I
don't have zsh installed or configured, and at work many people would
like to know where they left stuff before they grabbed coffee and talked
for 1h instead of taking 5 minutes ;)
I think this is useful and nice in the compactified version suggested by
Junio. Be prepared for someone requesting it with "status -s -b" :)

What became of the colouring of the git-prompt, btw? I see you're using
some, and I remember a stalled effort to have this in our shipped
completion. Do have something shareable in that respect?

Michael

Re: [PATCH 1/1] status: display "doing what" information in git status

From: Pierre Habouzit <hidden>
Date: 2016-06-15 22:51:10

On Fri, May 06, 2011 at 09:48:52AM +0200, Michael J Gruber wrote:
Pierre Habouzit venit, vidit, dixit 06.05.2011 01:26:
quoted
On Fri, May 06, 2011 at 01:06:45AM +0200, Sverre Rabbelier wrote:
quoted
Heya,

On Thu, May 5, 2011 at 23:48, Pierre Habouzit [off-list ref] wrote:
quoted
This provides the same information as the git bash prompt about the
current operation that is going on: rebase, merge, am, cherry-pick or
bisect.
Can you show how this will look like?
Sure, it adds a line on the top with the same color as "not on any
branch" iff there is an ongoing operation.

Of course in this setup it makes no sense since my shell shows it
already, but I'm frustrated when I use git on a remote machine where I
don't have zsh installed or configured, and at work many people would
like to know where they left stuff before they grabbed coffee and talked
for 1h instead of taking 5 minutes ;)
I think this is useful and nice in the compactified version suggested by
Junio. Be prepared for someone requesting it with "status -s -b" :)
Well, I've written the logic, it's easy to use :P
What became of the colouring of the git-prompt, btw? I see you're using
some, and I remember a stalled effort to have this in our shipped
completion. Do have something shareable in that respect?
My git prompt predates the bash one, it's here
http://madism.org/~madcoder/dotfiles/config/zsh/60_prompt you're
free to do what you want with that.

-- 
·O·  Pierre Habouzit
··O                                                madcoder@debian.org
OOO                                                http://www.madism.org
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help