From d17d76fb838479990550e02b0f37ceaaaa6c599f Mon Sep 17 00:00:00 2001 From: Michael J Gruber Date: Tue, 28 Mar 2017 13:43:00 +0200 Subject: [PATCH] status: show in-progress info for short status Ordinary (long) status shows information about bisect, revert, am, rebase, cherry-pick in progress, and so does git-prompt.sh. status --short currently shows none of this information. Introduce an `--in-progress` argument to git status so that, when used with `--short --branch`, in-progress information is shown next to the branch information. Just like `--branch`, this comes with a config option. The wording for the in-progress information is taken over from git-prompt.sh. --- Documentation/config/status.txt | 4 ++++ Documentation/git-status.txt | 5 +++++ builtin/commit.c | 13 ++++++++++++ t/t7512-status-help.sh | 35 +++++++++++++++++++++++++++++++++ wt-status.c | 32 +++++++++++++++++++++++++++--- wt-status.h | 1 + 6 files changed, 87 insertions(+), 3 deletions(-) diff --git a/Documentation/config/status.txt b/Documentation/config/status.txt index 0fc704ab80b223..f7f3c22c852e78 100644 --- a/Documentation/config/status.txt +++ b/Documentation/config/status.txt @@ -17,6 +17,10 @@ status.aheadBehind:: `--no-ahead-behind` by default in linkgit:git-status[1] for non-porcelain status formats. Defaults to true. +status.inProgress:: + Set to true to enable --in-progress by default in linkgit:git-status[1]. + The option --no-in-progress takes precedence over this variable. + status.displayCommentPrefix:: If set to true, linkgit:git-status[1] will insert a comment prefix before each output line (starting with diff --git a/Documentation/git-status.txt b/Documentation/git-status.txt index 48f46eb2047375..9e977d82c88cc4 100644 --- a/Documentation/git-status.txt +++ b/Documentation/git-status.txt @@ -35,6 +35,11 @@ OPTIONS --show-stash:: Show the number of entries currently stashed away. +-p:: +--in-progress:: + When showing branch and tracking info in short-format, + show in-progress information (BISECTING, MERGING etc.), too. + --porcelain[=]:: Give the output in an easy-to-parse format for scripts. This is similar to the short output, but will remain stable diff --git a/builtin/commit.c b/builtin/commit.c index 7da5f924484d58..8a9cdaadd222db 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -1204,10 +1204,12 @@ static struct status_deferred_config { enum wt_status_format status_format; int show_branch; enum ahead_behind_flags ahead_behind; + int show_in_progress; } status_deferred_config = { STATUS_FORMAT_UNSPECIFIED, -1, /* unspecified */ AHEAD_BEHIND_UNSPECIFIED, + -1 /* unspecified */ }; static void finalize_deferred_config(struct wt_status *s) @@ -1247,6 +1249,10 @@ static void finalize_deferred_config(struct wt_status *s) if (s->ahead_behind_flags == AHEAD_BEHIND_UNSPECIFIED) s->ahead_behind_flags = AHEAD_BEHIND_FULL; + if (use_deferred_config && s->show_in_progress < 0) + s->show_in_progress = status_deferred_config.show_in_progress; + if (s->show_in_progress < 0) + s->show_in_progress = 0; } static void check_fixup_reword_options(int argc, const char *argv[]) { @@ -1442,6 +1448,10 @@ static int git_status_config(const char *k, const char *v, s->show_stash = git_config_bool(k, v); return 0; } + if (!strcmp(k, "status.inProgress")) { + status_deferred_config.show_in_progress = git_config_bool(k, v); + return 0; + } if (!strcmp(k, "status.color") || !strcmp(k, "color.status")) { s->use_color = git_config_colorbool(k, v); return 0; @@ -1515,6 +1525,8 @@ int cmd_status(int argc, const char **argv, const char *prefix) N_("show stash information")), OPT_BOOL(0, "ahead-behind", &s.ahead_behind_flags, N_("compute full ahead/behind values")), + OPT_BOOL('p', "in-progress", &s.show_in_progress, + N_("show in-progress information")), OPT_CALLBACK_F(0, "porcelain", &status_format, N_("version"), N_("machine-readable output"), PARSE_OPT_OPTARG, opt_parse_porcelain), @@ -1680,6 +1692,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix) OPT_BOOL(0, "branch", &s.show_branch, N_("show branch information")), OPT_BOOL(0, "ahead-behind", &s.ahead_behind_flags, N_("compute full ahead/behind values")), + OPT_BOOL(0, "in-progress", &s.show_in_progress, N_("show in-progress information")), OPT_SET_INT(0, "porcelain", &status_format, N_("machine-readable output"), STATUS_FORMAT_PORCELAIN), OPT_SET_INT(0, "long", &status_format, diff --git a/t/t7512-status-help.sh b/t/t7512-status-help.sh index c2ab8a444a8325..5806531bcdb1c7 100755 --- a/t/t7512-status-help.sh +++ b/t/t7512-status-help.sh @@ -93,6 +93,12 @@ Unmerged paths: no changes added to commit (use "git add" and/or "git commit -a") EOF git status --untracked-files=no >actual && + test_cmp expected actual && + cat >expected <actual && test_cmp expected actual ' @@ -154,6 +160,12 @@ Unmerged paths: no changes added to commit (use "git add" and/or "git commit -a") EOF git status --untracked-files=no >actual && + test_cmp expected actual && + cat >expected <actual && test_cmp expected actual ' @@ -619,6 +631,11 @@ You are in the middle of an am session. nothing to commit (use -u to show untracked files) EOF git status --untracked-files=no >actual && + test_cmp expected actual && + cat >expected <<\EOF && +## am_already_exists; AM +EOF + git status --untracked-files=no --short --branch --in-progress >actual && test_cmp expected actual ' @@ -688,6 +705,11 @@ You are currently bisecting, started from branch '\''bisect'\''. nothing to commit (use -u to show untracked files) EOF git status --untracked-files=no >actual && + test_cmp expected actual && + cat >expected <actual && test_cmp expected actual ' @@ -747,6 +769,12 @@ Unmerged paths: no changes added to commit (use "git add" and/or "git commit -a") EOF git status --untracked-files=no >actual && + test_cmp expected actual && + cat >expected <actual && test_cmp expected actual ' @@ -875,9 +903,16 @@ Unmerged paths: no changes added to commit (use "git add" and/or "git commit -a") EOF git status --untracked-files=no >actual && + test_cmp expected actual && + cat >expected <actual && test_cmp expected actual ' + test_expect_success 'status while reverting commit (conflicts resolved)' ' echo reverted >to-revert.txt && git add to-revert.txt && diff --git a/wt-status.c b/wt-status.c index 9f45bf69490e6f..e541fb55a22c6d 100644 --- a/wt-status.c +++ b/wt-status.c @@ -2038,6 +2038,7 @@ static void wt_shortstatus_other(struct string_list_item *it, static void wt_shortstatus_print_tracking(struct wt_status *s) { struct branch *branch; + struct wt_status_state state; const char *header_color = color(WT_STATUS_HEADER, s); const char *branch_color_local = color(WT_STATUS_LOCAL_BRANCH, s); const char *branch_color_remote = color(WT_STATUS_REMOTE_BRANCH, s); @@ -2062,7 +2063,7 @@ static void wt_shortstatus_print_tracking(struct wt_status *s) if (!strcmp(s->branch, "HEAD")) { color_fprintf(s->fp, color(WT_STATUS_NOBRANCH, s), "%s", LABEL(N_("HEAD (no branch)"))); - goto conclude; + goto inprogress; } skip_prefix(branch_name, "refs/heads/", &branch_name); @@ -2075,7 +2076,7 @@ static void wt_shortstatus_print_tracking(struct wt_status *s) 0, s->ahead_behind_flags); if (sti < 0) { if (!base) - goto conclude; + goto inprogress; upstream_is_gone = 1; } @@ -2086,7 +2087,7 @@ static void wt_shortstatus_print_tracking(struct wt_status *s) free(short_base); if (!upstream_is_gone && !sti) - goto conclude; + goto inprogress; color_fprintf(s->fp, header_color, " ["); if (upstream_is_gone) { @@ -2107,6 +2108,31 @@ static void wt_shortstatus_print_tracking(struct wt_status *s) } color_fprintf(s->fp, header_color, "]"); + + inprogress: + if (!s->show_in_progress) + goto conclude; + memset(&state, 0, sizeof(state)); + wt_status_get_state(s->repo, &state, + s->branch && !strcmp(s->branch, "HEAD")); + if (state.merge_in_progress) + color_fprintf(s->fp, header_color, "; %s", LABEL(N_("MERGING"))); + else if (state.am_in_progress) + color_fprintf(s->fp, header_color, "; %s", LABEL(N_("AM"))); + else if (state.rebase_in_progress) + color_fprintf(s->fp, header_color, "; %s", LABEL(N_("REBASE-m"))); + else if (state.rebase_interactive_in_progress) + color_fprintf(s->fp, header_color, "; %s", LABEL(N_("REBASE-i"))); + else if (state.cherry_pick_in_progress) + color_fprintf(s->fp, header_color, "; %s", LABEL(N_("CHERRY-PICKING"))); + else if (state.revert_in_progress) + color_fprintf(s->fp, header_color, "; %s", LABEL(N_("REVERTING"))); + if (state.bisect_in_progress) + color_fprintf(s->fp, header_color, "; %s", LABEL(N_("BISECTING"))); + free(state.branch); + free(state.onto); + free(state.detached_from); + conclude: fputc(s->null_termination ? '\0' : '\n', s->fp); } diff --git a/wt-status.h b/wt-status.h index ab9cc9d8f032b7..ccc448691cb373 100644 --- a/wt-status.h +++ b/wt-status.h @@ -123,6 +123,7 @@ struct wt_status { int commit_template; int show_branch; int show_stash; + int show_in_progress; int hints; enum ahead_behind_flags ahead_behind_flags; int detect_rename;