Signed-off-by: Nguyễn Thái Ngọc Duy <pclo...@gmail.com>
---
 Seems like a good thing to do.

 t/t7512-status-help.sh | 36 +++++++++++++++----------------
 wt-status.c            | 58 ++++++++++++++++++++++++++++++++++++++++++--------
 wt-status.h            |  1 +
 3 files changed, 68 insertions(+), 27 deletions(-)

diff --git a/t/t7512-status-help.sh b/t/t7512-status-help.sh
index b3f6eb9..096ba6f 100755
--- a/t/t7512-status-help.sh
+++ b/t/t7512-status-help.sh
@@ -76,7 +76,7 @@ test_expect_success 'status when rebase in progress before 
resolving conflicts'
        test_must_fail git rebase HEAD^ --onto HEAD^^ &&
        cat >expected <<-\EOF &&
        # Not currently on any branch.
-       # You are currently rebasing.
+       # You are currently rebasing '\''rebase_conflicts'\''.
        #   (fix conflicts and then run "git rebase --continue")
        #   (use "git rebase --skip" to skip this patch)
        #   (use "git rebase --abort" to check out the original branch)
@@ -102,7 +102,7 @@ test_expect_success 'status when rebase in progress before 
rebase --continue' '
        git add main.txt &&
        cat >expected <<-\EOF &&
        # Not currently on any branch.
-       # You are currently rebasing.
+       # You are currently rebasing '\''rebase_conflicts'\''.
        #   (all conflicts fixed: run "git rebase --continue")
        #
        # Changes to be committed:
@@ -133,7 +133,7 @@ test_expect_success 'status during rebase -i when conflicts 
unresolved' '
        test_must_fail git rebase -i rebase_i_conflicts &&
        cat >expected <<-\EOF &&
        # Not currently on any branch.
-       # You are currently rebasing.
+       # You are currently rebasing '\''rebase_i_conflicts_second'\''.
        #   (fix conflicts and then run "git rebase --continue")
        #   (use "git rebase --skip" to skip this patch)
        #   (use "git rebase --abort" to check out the original branch)
@@ -158,7 +158,7 @@ test_expect_success 'status during rebase -i after 
resolving conflicts' '
        git add main.txt &&
        cat >expected <<-\EOF &&
        # Not currently on any branch.
-       # You are currently rebasing.
+       # You are currently rebasing '\''rebase_i_conflicts_second'\''.
        #   (all conflicts fixed: run "git rebase --continue")
        #
        # Changes to be committed:
@@ -185,7 +185,7 @@ test_expect_success 'status when rebasing -i in edit mode' '
        git rebase -i HEAD~2 &&
        cat >expected <<-\EOF &&
        # Not currently on any branch.
-       # You are currently editing a commit during a rebase.
+       # You are currently editing a commit while rebasing 
'\''rebase_i_edit'\''.
        #   (use "git commit --amend" to amend the current commit)
        #   (use "git rebase --continue" once you are satisfied with your 
changes)
        #
@@ -210,7 +210,7 @@ test_expect_success 'status when splitting a commit' '
        git reset HEAD^ &&
        cat >expected <<-\EOF &&
        # Not currently on any branch.
-       # You are currently splitting a commit during a rebase.
+       # You are currently splitting a commit while rebasing 
'\''split_commit'\''.
        #   (Once your working directory is clean, run "git rebase --continue")
        #
        # Changes not staged for commit:
@@ -240,7 +240,7 @@ test_expect_success 'status after editing the last commit 
with --amend during a
        git commit --amend -m "foo" &&
        cat >expected <<-\EOF &&
        # Not currently on any branch.
-       # You are currently editing a commit during a rebase.
+       # You are currently editing a commit while rebasing '\''amend_last'\''.
        #   (use "git commit --amend" to amend the current commit)
        #   (use "git rebase --continue" once you are satisfied with your 
changes)
        #
@@ -269,7 +269,7 @@ test_expect_success 'status: (continue first edit) second 
edit' '
        git rebase --continue &&
        cat >expected <<-\EOF &&
        # Not currently on any branch.
-       # You are currently editing a commit during a rebase.
+       # You are currently editing a commit while rebasing 
'\''several_edits'\''.
        #   (use "git commit --amend" to amend the current commit)
        #   (use "git rebase --continue" once you are satisfied with your 
changes)
        #
@@ -290,7 +290,7 @@ test_expect_success 'status: (continue first edit) second 
edit and split' '
        git reset HEAD^ &&
        cat >expected <<-\EOF &&
        # Not currently on any branch.
-       # You are currently splitting a commit during a rebase.
+       # You are currently splitting a commit while rebasing 
'\''several_edits'\''.
        #   (Once your working directory is clean, run "git rebase --continue")
        #
        # Changes not staged for commit:
@@ -316,7 +316,7 @@ test_expect_success 'status: (continue first edit) second 
edit and amend' '
        git commit --amend -m "foo" &&
        cat >expected <<-\EOF &&
        # Not currently on any branch.
