status: be prepared for not-yet-started interactive rebase
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. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johannes Schindelin committed
Jan 26, 2017 at 17:08 UTC
df9ded4984ca9a2d8da9007049f4fb5275eaa3ac
2 files changed
+29
-4
t/t7512-status-help.sh
+19
@@ -944,4 +944,23 @@ EOF
944
test_i18ncmp expected actual
945
'
946
947
+test_expect_success 'status: handle not-yet-started rebase -i gracefully' '
948
+ ONTO=$(git rev-parse --short HEAD^) &&
949
+ COMMIT=$(git rev-parse --short HEAD) &&
950
+ EDITOR="git status --untracked-files=no >actual" git rebase -i HEAD^ &&
951
+ cat >expected <<EOF &&
952
+On branch several_commits
953
+No commands done.
954
+Next command to do (1 remaining command):
955
+ pick $COMMIT four_commit
956
+ (use "git rebase --edit-todo" to view and edit)
957
+You are currently editing a commit while rebasing branch '\''several_commits'\'' on '\''$ONTO'\''.
958
+ (use "git commit --amend" to amend the current commit)
959
+ (use "git rebase --continue" once you are satisfied with your changes)
960
+
961
+nothing to commit (use -u to show untracked files)
962
+EOF
963
+ test_i18ncmp expected actual
964
+'
965
+
966
test_done
wt-status.c
+10
-4
@@ -1072,14 +1072,17 @@ static void abbrev_sha1_in_line(struct strbuf *line)
1072
strbuf_list_free(split);
1073
}
1074
1075
-static void read_rebase_todolist(const char *fname, struct string_list *lines)
1075
+static int read_rebase_todolist(const char *fname, struct string_list *lines)
1076
{
1077
struct strbuf line = STRBUF_INIT;
1078
FILE *f = fopen(git_path("%s", fname), "r");
1079
1080
- if (!f)
1080
+ if (!f) {
1081
+ if (errno == ENOENT)
1082
+ return -1;
1083
die_errno("Could not open file %s for reading",
1084
git_path("%s", fname));
1085
+ }
1086
while (!strbuf_getline_lf(&line, f)) {
1087
if (line.len && line.buf[0] == comment_line_char)
1088
continue;
@@ -1089,6 +1092,7 @@ static void read_rebase_todolist(const char *fname, struct string_list *lines)
1092
abbrev_sha1_in_line(&line);
1093
string_list_append(lines, line.buf);
1094
}
1095
+ return 0;
1096
}
1097
1098
static void show_rebase_information(struct wt_status *s,
@@ -1103,8 +1107,10 @@ static void show_rebase_information(struct wt_status *s,
1107
struct string_list yet_to_do = STRING_LIST_INIT_DUP;
1108
1109
read_rebase_todolist("rebase-merge/done", &have_done);
1106
- read_rebase_todolist("rebase-merge/git-rebase-todo", &yet_to_do);
1107
-
1110
+ if (read_rebase_todolist("rebase-merge/git-rebase-todo",
1111
+ &yet_to_do))
1112
+ status_printf_ln(s, color,
1113
+ _("git-rebase-todo is missing."));
1114
if (have_done.nr == 0)
1115
status_printf_ln(s, color, _("No commands done."));
1116
else {