branch: fix --verbose output column alignment
Commit f2e0873
(branch: report invalid tracking branch as gone) removed
an early return from fill_tracking_info() in the path taken when 'git
branch -v' lists a branch in sync with its upstream. This resulted in an
unconditionally added space in front of the subject line:
$ git branch -v
* master f5eb3da commit pushed to upstream
topic f935eb6 unpublished topic
Instead, only add the trailing space if a decoration have been added.
To catch this kind of whitespace breakage in the tests, be a bit less
smart when filtering the output through sed.
Signed-off-by: Torstein Hegge <hegge@resisty.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
f223459bec
commit
6b364d48f2
@ -424,6 +424,7 @@ static void fill_tracking_info(struct strbuf *stat, const char *branch_name,
|
|||||||
struct branch *branch = branch_get(branch_name);
|
struct branch *branch = branch_get(branch_name);
|
||||||
struct strbuf fancy = STRBUF_INIT;
|
struct strbuf fancy = STRBUF_INIT;
|
||||||
int upstream_is_gone = 0;
|
int upstream_is_gone = 0;
|
||||||
|
int added_decoration = 1;
|
||||||
|
|
||||||
switch (stat_tracking_info(branch, &ours, &theirs)) {
|
switch (stat_tracking_info(branch, &ours, &theirs)) {
|
||||||
case 0:
|
case 0:
|
||||||
@ -451,9 +452,13 @@ static void fill_tracking_info(struct strbuf *stat, const char *branch_name,
|
|||||||
if (upstream_is_gone) {
|
if (upstream_is_gone) {
|
||||||
if (show_upstream_ref)
|
if (show_upstream_ref)
|
||||||
strbuf_addf(stat, _("[%s: gone]"), fancy.buf);
|
strbuf_addf(stat, _("[%s: gone]"), fancy.buf);
|
||||||
|
else
|
||||||
|
added_decoration = 0;
|
||||||
} else if (!ours && !theirs) {
|
} else if (!ours && !theirs) {
|
||||||
if (show_upstream_ref)
|
if (show_upstream_ref)
|
||||||
strbuf_addf(stat, _("[%s]"), fancy.buf);
|
strbuf_addf(stat, _("[%s]"), fancy.buf);
|
||||||
|
else
|
||||||
|
added_decoration = 0;
|
||||||
} else if (!ours) {
|
} else if (!ours) {
|
||||||
if (show_upstream_ref)
|
if (show_upstream_ref)
|
||||||
strbuf_addf(stat, _("[%s: behind %d]"), fancy.buf, theirs);
|
strbuf_addf(stat, _("[%s: behind %d]"), fancy.buf, theirs);
|
||||||
@ -474,6 +479,7 @@ static void fill_tracking_info(struct strbuf *stat, const char *branch_name,
|
|||||||
ours, theirs);
|
ours, theirs);
|
||||||
}
|
}
|
||||||
strbuf_release(&fancy);
|
strbuf_release(&fancy);
|
||||||
|
if (added_decoration)
|
||||||
strbuf_addch(stat, ' ');
|
strbuf_addch(stat, ' ');
|
||||||
free(ref);
|
free(ref);
|
||||||
}
|
}
|
||||||
|
@ -39,12 +39,14 @@ test_expect_success setup '
|
|||||||
advance h
|
advance h
|
||||||
'
|
'
|
||||||
|
|
||||||
script='s/^..\(b.\)[ 0-9a-f]*\[\([^]]*\)\].*/\1 \2/p'
|
script='s/^..\(b.\) *[0-9a-f]* \(.*\)$/\1 \2/p'
|
||||||
cat >expect <<\EOF
|
cat >expect <<\EOF
|
||||||
b1 ahead 1, behind 1
|
b1 [ahead 1, behind 1] d
|
||||||
b2 ahead 1, behind 1
|
b2 [ahead 1, behind 1] d
|
||||||
b3 behind 1
|
b3 [behind 1] b
|
||||||
b4 ahead 2
|
b4 [ahead 2] f
|
||||||
|
b5 g
|
||||||
|
b6 c
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
test_expect_success 'branch -v' '
|
test_expect_success 'branch -v' '
|
||||||
@ -57,12 +59,12 @@ test_expect_success 'branch -v' '
|
|||||||
'
|
'
|
||||||
|
|
||||||
cat >expect <<\EOF
|
cat >expect <<\EOF
|
||||||
b1 origin/master: ahead 1, behind 1
|
b1 [origin/master: ahead 1, behind 1] d
|
||||||
b2 origin/master: ahead 1, behind 1
|
b2 [origin/master: ahead 1, behind 1] d
|
||||||
b3 origin/master: behind 1
|
b3 [origin/master: behind 1] b
|
||||||
b4 origin/master: ahead 2
|
b4 [origin/master: ahead 2] f
|
||||||
b5 brokenbase: gone
|
b5 [brokenbase: gone] g
|
||||||
b6 origin/master
|
b6 [origin/master] c
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
test_expect_success 'branch -vv' '
|
test_expect_success 'branch -vv' '
|
||||||
|
Loading…
Reference in New Issue
Block a user