-       # You are currently editing a commit during a rebase.
+       # You are currently editing a commit while rebasing 
'\''several_edits'\''.
        #   (use "git commit --amend" to amend the current commit)
        #   (use "git rebase --continue" once you are satisfied with your 
changes)
        #
@@ -337,7 +337,7 @@ test_expect_success 'status: (amend first edit) second 
edit' '
        git rebase --continue &&
        cat >expected <<-\EOF &&
        # Not currently on any branch.
-       # You are currently editing a commit during a rebase.
+       # You are currently editing a commit while rebasing 
'\''several_edits'\''.
        #   (use "git commit --amend" to amend the current commit)
        #   (use "git rebase --continue" once you are satisfied with your 
changes)
        #
@@ -359,7 +359,7 @@ test_expect_success 'status: (amend first edit) second edit 
and split' '
        git reset HEAD^ &&
        cat >expected <<-\EOF &&
        # Not currently on any branch.
-       # You are currently splitting a commit during a rebase.
+       # You are currently splitting a commit while rebasing 
'\''several_edits'\''.
        #   (Once your working directory is clean, run "git rebase --continue")
        #
        # Changes not staged for commit:
@@ -386,7 +386,7 @@ test_expect_success 'status: (amend first edit) second edit 
and amend' '
        git commit --amend -m "d" &&
        cat >expected <<-\EOF &&
        # Not currently on any branch.
-       # You are currently editing a commit during a rebase.
+       # You are currently editing a commit while rebasing 
'\''several_edits'\''.
        #   (use "git commit --amend" to amend the current commit)
        #   (use "git rebase --continue" once you are satisfied with your 
changes)
        #
@@ -409,7 +409,7 @@ test_expect_success 'status: (split first edit) second 
edit' '
        git rebase --continue &&
        cat >expected <<-\EOF &&
        # Not currently on any branch.
-       # You are currently editing a commit during a rebase.
+       # You are currently editing a commit while rebasing 
'\''several_edits'\''.
        #   (use "git commit --amend" to amend the current commit)
        #   (use "git rebase --continue" once you are satisfied with your 
changes)
        #
@@ -433,7 +433,7 @@ test_expect_success 'status: (split first edit) second edit 
and split' '
        git reset HEAD^ &&
        cat >expected <<-\EOF &&
        # Not currently on any branch.
-       # You are currently splitting a commit during a rebase.
+       # You are currently splitting a commit while rebasing 
'\''several_edits'\''.
        #   (Once your working directory is clean, run "git rebase --continue")
        #
        # Changes not staged for commit:
@@ -462,7 +462,7 @@ test_expect_success 'status: (split first edit) second edit 
and amend' '
        git commit --amend -m "h" &&
        cat >expected <<-\EOF &&
        # Not currently on any branch.
-       # You are currently editing a commit during a rebase.
+       # You are currently editing a commit while rebasing 
'\''several_edits'\''.
        #   (use "git commit --amend" to amend the current commit)
        #   (use "git rebase --continue" once you are satisfied with your 
changes)
        #
@@ -558,7 +558,7 @@ test_expect_success 'status when bisecting' '
        git bisect good one_bisect &&
        cat >expected <<-\EOF &&
        # Not currently on any branch.
-       # You are currently bisecting.
+       # You are currently bisecting '\''bisect'\''.
        #   (use "git bisect reset" to get back to the original branch)
        #
        nothing to commit (use -u to show untracked files)
@@ -580,7 +580,7 @@ test_expect_success 'status when rebase conflicts with 
statushints disabled' '
        test_must_fail git rebase HEAD^ --onto HEAD^^ &&
        cat >expected <<-\EOF &&
        # Not currently on any branch.
-       # You are currently rebasing.
+       # You are currently rebasing '\''statushints_disabled'\''.
        #
        # Unmerged paths:
        #       both modified:      main.txt
