Skip to content

Commit ab930f0

Browse files
committed
Merge branch 'jx/branch-vv-always-compare-with-upstream'
Hot-fix for a regression. * jx/branch-vv-always-compare-with-upstream: branch: fix --verbose output column alignment
2 parents 0397305 + 6b364d4 commit ab930f0

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

builtin/branch.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ static void fill_tracking_info(struct strbuf *stat, const char *branch_name,
424424
struct branch *branch = branch_get(branch_name);
425425
struct strbuf fancy = STRBUF_INIT;
426426
int upstream_is_gone = 0;
427+
int added_decoration = 1;
427428

428429
switch (stat_tracking_info(branch, &ours, &theirs)) {
429430
case 0:
@@ -451,9 +452,13 @@ static void fill_tracking_info(struct strbuf *stat, const char *branch_name,
451452
if (upstream_is_gone) {
452453
if (show_upstream_ref)
453454
strbuf_addf(stat, _("[%s: gone]"), fancy.buf);
455+
else
456+
added_decoration = 0;
454457
} else if (!ours && !theirs) {
455458
if (show_upstream_ref)
456459
strbuf_addf(stat, _("[%s]"), fancy.buf);
460+
else
461+
added_decoration = 0;
457462
} else if (!ours) {
458463
if (show_upstream_ref)
459464
strbuf_addf(stat, _("[%s: behind %d]"), fancy.buf, theirs);
@@ -474,7 +479,8 @@ static void fill_tracking_info(struct strbuf *stat, const char *branch_name,
474479
ours, theirs);
475480
}
476481
strbuf_release(&fancy);
477-
strbuf_addch(stat, ' ');
482+
if (added_decoration)
483+
strbuf_addch(stat, ' ');
478484
free(ref);
479485
}
480486

t/t6040-tracking-info.sh

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,14 @@ test_expect_success setup '
3939
advance h
4040
'
4141

42-
script='s/^..\(b.\)[ 0-9a-f]*\[\([^]]*\)\].*/\1 \2/p'
42+
script='s/^..\(b.\) *[0-9a-f]* \(.*\)$/\1 \2/p'
4343
cat >expect <<\EOF
44-
b1 ahead 1, behind 1
45-
b2 ahead 1, behind 1
46-
b3 behind 1
47-
b4 ahead 2
44+
b1 [ahead 1, behind 1] d
45+
b2 [ahead 1, behind 1] d
46+
b3 [behind 1] b
47+
b4 [ahead 2] f
48+
b5 g
49+
b6 c
4850
EOF
4951

5052
test_expect_success 'branch -v' '
@@ -57,12 +59,12 @@ test_expect_success 'branch -v' '
5759
'
5860

5961
cat >expect <<\EOF
60-
b1 origin/master: ahead 1, behind 1
61-
b2 origin/master: ahead 1, behind 1
62-
b3 origin/master: behind 1
63-
b4 origin/master: ahead 2
64-
b5 brokenbase: gone
65-
b6 origin/master
62+
b1 [origin/master: ahead 1, behind 1] d
63+
b2 [origin/master: ahead 1, behind 1] d
64+
b3 [origin/master: behind 1] b
65+
b4 [origin/master: ahead 2] f
66+
b5 [brokenbase: gone] g
67+
b6 [origin/master] c
6668
EOF
6769

6870
test_expect_success 'branch -vv' '

0 commit comments

Comments
 (0)