Skip to content

Commit 46c1008

Browse files
committed
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.
1 parent 700c83d commit 46c1008

6 files changed

Lines changed: 87 additions & 3 deletions

File tree

Documentation/config/status.adoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ Example:
4242
This would show comparisons against both the configured upstream and push
4343
tracking branches for the current branch.
4444
45+
status.inProgress::
46+
Set to true to enable `--in-progress` by default in linkgit:git-status[1].
47+
The option `--no-in-progress` takes precedence over this variable.
48+
4549
status.displayCommentPrefix::
4650
If set to true, linkgit:git-status[1] will insert a comment
4751
prefix before each output line (starting with

Documentation/git-status.adoc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ OPTIONS
3636
`--show-stash`::
3737
Show the number of entries currently stashed away.
3838

39+
`-p`::
40+
`--in-progress`::
41+
When showing branch and tracking info in short-format,
42+
show in-progress information (BISECTING, MERGING etc.), too.
43+
3944
`--porcelain[=<version>]`::
4045
Give the output in an easy-to-parse format for scripts.
4146
This is similar to the short output, but will remain stable

builtin/commit.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,10 +1247,12 @@ static struct status_deferred_config {
12471247
enum wt_status_format status_format;
12481248
int show_branch;
12491249
enum ahead_behind_flags ahead_behind;
1250+
int show_in_progress;
12501251
} status_deferred_config = {
12511252
STATUS_FORMAT_UNSPECIFIED,
12521253
-1, /* unspecified */
12531254
AHEAD_BEHIND_UNSPECIFIED,
1255+
-1 /* unspecified */
12541256
};
12551257

12561258
static void finalize_deferred_config(struct wt_status *s)
@@ -1290,6 +1292,10 @@ static void finalize_deferred_config(struct wt_status *s)
12901292

12911293
if (s->ahead_behind_flags == AHEAD_BEHIND_UNSPECIFIED)
12921294
s->ahead_behind_flags = AHEAD_BEHIND_FULL;
1295+
if (use_deferred_config && s->show_in_progress < 0)
1296+
s->show_in_progress = status_deferred_config.show_in_progress;
1297+
if (s->show_in_progress < 0)
1298+
s->show_in_progress = 0;
12931299
}
12941300

