Skip to content

Commit 4465690

Browse files
avargitster
authored andcommitted
show-branch: don't <COLOR></RESET> for space characters
Change the colored output introduced in ab07ba2 (show-branch: color the commit status signs, 2009-04-22) to not color and reset each individual space character we use for padding. The intent is to color just the "!", "+" etc. characters. This makes the output easier to test, so let's do that now. The test would be much more verbose without a color/reset for each space character. Since the coloring cycles through colors we previously had a "rainbow of space characters". In theory this breaks things for anyone who's relying on the exact colored output of show-branch, in practice I'd think anyone parsing it isn't actively turning on the colored output. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9b6e74a commit 4465690

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

builtin/show-branch.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -939,9 +939,12 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
939939
mark = '*';
940940
else
941941
mark = '+';
942-
printf("%s%c%s",
943-
get_color_code(i),
944-
mark, get_color_reset_code());
942+
if (mark == ' ')
943+
putchar(mark);
944+
else
945+
printf("%s%c%s",
946+
get_color_code(i),
947+
mark, get_color_reset_code());
945948
}
946949
putchar(' ');
947950
}

t/t3202-show-branch.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,34 @@ test_expect_success 'show-branch with showbranch.default' '
5555
test_cmp expect actual
5656
'
5757

58+
test_expect_success 'show-branch --color output' '
59+
sed "s/^> //" >expect <<-\EOF &&
60+
> <RED>!<RESET> [branch1] branch1
61+
> <GREEN>!<RESET> [branch2] branch2
62+
> <YELLOW>!<RESET> [branch3] branch3
63+
> <BLUE>!<RESET> [branch4] branch4
64+
> <MAGENTA>!<RESET> [branch5] branch5
65+
> <CYAN>!<RESET> [branch6] branch6
66+
> <BOLD;RED>!<RESET> [branch7] branch7
67+
> <BOLD;GREEN>!<RESET> [branch8] branch8
68+
> <BOLD;YELLOW>!<RESET> [branch9] branch9
69+
> <BOLD;BLUE>*<RESET> [branch10] branch10
70+
> ----------
71+
> <BOLD;BLUE>*<RESET> [branch10] branch10
72+
> <BOLD;YELLOW>+<RESET> [branch9] branch9
73+
> <BOLD;GREEN>+<RESET> [branch8] branch8
74+
> <BOLD;RED>+<RESET> [branch7] branch7
75+
> <CYAN>+<RESET> [branch6] branch6
76+
> <MAGENTA>+<RESET> [branch5] branch5
77+
> <BLUE>+<RESET> [branch4] branch4
78+
> <YELLOW>+<RESET> [branch3] branch3
79+
> <GREEN>+<RESET> [branch2] branch2
80+
> <RED>+<RESET> [branch1] branch1
81+
> <RED>+<RESET><GREEN>+<RESET><YELLOW>+<RESET><BLUE>+<RESET><MAGENTA>+<RESET><CYAN>+<RESET><BOLD;RED>+<RESET><BOLD;GREEN>+<RESET><BOLD;YELLOW>+<RESET><BOLD;BLUE>*<RESET> [branch10^] initial
82+
EOF
83+
git show-branch --color=always $(cat branches.sorted) >actual.raw &&
84+
test_decode_color <actual.raw >actual &&
85+
test_cmp expect actual
86+
'
87+
5888
test_done

0 commit comments

Comments
 (0)