From a07453f90191cd7716712e0ab953d21573f0536e 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 2ff8237f8fc458..da7ed763d7ce50 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 10fecc51a75d47..11fd9527bec919 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 65196a28278bd5..6e7bd165640036 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -1196,10 +1196,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) @@ -1239,6 +1241,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[]) { @@ -1434,6 +1440,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; @@ -1507,6 +1517,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), @@ -1672,6 +1684,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 802f8f704c62eb..eb627c0bd09d7d 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 ' @@ -775,6 +797,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 ' @@ -903,9 +931,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 b5a29083df503e..62995a840b34f6 100644 --- a/wt-status.c +++ b/wt-status.c @@ -2045,6 +2045,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); @@ -2069,7 +2070,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); @@ -2082,7 +2083,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; } @@ -2093,7 +2094,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) { @@ -2114,6 +2115,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 819dcad72300c5..619cf323b324b4 100644 --- a/wt-status.h +++ b/wt-status.h @@ -124,6 +124,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;