12951301
static void check_fixup_reword_options(int argc, const char *argv[]) {
@@ -1483,6 +1489,10 @@ static int git_status_config(const char *k, const char *v,
14831489
s->show_stash = git_config_bool(k, v);
14841490
return 0;
14851491
}
1492+
if (!strcmp(k, "status.inProgress")) {
1493+
status_deferred_config.show_in_progress = git_config_bool(k, v);
1494+
return 0;
1495+
}
14861496
if (!strcmp(k, "status.color") || !strcmp(k, "color.status")) {
14871497
s->use_color = git_config_colorbool(k, v);
14881498
return 0;
@@ -1555,6 +1565,8 @@ struct repository *repo UNUSED)
15551565
N_("show stash information")),
15561566
OPT_BOOL(0, "ahead-behind", &s.ahead_behind_flags,
15571567
N_("compute full ahead/behind values")),
1568+
OPT_BOOL('p', "in-progress", &s.show_in_progress,
1569+
N_("show in-progress information")),
15581570
OPT_CALLBACK_F(0, "porcelain", &status_format,
15591571
N_("version"), N_("machine-readable output"),
15601572
PARSE_OPT_OPTARG, opt_parse_porcelain),
@@ -1754,6 +1766,7 @@ int cmd_commit(int argc,
17541766
OPT_BOOL(0, "branch", &s.show_branch, N_("show branch information")),
17551767
OPT_BOOL(0, "ahead-behind", &s.ahead_behind_flags,
17561768
N_("compute full ahead/behind values")),
1769+
OPT_BOOL(0, "in-progress", &s.show_in_progress, N_("show in-progress information")),
17571770
OPT_SET_INT(0, "porcelain", &status_format,
17581771
N_("machine-readable output"), STATUS_FORMAT_PORCELAIN),
17591772
OPT_SET_INT(0, "long", &status_format,

t/t7512-status-help.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@ Unmerged paths:
9393
no changes added to commit (use "git add" and/or "git commit -a")
9494
EOF
9595
git status --untracked-files=no >actual &&
96+
test_cmp expected actual &&
97+
cat >expected <<EOF &&
98+
## HEAD (no branch); REBASE-m
99+
UU main.txt
100+
EOF
101+
git status --untracked-files=no --short --branch --in-progress >actual &&
96102
test_cmp expected actual
97103
'
98104

@@ -154,6 +160,12 @@ Unmerged paths:
154160
no changes added to commit (use "git add" and/or "git commit -a")
155161
EOF
156162
git status --untracked-files=no >actual &&
163+
test_cmp expected actual &&
164+
cat >expected <<EOF &&
165+
## HEAD (no branch); REBASE-i
166+
UU main.txt
167+
EOF
168+
git status --untracked-files=no --short --branch --in-progress >actual &&
157169
test_cmp expected actual
158170
'
159171

@@ -650,6 +662,11 @@ You are in the middle of an am session.
650662
nothing to commit (use -u to show untracked files)
651663
EOF
652664
git status --untracked-files=no >actual &&
665+
test_cmp expected actual &&
666+
cat >expected <<\EOF &&
667+
## am_already_exists; AM
668+
EOF
669+
git status --untracked-files=no --short --branch --in-progress >actual &&
653670
test_cmp expected actual
654671
'
655672

@@ -719,6 +736,11 @@ You are currently bisecting, started from branch '\''bisect'\''.
719736
nothing to commit (use -u to show untracked files)
720737
EOF
721738
git status --untracked-files=no >actual &&
739+
test_cmp expected actual &&
740+
cat >expected <<EOF &&
741+
## HEAD (no branch); BISECTING
742+
EOF
743+
git status --untracked-files=no --short --branch --in-progress >actual &&
722744
test_cmp expected actual
723745
'
724746

@@ -806,6 +828,12 @@ Unmerged paths:
806828
no changes added to commit (use "git add" and/or "git commit -a")
807829
EOF
808830
git status --untracked-files=no >actual &&
831+
test_cmp expected actual &&
832+
cat >expected <<EOF &&
833+
## cherry_branch; CHERRY-PICKING
834+
UU main.txt
835+
EOF
836+
git status --untracked-files=no --short --branch --in-progress >actual &&
809837
test_cmp expected actual
810838
'
811839

@@ -934,9 +962,16 @@ Unmerged paths:
934962
no changes added to commit (use "git add" and/or "git commit -a")
935963
EOF
936964
git status --untracked-files=no >actual &&
965+
test_cmp expected actual &&
966+
cat >expected <<EOF &&
967+
## main; REVERTING
968+
UU to-revert.txt
969+
EOF
970+
git status --untracked-files=no --short --branch --in-progress >actual &&
937971
test_cmp expected actual
938972
'
939973

974+
940975
test_expect_success 'status while reverting commit (conflicts resolved)' '
941976
echo reverted >to-revert.txt &&
942977
git add to-revert.txt &&

wt-status.c

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2192,6 +2192,7 @@ static void wt_shortstatus_other(struct string_list_item *it,
21922192
static void wt_shortstatus_print_tracking(struct wt_status *s)
21932193
{
21942194
struct branch *branch;
2195+
struct wt_status_state state;
21952196
const char *header_color = color(WT_STATUS_HEADER, s);
21962197
const char *branch_color_local = color(WT_STATUS_LOCAL_BRANCH, s);
21972198
const char *branch_color_remote = color(WT_STATUS_REMOTE_BRANCH, s);
@@ -2216,7 +2217,7 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)
22162217
if (!strcmp(s->branch, "HEAD")) {
22172218
color_fprintf(s->fp, color(WT_STATUS_NOBRANCH, s), "%s",
22182219
LABEL(N_("HEAD (no branch)")));
2219-
goto conclude;
2220+
goto inprogress;
22202221
}
22212222

22222223
skip_prefix(branch_name, "refs/heads/", &branch_name);
@@ -2229,7 +2230,7 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)
22292230
0, s->ahead_behind_flags);
22302231
if (sti < 0) {
22312232
if (!base)
2232-
goto conclude;
2233+
goto inprogress;
22332234

22342235
upstream_is_gone = 1;
22352236
}
@@ -2241,7 +2242,7 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)
22412242
free(short_base);
22422243

22432244
if (!upstream_is_gone && !sti)
2244-
goto conclude;
2245+
goto inprogress;
22452246

22462247
color_fprintf(s->fp, header_color, " [");
22472248
if (upstream_is_gone) {
@@ -2262,6 +2263,31 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)
22622263
}
22632264

22642265
color_fprintf(s->fp, header_color, "]");
2266+
2267+
inprogress:
2268+
if (!s->show_in_progress)
2269+
goto conclude;
2270+
memset(&state, 0, sizeof(state));
2271+
wt_status_get_state(s->repo, &state,
2272+
s->branch && !strcmp(s->branch, "HEAD"));
2273+
if (state.merge_in_progress)
2274+
color_fprintf(s->fp, header_color, "; %s", LABEL(N_("MERGING")));
2275+
else if (state.am_in_progress)
2276+
color_fprintf(s->fp, header_color, "; %s", LABEL(N_("AM")));
2277+
else if (state.rebase_in_progress)
2278+
color_fprintf(s->fp, header_color, "; %s", LABEL(N_("REBASE-m")));
2279+
else if (state.rebase_interactive_in_progress)
2280+
color_fprintf(s->fp, header_color, "; %s", LABEL(N_("REBASE-i")));
2281+
else if (state.cherry_pick_in_progress)
2282+
color_fprintf(s->fp, header_color, "; %s", LABEL(N_("CHERRY-PICKING")));
2283+
else if (state.revert_in_progress)
2284+
color_fprintf(s->fp, header_color, "; %s", LABEL(N_("REVERTING")));
2285+
if (state.bisect_in_progress)
2286+
color_fprintf(s->fp, header_color, "; %s", LABEL(N_("BISECTING")));
2287+
free(state.branch);
2288+
free(state.onto);
2289+
free(state.detached_from);
2290+
22652291
conclude:
22662292
fputc(s->null_termination ? '\0' : '\n', s->fp);
22672293
}

wt-status.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ struct wt_status {
125125
int commit_template;
126126
int show_branch;
127127
int show_stash;
128+
int show_in_progress;
128129
int hints;
129130
enum ahead_behind_flags ahead_behind_flags;
130131
int detect_rename;

0 commit comments

Comments
 (0)