git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] status: be prepared for not-yet-started interactive rebase
@ 2016-01-22 16:28 Johannes Schindelin
  2016-01-22 16:45 ` Matthieu Moy
  2017-01-26 16:08 ` [PATCH v2 0/1] Let `git status` handle a not-yet-started `rebase -i` gracefully Johannes Schindelin
  0 siblings, 2 replies; 10+ messages in thread
From: Johannes Schindelin @ 2016-01-22 16:28 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: Junio C Hamano, git, Stefan Beller, Matthieu Moy, Guillaume Pages

From: Junio C Hamano <gitster@pobox.com>

Some developers might want to call `git status` in a working
directory where they just started an interactive rebase, but the
edit script is still opened in the editor.

Let's show a meaningful message in such cases.

[jes: suppressed the "No commands remaining" message when the
interactive rebase has not started yet.]

Signed-off-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 wt-status.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/wt-status.c b/wt-status.c
index bba2596..ce8dfda 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -1068,14 +1068,17 @@ static void abbrev_sha1_in_line(struct strbuf *line)
 
 }
 
-static void read_rebase_todolist(const char *fname, struct string_list *lines)
+static int read_rebase_todolist(const char *fname, struct string_list *lines)
 {
 	struct strbuf line = STRBUF_INIT;
 	FILE *f = fopen(git_path("%s", fname), "r");
 
-	if (!f)
+	if (!f) {
+		if (errno == ENOENT)
+			return -1;
 		die_errno("Could not open file %s for reading",
 			  git_path("%s", fname));
+	}
 	while (!strbuf_getline(&line, f, '\n')) {
 		if (line.len && line.buf[0] == comment_line_char)
 			continue;
@@ -1085,6 +1088,7 @@ static void read_rebase_todolist(const char *fname, struct string_list *lines)
 		abbrev_sha1_in_line(&line);
 		string_list_append(lines, line.buf);
 	}
+	return 0;
 }
 
 static void show_rebase_information(struct wt_status *s,
@@ -1098,10 +1102,12 @@ static void show_rebase_information(struct wt_status *s,
 		struct string_list have_done = STRING_LIST_INIT_DUP;
 		struct string_list yet_to_do = STRING_LIST_INIT_DUP;
 
-		read_rebase_todolist("rebase-merge/done", &have_done);
-		read_rebase_todolist("rebase-merge/git-rebase-todo", &yet_to_do);
-
-		if (have_done.nr == 0)
+		if ((read_rebase_todolist("rebase-merge/done", &have_done)) ||
+		    (read_rebase_todolist("rebase-merge/git-rebase-todo",
+				  &yet_to_do)))
+			status_printf_ln(s, color,
+				_("rebase-i not started yet."));
+		else if (have_done.nr == 0)
 			status_printf_ln(s, color, _("No commands done."));
 		else {
 			status_printf_ln(s, color,
@@ -1119,7 +1125,9 @@ static void show_rebase_information(struct wt_status *s,
 					_("  (see more in file %s)"), git_path("rebase-merge/done"));
 		}
 
-		if (yet_to_do.nr == 0)
+		if (have_done.nr == 0)
+			; /* do nothing */
+		else if (yet_to_do.nr == 0)
 			status_printf_ln(s, color,
 					 _("No commands remaining."));
 		else {
-- 
2.7.0.windows.1.7.g55a05c8

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

end of thread, other threads:[~2017-01-27 10:52 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-22 16:28 [PATCH] status: be prepared for not-yet-started interactive rebase Johannes Schindelin
2016-01-22 16:45 ` Matthieu Moy
2016-01-22 17:11   ` Johannes Schindelin
2016-01-22 18:38   ` Junio C Hamano
2016-01-22 19:02     ` Johannes Schindelin
2017-01-26 16:08 ` [PATCH v2 0/1] Let `git status` handle a not-yet-started `rebase -i` gracefully Johannes Schindelin
2017-01-26 16:08   ` [PATCH v2 1/1] status: be prepared for not-yet-started interactive rebase Johannes Schindelin
2017-01-26 18:02     ` Stefan Beller
2017-01-27 10:49       ` Johannes Schindelin
2017-01-26 18:04     ` Matthieu Moy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).