All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/1] status: display "doing what" information in git status
@ 2011-05-05 21:48 Pierre Habouzit
  2011-05-05 23:06 ` Sverre Rabbelier
  2011-05-05 23:37 ` Junio C Hamano
  0 siblings, 2 replies; 19+ messages in thread
From: Pierre Habouzit @ 2011-05-05 21:48 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Git ML

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 <madcoder@debian.org>
---
 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

^ permalink raw reply related	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2011-05-06 19:18 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-05 21:48 [PATCH 1/1] status: display "doing what" information in git status Pierre Habouzit
2011-05-05 23:06 ` Sverre Rabbelier
2011-05-05 23:26   ` Pierre Habouzit
2011-05-06  7:48     ` Michael J Gruber
2011-05-06  8:04       ` Pierre Habouzit
2011-05-05 23:37 ` Junio C Hamano
2011-05-05 23:39   ` Pierre Habouzit
2011-05-05 23:47     ` Pierre Habouzit
2011-05-05 23:49     ` Junio C Hamano
2011-05-05 23:51       ` Pierre Habouzit
2011-05-06  7:38       ` [PATCH v2] " Pierre Habouzit
2011-05-06 10:13         ` Jakub Narebski
2011-05-06 17:40           ` Pierre Habouzit
2011-05-06 17:29         ` Junio C Hamano
2011-05-06 17:36           ` Pierre Habouzit
2011-05-06 18:24             ` Junio C Hamano
2011-05-06 18:40         ` Matthieu Moy
2011-05-06 18:44           ` Pierre Habouzit
2011-05-06 19:15             ` Matthieu Moy

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.