Skip to content

Commit b474398

Browse files
jeffhostetlerdscho
authored andcommitted
status: update short status to respect --no-ahead-behind
Teach "git status --short --branch" to respect "--no-ahead-behind" parameter to skip computing ahead/behind counts for the branch and its upstream and just report '[different]'. Signed-off-by: Jeff Hostetler <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 7ab11fd commit b474398

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

t/t6040-tracking-info.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,19 @@ test_expect_success 'status -s -b (diverged from upstream)' '
146146
test_i18ncmp expect actual
147147
'
148148

149+
cat >expect <<\EOF
150+
## b1...origin/master [different]
151+
EOF
152+
153+
test_expect_success 'status -s -b --no-ahead-behind (diverged from upstream)' '
154+
(
155+
cd test &&
156+
git checkout b1 >/dev/null &&
157+
git status -s -b --no-ahead-behind | head -1
158+
) >actual &&
159+
test_i18ncmp expect actual
160+
'
161+
149162
cat >expect <<\EOF
150163
## b5...brokenbase [gone]
151164
EOF

wt-status.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1766,7 +1766,7 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)
17661766
const char *base;
17671767
char *short_base;
17681768
const char *branch_name;
1769-
int num_ours, num_theirs;
1769+
int num_ours, num_theirs, sti;
17701770
int upstream_is_gone = 0;
17711771

17721772
color_fprintf(s->fp, color(WT_STATUS_HEADER, s), "## ");
@@ -1792,8 +1792,9 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)
17921792

17931793
color_fprintf(s->fp, branch_color_local, "%s", branch_name);
17941794

1795-
if (stat_tracking_info(branch, &num_ours, &num_theirs, &base,
1796-
AHEAD_BEHIND_FULL) < 0) {
1795+
sti = stat_tracking_info(branch, &num_ours, &num_theirs, &base,
1796+
s->ahead_behind_flags);
1797+
if (sti < 0) {
17971798
if (!base)
17981799
goto conclude;
17991800

@@ -1805,12 +1806,14 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)
18051806
color_fprintf(s->fp, branch_color_remote, "%s", short_base);
18061807
free(short_base);
18071808

1808-
if (!upstream_is_gone && !num_ours && !num_theirs)
1809+
if (!upstream_is_gone && !sti)
18091810
goto conclude;
18101811

18111812
color_fprintf(s->fp, header_color, " [");
18121813
if (upstream_is_gone) {
18131814
color_fprintf(s->fp, header_color, LABEL(N_("gone")));
1815+
} else if (s->ahead_behind_flags == AHEAD_BEHIND_QUICK) {
1816+
color_fprintf(s->fp, header_color, LABEL(N_("different")));
18141817
} else if (!num_ours) {
18151818
color_fprintf(s->fp, header_color, LABEL(N_("behind ")));
18161819
color_fprintf(s->fp, branch_color_remote, "%d", num_theirs);

0 commit comments

Comments
 (0)