Skip to content

Commit 85e6878

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 0605465 commit 85e6878

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
@@ -1771,7 +1771,7 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)
17711771
const char *base;
17721772
char *short_base;
17731773
const char *branch_name;
1774-
int num_ours, num_theirs;
1774+
int num_ours, num_theirs, sti;
17751775
int upstream_is_gone = 0;
17761776

17771777
color_fprintf(s->fp, color(WT_STATUS_HEADER, s), "## ");
@@ -1797,8 +1797,9 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)
17971797

17981798
color_fprintf(s->fp, branch_color_local, "%s", branch_name);
17991799

1800-
if (stat_tracking_info(branch, &num_ours, &num_theirs, &base,
1801-
AHEAD_BEHIND_FULL) < 0) {
1800+
sti = stat_tracking_info(branch, &num_ours, &num_theirs, &base,
1801+
s->ahead_behind_flags);
1802+
if (sti < 0) {
18021803
if (!base)
18031804
goto conclude;
18041805

@@ -1810,12 +1811,14 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)
18101811
color_fprintf(s->fp, branch_color_remote, "%s", short_base);
18111812
free(short_base);
18121813

1813-
if (!upstream_is_gone && !num_ours && !num_theirs)
1814+
if (!upstream_is_gone && !sti)
18141815
goto conclude;
18151816

18161817
color_fprintf(s->fp, header_color, " [");
18171818
if (upstream_is_gone) {
18181819
color_fprintf(s->fp, header_color, LABEL(N_("gone")));
1820+
} else if (s->ahead_behind_flags == AHEAD_BEHIND_QUICK) {
1821+
color_fprintf(s->fp, header_color, LABEL(N_("different")));
18191822
} else if (!num_ours) {
18201823
color_fprintf(s->fp, header_color, LABEL(N_("behind ")));
18211824
color_fprintf(s->fp, branch_color_remote, "%d", num_theirs);

0 commit comments

Comments
 (0)