status: give more information during rebase -i

git status gives more information during rebase -i, about the list of command that are done during the rebase. It displays the two last commands executed and the two next lines to be executed. It also gives hints to find the whole files in .git directory. Signed-off-by: Guillaume Pagès <guillaume.pages@ensimag.grenoble-inp.fr> Signed-off-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Guillaume Pagès committed Jul 6, 2015 at 22:56 UTC 84e6fb9da95c1d2407fd2740336371f9604ef6d7
2 files changed +225
t/t7512-status-help.sh
+111
@@ -134,9 +134,13 @@ test_expect_success 'prepare for rebase_i_conflicts' '
134 test_expect_success 'status during rebase -i when conflicts unresolved' '
135 test_when_finished "git rebase --abort" &&
136 ONTO=$(git rev-parse --short rebase_i_conflicts) &&
137 + LAST_COMMIT=$(git rev-parse --short rebase_i_conflicts_second) &&
138 test_must_fail git rebase -i rebase_i_conflicts &&
139 cat >expected <<EOF &&
140 interactive rebase in progress; onto $ONTO
141 +Last command done (1 command done):
142 + pick $LAST_COMMIT one_second
143 +No commands remaining.
144 You are currently rebasing branch '\''rebase_i_conflicts_second'\'' on '\''$ONTO'\''.
145 (fix conflicts and then run "git rebase --continue")
146 (use "git rebase --skip" to skip this patch)
@@ -159,10 +163,14 @@ test_expect_success 'status during rebase -i after resolving conflicts' '
163 git reset --hard rebase_i_conflicts_second &&
164 test_when_finished "git rebase --abort" &&
165 ONTO=$(git rev-parse --short rebase_i_conflicts) &&
166 + LAST_COMMIT=$(git rev-parse --short rebase_i_conflicts_second) &&
167 test_must_fail git rebase -i rebase_i_conflicts &&
168 git add main.txt &&
169 cat >expected <<EOF &&
170 interactive rebase in progress; onto $ONTO
171 +Last command done (1 command done):
172 + pick $LAST_COMMIT one_second
173 +No commands remaining.
174 You are currently rebasing branch '\''rebase_i_conflicts_second'\'' on '\''$ONTO'\''.
175 (all conflicts fixed: run "git rebase --continue")
176
@@ -183,7 +191,9 @@ test_expect_success 'status when rebasing -i in edit mode' '
191 git checkout -b rebase_i_edit &&
192 test_commit one_rebase_i main.txt one &&
193 test_commit two_rebase_i main.txt two &&
194 + COMMIT2=$(git rev-parse --short rebase_i_edit) &&
195 test_commit three_rebase_i main.txt three &&
196 + COMMIT3=$(git rev-parse --short rebase_i_edit) &&
197 FAKE_LINES="1 edit 2" &&
198 export FAKE_LINES &&
199 test_when_finished "git rebase --abort" &&
@@ -191,6 +201,10 @@ test_expect_success 'status when rebasing -i in edit mode' '
201 git rebase -i HEAD~2 &&
202 cat >expected <<EOF &&
203 interactive rebase in progress; onto $ONTO
204 +Last commands done (2 commands done):
205 + pick $COMMIT2 two_rebase_i
206 + edit $COMMIT3 three_rebase_i
207 +No commands remaining.
208 You are currently editing a commit while rebasing branch '\''rebase_i_edit'\'' on '\''$ONTO'\''.
209 (use "git commit --amend" to amend the current commit)
210 (use "git rebase --continue" once you are satisfied with your changes)
@@ -207,8 +221,11 @@ test_expect_success 'status when splitting a commit' '
221 git checkout -b split_commit &&
222 test_commit one_split main.txt one &&
223 test_commit two_split main.txt two &&
224 + COMMIT2=$(git rev-parse --short split_commit) &&
225 test_commit three_split main.txt three &&
226 + COMMIT3=$(git rev-parse --short split_commit) &&
227 test_commit four_split main.txt four &&
228 + COMMIT4=$(git rev-parse --short split_commit) &&
229 FAKE_LINES="1 edit 2 3" &&
230 export FAKE_LINES &&
231 test_when_finished "git rebase --abort" &&
@@ -217,6 +234,12 @@ test_expect_success 'status when splitting a commit' '
234 git reset HEAD^ &&
235 cat >expected <<EOF &&
236 interactive rebase in progress; onto $ONTO
237 +Last commands done (2 commands done):
238 + pick $COMMIT2 two_split
239 + edit $COMMIT3 three_split
240 +Next command to do (1 remaining command):
241 + pick $COMMIT4 four_split
242 + (use "git rebase --edit-todo" to view and edit)
243 You are currently splitting a commit while rebasing branch '\''split_commit'\'' on '\''$ONTO'\''.
244 (Once your working directory is clean, run "git rebase --continue")
245
@@ -239,7 +262,9 @@ test_expect_success 'status after editing the last commit with --amend during a
262 test_commit one_amend main.txt one &&
263 test_commit two_amend main.txt two &&
264 test_commit three_amend main.txt three &&
265 + COMMIT3=$(git rev-parse --short amend_last) &&
266 test_commit four_amend main.txt four &&
267 + COMMIT4=$(git rev-parse --short amend_last) &&
268 FAKE_LINES="1 2 edit 3" &&
269 export FAKE_LINES &&
270 test_when_finished "git rebase --abort" &&
@@ -248,6 +273,11 @@ test_expect_success 'status after editing the last commit with --amend during a
273 git commit --amend -m "foo" &&
274 cat >expected <<EOF &&
275 interactive rebase in progress; onto $ONTO
276 +Last commands done (3 commands done):
277 + pick $COMMIT3 three_amend
278 + edit $COMMIT4 four_amend
279 + (see more in file .git/rebase-merge/done)
280 +No commands remaining.
281 You are currently editing a commit while rebasing branch '\''amend_last'\'' on '\''$ONTO'\''.
282 (use "git commit --amend" to amend the current commit)
283 (use "git rebase --continue" once you are satisfied with your changes)
@@ -273,11 +303,20 @@ test_expect_success 'status: (continue first edit) second edit' '
303 FAKE_LINES="edit 1 edit 2 3" &&
304 export FAKE_LINES &&
305 test_when_finished "git rebase --abort" &&
306 + COMMIT2=$(git rev-parse --short several_edits^^) &&
307 + COMMIT3=$(git rev-parse --short several_edits^) &&
308 + COMMIT4=$(git rev-parse --short several_edits) &&
309 ONTO=$(git rev-parse --short HEAD~3) &&
310 git rebase -i HEAD~3 &&
311 git rebase --continue &&
312 cat >expected <<EOF &&
313 interactive rebase in progress; onto $ONTO
314 +Last commands done (2 commands done):
315 + edit $COMMIT2 two_edits
316 + edit $COMMIT3 three_edits
317 +Next command to do (1 remaining command):
318 + pick $COMMIT4 four_edits
319 + (use "git rebase --edit-todo" to view and edit)
320 You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
321 (use "git commit --amend" to amend the current commit)
322 (use "git rebase --continue" once you are satisfied with your changes)
@@ -294,12 +333,21 @@ test_expect_success 'status: (continue first edit) second edit and split' '
333 FAKE_LINES="edit 1 edit 2 3" &&
334 export FAKE_LINES &&
335 test_when_finished "git rebase --abort" &&
336 + COMMIT2=$(git rev-parse --short several_edits^^) &&
337 + COMMIT3=$(git rev-parse --short several_edits^) &&
338 + COMMIT4=$(git rev-parse --short several_edits) &&
339 ONTO=$(git rev-parse --short HEAD~3) &&
340 git rebase -i HEAD~3 &&
341 git rebase --continue &&
342 git reset HEAD^ &&
343 cat >expected <<EOF &&
344 interactive rebase in progress; onto $ONTO
345 +Last commands done (2 commands done):
346 + edit $COMMIT2 two_edits
347 + edit $COMMIT3 three_edits
348 +Next command to do (1 remaining command):
349 + pick $COMMIT4 four_edits
350 + (use "git rebase --edit-todo" to view and edit)
351 You are currently splitting a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
352 (Once your working directory is clean, run "git rebase --continue")
353
@@ -321,12 +369,21 @@ test_expect_success 'status: (continue first edit) second edit and amend' '
369 FAKE_LINES="edit 1 edit 2 3" &&
370 export FAKE_LINES &&
371 test_when_finished "git rebase --abort" &&
372 + COMMIT2=$(git rev-parse --short several_edits^^) &&
373 + COMMIT3=$(git rev-parse --short several_edits^) &&
374 + COMMIT4=$(git rev-parse --short several_edits) &&
375 ONTO=$(git rev-parse --short HEAD~3) &&
376 git rebase -i HEAD~3 &&
377 git rebase --continue &&
378 git commit --amend -m "foo" &&
379 cat >expected <<EOF &&
380 interactive rebase in progress; onto $ONTO
381 +Last commands done (2 commands done):
382 + edit $COMMIT2 two_edits
383 + edit $COMMIT3 three_edits
384 +Next command to do (1 remaining command):
385 + pick $COMMIT4 four_edits
386 + (use "git rebase --edit-todo" to view and edit)
387 You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
388 (use "git commit --amend" to amend the current commit)
389 (use "git rebase --continue" once you are satisfied with your changes)
@@ -343,12 +400,21 @@ test_expect_success 'status: (amend first edit) second edit' '
400 FAKE_LINES="edit 1 edit 2 3" &&
401 export FAKE_LINES &&
402 test_when_finished "git rebase --abort" &&
403 + COMMIT2=$(git rev-parse --short several_edits^^) &&
404 + COMMIT3=$(git rev-parse --short several_edits^) &&
405 + COMMIT4=$(git rev-parse --short several_edits) &&
406 ONTO=$(git rev-parse --short HEAD~3) &&
407 git rebase -i HEAD~3 &&
408 git commit --amend -m "a" &&
409 git rebase --continue &&
410 cat >expected <<EOF &&
411 interactive rebase in progress; onto $ONTO
412 +Last commands done (2 commands done):
413 + edit $COMMIT2 two_edits
414 + edit $COMMIT3 three_edits
415 +Next command to do (1 remaining command):
416 + pick $COMMIT4 four_edits
417 + (use "git rebase --edit-todo" to view and edit)
418 You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
419 (use "git commit --amend" to amend the current commit)
420 (use "git rebase --continue" once you are satisfied with your changes)
@@ -366,12 +432,21 @@ test_expect_success 'status: (amend first edit) second edit and split' '
432 export FAKE_LINES &&
433 test_when_finished "git rebase --abort" &&
434 ONTO=$(git rev-parse --short HEAD~3) &&
435 + COMMIT2=$(git rev-parse --short several_edits^^) &&
436 + COMMIT3=$(git rev-parse --short several_edits^) &&
437 + COMMIT4=$(git rev-parse --short several_edits) &&
438 git rebase -i HEAD~3 &&
439 git commit --amend -m "b" &&
440 git rebase --continue &&
441 git reset HEAD^ &&
442 cat >expected <<EOF &&
443 interactive rebase in progress; onto $ONTO
444 +Last commands done (2 commands done):
445 + edit $COMMIT2 two_edits
446 + edit $COMMIT3 three_edits
447 +Next command to do (1 remaining command):
448 + pick $COMMIT4 four_edits
449 + (use "git rebase --edit-todo" to view and edit)
450 You are currently splitting a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
451 (Once your working directory is clean, run "git rebase --continue")
452
@@ -393,6 +468,9 @@ test_expect_success 'status: (amend first edit) second edit and amend' '
468 FAKE_LINES="edit 1 edit 2 3" &&
469 export FAKE_LINES &&
470 test_when_finished "git rebase --abort" &&
471 + COMMIT2=$(git rev-parse --short several_edits^^) &&
472 + COMMIT3=$(git rev-parse --short several_edits^) &&
473 + COMMIT4=$(git rev-parse --short several_edits) &&
474 ONTO=$(git rev-parse --short HEAD~3) &&
475 git rebase -i HEAD~3 &&
476 git commit --amend -m "c" &&
@@ -400,6 +478,12 @@ test_expect_success 'status: (amend first edit) second edit and amend' '
478 git commit --amend -m "d" &&
479 cat >expected <<EOF &&
480 interactive rebase in progress; onto $ONTO
481 +Last commands done (2 commands done):
482 + edit $COMMIT2 two_edits
483 + edit $COMMIT3 three_edits
484 +Next command to do (1 remaining command):
485 + pick $COMMIT4 four_edits
486 + (use "git rebase --edit-todo" to view and edit)
487 You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
488 (use "git commit --amend" to amend the current commit)
489 (use "git rebase --continue" once you are satisfied with your changes)
@@ -416,6 +500,9 @@ test_expect_success 'status: (split first edit) second edit' '
500 FAKE_LINES="edit 1 edit 2 3" &&
501 export FAKE_LINES &&
502 test_when_finished "git rebase --abort" &&
503 + COMMIT2=$(git rev-parse --short several_edits^^) &&
504 + COMMIT3=$(git rev-parse --short several_edits^) &&
505 + COMMIT4=$(git rev-parse --short several_edits) &&
506 ONTO=$(git rev-parse --short HEAD~3) &&
507 git rebase -i HEAD~3 &&
508 git reset HEAD^ &&
@@ -424,6 +511,12 @@ test_expect_success 'status: (split first edit) second edit' '
511 git rebase --continue &&
512 cat >expected <<EOF &&
513 interactive rebase in progress; onto $ONTO
514 +Last commands done (2 commands done):
515 + edit $COMMIT2 two_edits
516 + edit $COMMIT3 three_edits
517 +Next command to do (1 remaining command):
518 + pick $COMMIT4 four_edits
519 + (use "git rebase --edit-todo" to view and edit)
520 You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
521 (use "git commit --amend" to amend the current commit)
522 (use "git rebase --continue" once you are satisfied with your changes)
@@ -440,6 +533,9 @@ test_expect_success 'status: (split first edit) second edit and split' '
533 FAKE_LINES="edit 1 edit 2 3" &&
534 export FAKE_LINES &&
535 test_when_finished "git rebase --abort" &&
536 + COMMIT2=$(git rev-parse --short several_edits^^) &&
537 + COMMIT3=$(git rev-parse --short several_edits^) &&
538 + COMMIT4=$(git rev-parse --short several_edits) &&
539 ONTO=$(git rev-parse --short HEAD~3) &&
540 git rebase -i HEAD~3 &&
541 git reset HEAD^ &&
@@ -449,6 +545,12 @@ test_expect_success 'status: (split first edit) second edit and split' '
545 git reset HEAD^ &&
546 cat >expected <<EOF &&
547 interactive rebase in progress; onto $ONTO
548 +Last commands done (2 commands done):
549 + edit $COMMIT2 two_edits
550 + edit $COMMIT3 three_edits
551 +Next command to do (1 remaining command):
552 + pick $COMMIT4 four_edits
553 + (use "git rebase --edit-todo" to view and edit)
554 You are currently splitting a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
555 (Once your working directory is clean, run "git rebase --continue")
556
@@ -470,6 +572,9 @@ test_expect_success 'status: (split first edit) second edit and amend' '
572 FAKE_LINES="edit 1 edit 2 3" &&
573 export FAKE_LINES &&
574 test_when_finished "git rebase --abort" &&
575 + COMMIT2=$(git rev-parse --short several_edits^^) &&
576 + COMMIT3=$(git rev-parse --short several_edits^) &&
577 + COMMIT4=$(git rev-parse --short several_edits) &&
578 ONTO=$(git rev-parse --short HEAD~3) &&
579 git rebase -i HEAD~3 &&
580 git reset HEAD^ &&
@@ -479,6 +584,12 @@ test_expect_success 'status: (split first edit) second edit and amend' '
584 git commit --amend -m "h" &&
585 cat >expected <<EOF &&
586 interactive rebase in progress; onto $ONTO
587 +Last commands done (2 commands done):
588 + edit $COMMIT2 two_edits
589 + edit $COMMIT3 three_edits
590 +Next command to do (1 remaining command):
591 + pick $COMMIT4 four_edits
592 + (use "git rebase --edit-todo" to view and edit)
593 You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
594 (use "git commit --amend" to amend the current commit)
595 (use "git rebase --continue" once you are satisfied with your changes)
wt-status.c
+114
@@ -1026,6 +1026,119 @@ static int split_commit_in_progress(struct wt_status *s)
1026 return split_in_progress;
1027 }
1028
1029 +/*
1030 + * Turn
1031 + * "pick d6a2f0303e897ec257dd0e0a39a5ccb709bc2047 some message"
1032 + * into
1033 + * "pick d6a2f03 some message"
1034 + *
1035 + * The function assumes that the line does not contain useless spaces
1036 + * before or after the command.
1037 + */
1038 +static void abbrev_sha1_in_line(struct strbuf *line)
1039 +{
1040 + struct strbuf **split;
1041 + int i;
1042 +
1043 + if (starts_with(line->buf, "exec ") ||
1044 + starts_with(line->buf, "x "))
1045 + return;
1046 +
1047 + split = strbuf_split_max(line, ' ', 3);
1048 + if (split[0] && split[1]) {
1049 + unsigned char sha1[20];
1050 + const char *abbrev;
1051 +
1052 + /*
1053 + * strbuf_split_max left a space. Trim it and re-add
1054 + * it after abbreviation.
1055 + */
1056 + strbuf_trim(split[1]);
1057 + if (!get_sha1(split[1]->buf, sha1)) {
1058 + abbrev = find_unique_abbrev(sha1, DEFAULT_ABBREV);
1059 + strbuf_reset(split[1]);
1060 + strbuf_addf(split[1], "%s ", abbrev);
1061 + strbuf_reset(line);
1062 + for (i = 0; split[i]; i++)
1063 + strbuf_addf(line, "%s", split[i]->buf);
1064 + }
1065 + }
1066 + for (i = 0; split[i]; i++)
1067 + strbuf_release(split[i]);
1068 +
1069 +}
1070 +
1071 +static void read_rebase_todolist(const char *fname, struct string_list *lines)
1072 +{
1073 + struct strbuf line = STRBUF_INIT;
1074 + FILE *f = fopen(git_path("%s", fname), "r");
1075 +
1076 + if (!f)
1077 + die_errno("Could not open file %s for reading",
1078 + git_path("%s", fname));
1079 + while (!strbuf_getline(&line, f, '\n')) {
1080 + if (line.len && line.buf[0] == comment_line_char)
1081 + continue;
1082 + strbuf_trim(&line);
1083 + if (!line.len)
1084 + continue;
1085 + abbrev_sha1_in_line(&line);
1086 + string_list_append(lines, line.buf);
1087 + }
1088 +}
1089 +
1090 +static void show_rebase_information(struct wt_status *s,
1091 + struct wt_status_state *state,
1092 + const char *color)
1093 +{
1094 + if (state->rebase_interactive_in_progress) {
1095 + int i;
1096 + int nr_lines_to_show = 2;
1097 +
1098 + struct string_list have_done = STRING_LIST_INIT_DUP;
1099 + struct string_list yet_to_do = STRING_LIST_INIT_DUP;
1100 +
1101 + read_rebase_todolist("rebase-merge/done", &have_done);
1102 + read_rebase_todolist("rebase-merge/git-rebase-todo", &yet_to_do);
1103 +
1104 + if (have_done.nr == 0)
1105 + status_printf_ln(s, color, _("No commands done."));
1106 + else {
1107 + status_printf_ln(s, color,
1108 + Q_("Last command done (%d command done):",
1109 + "Last commands done (%d commands done):",
1110 + have_done.nr),
1111 + have_done.nr);
1112 + for (i = (have_done.nr > nr_lines_to_show)
1113 + ? have_done.nr - nr_lines_to_show : 0;
1114 + i < have_done.nr;
1115 + i++)
1116 + status_printf_ln(s, color, " %s", have_done.items[i].string);
1117 + if (have_done.nr > nr_lines_to_show && s->hints)
1118 + status_printf_ln(s, color,
1119 + _(" (see more in file %s)"), git_path("rebase-merge/done"));
1120 + }
1121 +
1122 + if (yet_to_do.nr == 0)
1123 + status_printf_ln(s, color,
1124 + _("No commands remaining."));
1125 + else {
1126 + status_printf_ln(s, color,
1127 + Q_("Next command to do (%d remaining command):",
1128 + "Next commands to do (%d remaining commands):",
1129 + yet_to_do.nr),
1130 + yet_to_do.nr);
1131 + for (i = 0; i < nr_lines_to_show && i < yet_to_do.nr; i++)
1132 + status_printf_ln(s, color, " %s", yet_to_do.items[i].string);
1133 + if (s->hints)
1134 + status_printf_ln(s, color,
1135 + _(" (use \"git rebase --edit-todo\" to view and edit)"));
1136 + }
1137 + string_list_clear(&yet_to_do, 0);
1138 + string_list_clear(&have_done, 0);
1139 + }
1140 +}
1141 +
1142 static void print_rebase_state(struct wt_status *s,
1143 struct wt_status_state *state,
1144 const char *color)
@@ -1046,6 +1159,7 @@ static void show_rebase_in_progress(struct wt_status *s,
1159 {
1160 struct stat st;
1161
1162 + show_rebase_information(s, state, color);
1163 if (has_unmerged(s)) {
1164 print_rebase_state(s, state, color);
1165 if (s->hints) {