From 05eb5635537bac0494bfd8cf41fa5502e05b6fd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillaume=20Pag=C3=A8s?= Date: Tue, 30 Jun 2015 15:01:12 +0200 Subject: [PATCH 1/4] status: factor two rebase-related messages together MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Guillaume Pagès Signed-off-by: Junio C Hamano Signed-off-by: Matthieu Moy Signed-off-by: Junio C Hamano --- wt-status.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/wt-status.c b/wt-status.c index c56c78fb6f..9e0559c0c8 100644 --- a/wt-status.c +++ b/wt-status.c @@ -1026,6 +1026,20 @@ static int split_commit_in_progress(struct wt_status *s) return split_in_progress; } +static void print_rebase_state(struct wt_status *s, + struct wt_status_state *state, + const char *color) +{ + if (state->branch) + status_printf_ln(s, color, + _("You are currently rebasing branch '%s' on '%s'."), + state->branch, + state->onto); + else + status_printf_ln(s, color, + _("You are currently rebasing.")); +} + static void show_rebase_in_progress(struct wt_status *s, struct wt_status_state *state, const char *color) @@ -1033,14 +1047,7 @@ static void show_rebase_in_progress(struct wt_status *s, struct stat st; if (has_unmerged(s)) { - if (state->branch) - status_printf_ln(s, color, - _("You are currently rebasing branch '%s' on '%s'."), - state->branch, - state->onto); - else - status_printf_ln(s, color, - _("You are currently rebasing.")); + print_rebase_state(s, state, color); if (s->hints) { status_printf_ln(s, color, _(" (fix conflicts and then run \"git rebase --continue\")")); @@ -1050,14 +1057,7 @@ static void show_rebase_in_progress(struct wt_status *s, _(" (use \"git rebase --abort\" to check out the original branch)")); } } else if (state->rebase_in_progress || !stat(git_path("MERGE_MSG"), &st)) { - if (state->branch) - status_printf_ln(s, color, - _("You are currently rebasing branch '%s' on '%s'."), - state->branch, - state->onto); - else - status_printf_ln(s, color, - _("You are currently rebasing.")); + print_rebase_state(s, state, color); if (s->hints) status_printf_ln(s, color, _(" (all conflicts fixed: run \"git rebase --continue\")")); From df25e9475bbec86c5c8adaea1d515e7559607def Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillaume=20Pag=C3=A8s?= Date: Tue, 30 Jun 2015 15:01:13 +0200 Subject: [PATCH 2/4] status: differentiate interactive from non-interactive rebases MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Guillaume Pagès Signed-off-by: Junio C Hamano Signed-off-by: Matthieu Moy Signed-off-by: Junio C Hamano --- t/t7512-status-help.sh | 28 ++++++++++++++-------------- wt-status.c | 5 ++++- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/t/t7512-status-help.sh b/t/t7512-status-help.sh index 68ad2d7454..190656dc7e 100755 --- a/t/t7512-status-help.sh +++ b/t/t7512-status-help.sh @@ -136,7 +136,7 @@ test_expect_success 'status during rebase -i when conflicts unresolved' ' ONTO=$(git rev-parse --short rebase_i_conflicts) && test_must_fail git rebase -i rebase_i_conflicts && cat >expected <expected <expected <expected <expected <expected <expected <expected <expected <expected <expected <expected <expected <expected < Date: Mon, 6 Jul 2015 22:56:03 +0200 Subject: [PATCH 3/4] status: give more information during rebase -i MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Junio C Hamano Signed-off-by: Matthieu Moy Signed-off-by: Junio C Hamano --- t/t7512-status-help.sh | 111 +++++++++++++++++++++++++++++++++++++++ wt-status.c | 114 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 225 insertions(+) diff --git a/t/t7512-status-help.sh b/t/t7512-status-help.sh index 190656dc7e..9be0235445 100755 --- a/t/t7512-status-help.sh +++ b/t/t7512-status-help.sh @@ -134,9 +134,13 @@ test_expect_success 'prepare for rebase_i_conflicts' ' test_expect_success 'status during rebase -i when conflicts unresolved' ' test_when_finished "git rebase --abort" && ONTO=$(git rev-parse --short rebase_i_conflicts) && + LAST_COMMIT=$(git rev-parse --short rebase_i_conflicts_second) && test_must_fail git rebase -i rebase_i_conflicts && cat >expected <expected <expected <expected <expected <expected <expected <expected <expected <expected <expected <expected <expected <expected <buf, "exec ") || + starts_with(line->buf, "x ")) + return; + + split = strbuf_split_max(line, ' ', 3); + if (split[0] && split[1]) { + unsigned char sha1[20]; + const char *abbrev; + + /* + * strbuf_split_max left a space. Trim it and re-add + * it after abbreviation. + */ + strbuf_trim(split[1]); + if (!get_sha1(split[1]->buf, sha1)) { + abbrev = find_unique_abbrev(sha1, DEFAULT_ABBREV); + strbuf_reset(split[1]); + strbuf_addf(split[1], "%s ", abbrev); + strbuf_reset(line); + for (i = 0; split[i]; i++) + strbuf_addf(line, "%s", split[i]->buf); + } + } + for (i = 0; split[i]; i++) + strbuf_release(split[i]); + +} + +static void 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) + 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; + strbuf_trim(&line); + if (!line.len) + continue; + abbrev_sha1_in_line(&line); + string_list_append(lines, line.buf); + } +} + +static void show_rebase_information(struct wt_status *s, + struct wt_status_state *state, + const char *color) +{ + if (state->rebase_interactive_in_progress) { + int i; + int nr_lines_to_show = 2; + + 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) + status_printf_ln(s, color, _("No commands done.")); + else { + status_printf_ln(s, color, + Q_("Last command done (%d command done):", + "Last commands done (%d commands done):", + have_done.nr), + have_done.nr); + for (i = (have_done.nr > nr_lines_to_show) + ? have_done.nr - nr_lines_to_show : 0; + i < have_done.nr; + i++) + status_printf_ln(s, color, " %s", have_done.items[i].string); + if (have_done.nr > nr_lines_to_show && s->hints) + status_printf_ln(s, color, + _(" (see more in file %s)"), git_path("rebase-merge/done")); + } + + if (yet_to_do.nr == 0) + status_printf_ln(s, color, + _("No commands remaining.")); + else { + status_printf_ln(s, color, + Q_("Next command to do (%d remaining command):", + "Next commands to do (%d remaining commands):", + yet_to_do.nr), + yet_to_do.nr); + for (i = 0; i < nr_lines_to_show && i < yet_to_do.nr; i++) + status_printf_ln(s, color, " %s", yet_to_do.items[i].string); + if (s->hints) + status_printf_ln(s, color, + _(" (use \"git rebase --edit-todo\" to view and edit)")); + } + string_list_clear(&yet_to_do, 0); + string_list_clear(&have_done, 0); + } +} + static void print_rebase_state(struct wt_status *s, struct wt_status_state *state, const char *color) @@ -1046,6 +1159,7 @@ static void show_rebase_in_progress(struct wt_status *s, { struct stat st; + show_rebase_information(s, state, color); if (has_unmerged(s)) { print_rebase_state(s, state, color); if (s->hints) { From 592e412d0f02313fcab7c7264b4237c298539971 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillaume=20Pag=C3=A8s?= Date: Mon, 6 Jul 2015 22:56:04 +0200 Subject: [PATCH 4/4] status: add new tests for status during rebase -i MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Expand test coverage with one or more than two commands done and with zero, one or more than two commands remaining. Signed-off-by: Guillaume Pagès Signed-off-by: Junio C Hamano Signed-off-by: Matthieu Moy Signed-off-by: Junio C Hamano --- t/t7512-status-help.sh | 87 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/t/t7512-status-help.sh b/t/t7512-status-help.sh index 9be0235445..49d19a3b36 100755 --- a/t/t7512-status-help.sh +++ b/t/t7512-status-help.sh @@ -856,4 +856,91 @@ EOF test_i18ncmp expected actual ' +test_expect_success 'prepare for different number of commits rebased' ' + git reset --hard master && + git checkout -b several_commits && + test_commit one_commit main.txt one && + test_commit two_commit main.txt two && + test_commit three_commit main.txt three && + test_commit four_commit main.txt four +' + +test_expect_success 'status: one command done nothing remaining' ' + FAKE_LINES="exec_exit_15" && + export FAKE_LINES && + test_when_finished "git rebase --abort" && + ONTO=$(git rev-parse --short HEAD~3) && + test_must_fail git rebase -i HEAD~3 && + cat >expected <actual && + test_i18ncmp expected actual +' + +test_expect_success 'status: two commands done with some white lines in done file' ' + FAKE_LINES="1 > exec_exit_15 2 3" && + export FAKE_LINES && + test_when_finished "git rebase --abort" && + ONTO=$(git rev-parse --short HEAD~3) && + COMMIT4=$(git rev-parse --short HEAD) && + COMMIT3=$(git rev-parse --short HEAD^) && + COMMIT2=$(git rev-parse --short HEAD^^) && + test_must_fail git rebase -i HEAD~3 && + cat >expected <actual && + test_i18ncmp expected actual +' + +test_expect_success 'status: two remaining commands with some white lines in todo file' ' + FAKE_LINES="1 2 exec_exit_15 3 > 4" && + export FAKE_LINES && + test_when_finished "git rebase --abort" && + ONTO=$(git rev-parse --short HEAD~4) && + COMMIT4=$(git rev-parse --short HEAD) && + COMMIT3=$(git rev-parse --short HEAD^) && + COMMIT2=$(git rev-parse --short HEAD^^) && + test_must_fail git rebase -i HEAD~4 && + cat >expected <actual && + test_i18ncmp expected actual +' + test_done