Skip to content

Commit

Permalink
status: show in-progress info for short status
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mjg committed Sep 10, 2023
1 parent 461bb28 commit 98eb3c2
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 3 deletions.
4 changes: 4 additions & 0 deletions Documentation/config/status.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions Documentation/git-status.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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[=<version>]::
Give the output in an easy-to-parse format for scripts.
This is similar to the short output, but will remain stable
Expand Down
13 changes: 13 additions & 0 deletions builtin/commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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[]) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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,
Expand Down
35 changes: 35 additions & 0 deletions t/t7512-status-help.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 <<EOF &&
## HEAD (no branch); REBASE-m
UU main.txt
EOF
git status --untracked-files=no --short --branch --in-progress >actual &&
test_cmp expected actual
'

Expand Down Expand Up @@ -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 <<EOF &&
## HEAD (no branch); REBASE-i
UU main.txt
EOF
git status --untracked-files=no --short --branch --in-progress >actual &&
test_cmp expected actual
'

Expand Down Expand Up @@ -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
'

Expand Down Expand Up @@ -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 <<EOF &&
## HEAD (no branch); BISECTING
EOF
git status --untracked-files=no --short --branch --in-progress >actual &&
test_cmp expected actual
'

Expand Down Expand Up @@ -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 <<EOF &&
## cherry_branch; CHERRY-PICKING
UU main.txt
EOF
git status --untracked-files=no --short --branch --in-progress >actual &&
test_cmp expected actual
'

Expand Down Expand Up @@ -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 <<EOF &&
## main; REVERTING
UU to-revert.txt
EOF
git status --untracked-files=no --short --branch --in-progress >actual &&
test_cmp expected actual
'


test_expect_success 'status while reverting commit (conflicts resolved)' '
echo reverted >to-revert.txt &&
git add to-revert.txt &&
Expand Down
32 changes: 29 additions & 3 deletions wt-status.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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;
}
Expand All @@ -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) {
Expand All @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions wt-status.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 98eb3c2

Please sign in to comment.