diff --git a/wt-status.c b/wt-status.c
index d7cfe8f..cc7e2d7 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -872,7 +872,13 @@ static void show_rebase_in_progress(struct wt_status *s,
        struct stat st;
 
        if (has_unmerged(s)) {
-               status_printf_ln(s, color, _("You are currently rebasing."));
+               if (state->branch)
+                       status_printf_ln(s, color,
+                                        _("You are currently rebasing '%s'."),
+                                        state->branch);
+               else
+                       status_printf_ln(s, color,
+                                        _("You are currently rebasing."));
                if (advice_status_hints) {
                        status_printf_ln(s, color,
                                _("  (fix conflicts and then run \"git rebase 
--continue\")"));
@@ -882,17 +888,35 @@ 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)) {
-               status_printf_ln(s, color, _("You are currently rebasing."));
+               if (state->branch)
+                       status_printf_ln(s, color,
+                                        _("You are currently rebasing '%s'."),
+                                        state->branch);
+               else
+                       status_printf_ln(s, color,
+                                        _("You are currently rebasing."));
                if (advice_status_hints)
                        status_printf_ln(s, color,
                                _("  (all conflicts fixed: run \"git rebase 
--continue\")"));
        } else if (split_commit_in_progress(s)) {
-               status_printf_ln(s, color, _("You are currently splitting a 
commit during a rebase."));
+               if (state->branch)
+                       status_printf_ln(s, color,
+                                        _("You are currently splitting a 
commit while rebasing '%s'."),
+                                        state->branch);
+               else
+                       status_printf_ln(s, color,
+                                        _("You are currently splitting a 
commit during a rebase."));
                if (advice_status_hints)
                        status_printf_ln(s, color,
                                _("  (Once your working directory is clean, run 
\"git rebase --continue\")"));
        } else {
-               status_printf_ln(s, color, _("You are currently editing a 
commit during a rebase."));
+               if (state->branch)
+                       status_printf_ln(s, color,
+                                        _("You are currently editing a commit 
while rebasing '%s'."),
+                                        state->branch);
+               else
+                       status_printf_ln(s, color,
+                                        _("You are currently editing a commit 
during a rebase."));
                if (advice_status_hints && !s->amend) {
                        status_printf_ln(s, color,
                                _("  (use \"git commit --amend\" to amend the 
current commit)"));
@@ -923,7 +947,7 @@ static void show_bisect_in_progress(struct wt_status *s,
                                struct wt_status_state *state,
                                const char *color)
 {
-       status_printf_ln(s, color, _("You are currently bisecting."));
+       status_printf_ln(s, color, _("You are currently bisecting '%s'."), 
state->branch);
        if (advice_status_hints)
                status_printf_ln(s, color,
                        _("  (use \"git bisect reset\" to get back to the 
original branch)"));
@@ -935,6 +959,7 @@ static void wt_status_print_state(struct wt_status *s)
        const char *state_color = color(WT_STATUS_HEADER, s);
        struct wt_status_state state;
        struct stat st;
+       struct strbuf sb = STRBUF_INIT;
 
        memset(&state, 0, sizeof(state));
 
@@ -947,28 +972,43 @@ static void wt_status_print_state(struct wt_status *s)
                                state.am_empty_patch = 1;
                } else {
                        state.rebase_in_progress = 1;
+                       strbuf_read_file(&sb, 
git_path("rebase-apply/head-name"), 0);
                }
        } else if (!stat(git_path("rebase-merge"), &st)) {
                if (!stat(git_path("rebase-merge/interactive"), &st))
                        state.rebase_interactive_in_progress = 1;
                else
                        state.rebase_in_progress = 1;
+               strbuf_read_file(&sb, git_path("rebase-merge/head-name"), 0);
        } else if (!stat(git_path("CHERRY_PICK_HEAD"), &st)) {
                state.cherry_pick_in_progress = 1;
        }
-       if (!stat(git_path("BISECT_LOG"), &st))
+       if (!stat(git_path("BISECT_LOG"), &st)) {
+               strbuf_read_file(&sb, git_path("BISECT_START"), 0);
                state.bisect_in_progress = 1;
+       }
 
        if (state.merge_in_progress)
                show_merge_in_progress(s, &state, state_color);
        else if (state.am_in_progress)
                show_am_in_progress(s, &state, state_color);
-       else if (state.rebase_in_progress || 
state.rebase_interactive_in_progress)
+       else if (state.rebase_in_progress || 
state.rebase_interactive_in_progress) {
+               while (sb.len && sb.buf[sb.len - 1] == '\n')
+                       strbuf_setlen(&sb, sb.len - 1);
+               if (!prefixcmp(sb.buf, "refs/heads/"))
+                       state.branch = sb.buf + strlen("refs/heads/");
+               else if (!prefixcmp(sb.buf, "refs/"))
+                       state.branch = sb.buf;
                show_rebase_in_progress(s, &state, state_color);
-       else if (state.cherry_pick_in_progress)
+       } else if (state.cherry_pick_in_progress)
                show_cherry_pick_in_progress(s, &state, state_color);
-       if (state.bisect_in_progress)
+       if (state.bisect_in_progress) {
+               while (sb.len && sb.buf[sb.len - 1] == '\n')
+                       strbuf_setlen(&sb, sb.len - 1);
+               state.branch = sb.buf;
                show_bisect_in_progress(s, &state, state_color);
+       }
+       strbuf_release(&sb);
 }
 
 void wt_status_print(struct wt_status *s)
diff --git a/wt-status.h b/wt-status.h
index 236b41f..c5eae29 100644
--- a/wt-status.h
+++ b/wt-status.h
@@ -79,6 +79,7 @@ struct wt_status_state {
        int rebase_interactive_in_progress;
        int cherry_pick_in_progress;
        int bisect_in_progress;
+       const char *branch;
 };
 
 void wt_status_prepare(struct wt_status *s);
-- 
1.8.1.1.459.g5970e58

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to