This is a series I've had lying around for a while, when looking at
the color output for show-branch I noticed it reset and re-enabled
color for every single space character.
This fixes that, but mostly fixes the mostly non-existing tests for
that old command it. It still has big blind spots, but now we have
fewer blind spots.
Ævar Arnfjörð Bjarmason (4):
show-branch tests: rename the one "show-branch" test file
show-branch tests: modernize test code
show-branch: fix and test --color output
show-branch tests: add missing tests
builtin/show-branch.c | 9 +-
t/t3202-show-branch-octopus.sh | 70 ----------------
t/t3202-show-branch.sh | 149 +++++++++++++++++++++++++++++++++
3 files changed, 155 insertions(+), 73 deletions(-)
delete mode 100755 t/t3202-show-branch-octopus.sh
create mode 100755 t/t3202-show-branch.sh
--
2.32.0.555.g0268d380f7b
Fix the "show-branch --color" output so it doesn't needlessly color
and reset each time it emits a space character.
Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
builtin/show-branch.c | 9 ++++++---
t/t3202-show-branch.sh | 30 ++++++++++++++++++++++++++++++
2 files changed, 36 insertions(+), 3 deletions(-)
Add missing tests for --remotes, --list and --merge-base. These are
not exhaustive, but better than the nothing we have now.
There were some tests for this command added in f76412ed6db ([PATCH]
Add 'git show-branch'., 2005-08-21) has never been properly tested,
namely for the --all option in t6432-merge-recursive-space-options.sh,
and some of --merge-base and --independent in t6010-merge-base.sh.
This fixes a few more blind spots, but there's still a lot of behavior
that's not tested for.
These new tests show the add (and possibly unintentional) behavior of
--merge-base with one argument, and how its output is the same as "git
merge-base" with N bases in this particular case. See the test added
in f621a8454d1 (git-merge-base/git-show-branch --merge-base:
Documentation and test, 2009-08-05) for a case where the two aren't
the same.
Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
t/t3202-show-branch.sh | 61 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 61 insertions(+)
@@ -85,4 +85,65 @@ test_expect_success 'show-branch --color output' 'test_cmpexpectactual'+test_expect_success'show branch --remotes''+cat>expect.err<<-\EOF&&+Norevstobeshown.+EOF+gitshow-branch-r2>actual.err>actual.out&&+test_cmpexpect.erractual.err&&+test_must_be_emptyactual.out+'++test_expect_success'setup show branch --list''+sed"s/^> //">expect<<-\EOF+>[branch1]branch1+>[branch2]branch2+>[branch3]branch3+>[branch4]branch4+>[branch5]branch5+>[branch6]branch6+>[branch7]branch7+>[branch8]branch8+>[branch9]branch9+>*[branch10]branch10+EOF+'++test_expect_success'show branch --list''+gitshow-branch--list$(catbranches.sorted)>actual&&+test_cmpexpectactual+'++test_expect_success'show branch --list has no --color output''+gitshow-branch--color=always--list$(catbranches.sorted)>actual&&+test_cmpexpectactual+'++test_expect_success'show branch --merge-base with one argument''+forbranchin$(catbranches.sorted)+do+gitrev-parse$branch>expect&&+gitshow-branch--merge-base$branch>actual&&+test_cmpexpectactual+done+'++test_expect_success'show branch --merge-base with two arguments''+forbranchin$(catbranches.sorted)+do+gitrev-parseinitial>expect&&+gitshow-branch--merge-baseinitial$branch>actual&&+test_cmpexpectactual+done+'++test_expect_success'show branch --merge-base with N arguments''+gitrev-parseinitial>expect&&+gitshow-branch--merge-base$(catbranches.sorted)>actual&&+test_cmpexpectactual&&++gitmerge-base$(catbranches.sorted)>actual&&+test_cmpexpectactual+'+ test_done
Rename the only *show-branch* test file to indicate that more tests
belong it in than just the one-off octopus test it now contains.
The test was initially added in ce567d1867a (Add test to show that
show-branch misses out the 8th column, 2008-07-23) and
11ee57bc4c4 (sort_in_topological_order(): avoid setting a commit flag,
2008-07-23). Those two add almost the same content, one with a
test_expect_success and the other a test_expect_failure (a bug being
tested for was fixed on one of the branches).
Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
t/{t3202-show-branch-octopus.sh => t3202-show-branch.sh} | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
rename t/{t3202-show-branch-octopus.sh => t3202-show-branch.sh} (95%)
diff --git a/t/t3202-show-branch-octopus.sh b/t/t3202-show-branch.shsimilarity index 95%rename from t/t3202-show-branch-octopus.shrename to t/t3202-show-branch.shindex 5cb0126cfed..8cfbbf79c1b 100755--- a/t/t3202-show-branch-octopus.sh+++ b/t/t3202-show-branch.sh
@@ -1,6 +1,6 @@#!/bin/sh-test_description='test show-branch with more than 8 heads'+test_description='test show-branch'GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=mainexportGIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
Modernize test code added in ce567d1867a (Add test to show that
show-branch misses out the 8th column, 2008-07-23) and
11ee57bc4c4 (sort_in_topological_order(): avoid setting a commit flag,
2008-07-23) to use test helpers.
I'm renaming "out" to "actual" for consistency with other tests, and
introducing a "branches.sorted" file in the setup, to make it clear
that it's important that the list be sorted in this particular way.
The "show-branch" output is indented with spaces, which would cause
complaints under "git show --check" with an indented here-doc
block. Let's prefix the lines with "> " to work around that, and to
make it clear that the leading whitespace is important.
We can also get rid of the hardcoding of "main" added here in
334afbc76fb (tests: mark tests relying on the current default for
`init.defaultBranch`, 2020-11-18). For this test we're setting up an
"initial" commit anyway, and now that we've moved over to test_commit
we can reference that instead.
Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
t/t3202-show-branch.sh | 92 ++++++++++++++++++------------------------
1 file changed, 40 insertions(+), 52 deletions(-)
From: Michael J Gruber <hidden> Date: 2021-06-15 09:34:04
Ævar Arnfjörð Bjarmason venit, vidit, dixit 2021-06-14 19:18:10:
Add missing tests for --remotes, --list and --merge-base. These are
not exhaustive, but better than the nothing we have now.
There were some tests for this command added in f76412ed6db ([PATCH]
Add 'git show-branch'., 2005-08-21) has never been properly tested,
namely for the --all option in t6432-merge-recursive-space-options.sh,
and some of --merge-base and --independent in t6010-merge-base.sh.
This fixes a few more blind spots, but there's still a lot of behavior
that's not tested for.
These new tests show the add (and possibly unintentional) behavior of
"odd"
Other than that, I don't think show-branch was broken, so I somehow
contest the phrase "fix" in this series, it's more of a clean-up.
Just to be sure: Users have no way of assigning a color code with
background colors to the columns, which is why omitting
the lookup and reset is correct for a space.
Now, people scripting around show-branch might be bitten by that change
because the number of (unprocessed) characters in the output changes, or
because a control character which they used to "tr" is not there any more.
They should not (script this command), I guess.
quoted hunk
--merge-base with one argument, and how its output is the same as "git
merge-base" with N bases in this particular case. See the test added
in f621a8454d1 (git-merge-base/git-show-branch --merge-base:
Documentation and test, 2009-08-05) for a case where the two aren't
the same.
Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
t/t3202-show-branch.sh | 61 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 61 insertions(+)
@@ -85,4 +85,65 @@ test_expect_success 'show-branch --color output' 'test_cmpexpectactual'+test_expect_success'show branch --remotes''+cat>expect.err<<-\EOF&&+Norevstobeshown.+EOF+gitshow-branch-r2>actual.err>actual.out&&+test_cmpexpect.erractual.err&&+test_must_be_emptyactual.out+'++test_expect_success'setup show branch --list''+sed"s/^> //">expect<<-\EOF+>[branch1]branch1+>[branch2]branch2+>[branch3]branch3+>[branch4]branch4+>[branch5]branch5+>[branch6]branch6+>[branch7]branch7+>[branch8]branch8+>[branch9]branch9+>*[branch10]branch10+EOF+'++test_expect_success'show branch --list''+gitshow-branch--list$(catbranches.sorted)>actual&&+test_cmpexpectactual+'++test_expect_success'show branch --list has no --color output''+gitshow-branch--color=always--list$(catbranches.sorted)>actual&&+test_cmpexpectactual+'++test_expect_success'show branch --merge-base with one argument''+forbranchin$(catbranches.sorted)+do+gitrev-parse$branch>expect&&+gitshow-branch--merge-base$branch>actual&&+test_cmpexpectactual+done+'++test_expect_success'show branch --merge-base with two arguments''+forbranchin$(catbranches.sorted)+do+gitrev-parseinitial>expect&&+gitshow-branch--merge-baseinitial$branch>actual&&+test_cmpexpectactual+done+'++test_expect_success'show branch --merge-base with N arguments''+gitrev-parseinitial>expect&&+gitshow-branch--merge-base$(catbranches.sorted)>actual&&+test_cmpexpectactual&&++gitmerge-base$(catbranches.sorted)>actual&&+test_cmpexpectactual+'+ test_done
This v2 doesn't change any of the code (see range-diff), but better
explains the change per Michael J Gruber's feedback in
https://lore.kernel.org/git/162374905722.40525.516266574605586007.git@grubix.eu/
There's also a trivial grammar fix, s/add/odd/g.
Ævar Arnfjörð Bjarmason (4):
show-branch tests: rename the one "show-branch" test file
show-branch tests: modernize test code
show-branch: don't <COLOR></RESET> for space characters
show-branch tests: add missing tests
builtin/show-branch.c | 9 +-
t/t3202-show-branch-octopus.sh | 70 ----------------
t/t3202-show-branch.sh | 149 +++++++++++++++++++++++++++++++++
3 files changed, 155 insertions(+), 73 deletions(-)
delete mode 100755 t/t3202-show-branch-octopus.sh
create mode 100755 t/t3202-show-branch.sh
Range-diff against v1:
1: 7b8ac43339 = 1: 7b8ac43339 show-branch tests: rename the one "show-branch" test file
2: 27f94abaed = 2: 27f94abaed show-branch tests: modernize test code
3: 8db7029086 ! 3: 937e728f7f show-branch: fix and test --color output
@@ Metadata
Author: Ævar Arnfjörð Bjarmason [off-list ref]
## Commit message ##
- show-branch: fix and test --color output
+ show-branch: don't <COLOR></RESET> for space characters
- Fix the "show-branch --color" output so it doesn't needlessly color
- and reset each time it emits a space character.
+ Change the colored output introduced in ab07ba2a24 (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 [off-list ref]
4: c54c6a7b20 ! 4: dde0177235 show-branch tests: add missing tests
@@ Commit message
This fixes a few more blind spots, but there's still a lot of behavior
that's not tested for.
- These new tests show the add (and possibly unintentional) behavior of
+ These new tests show the odd (and possibly unintentional) behavior of
--merge-base with one argument, and how its output is the same as "git
merge-base" with N bases in this particular case. See the test added
in f621a8454d1 (git-merge-base/git-show-branch --merge-base:
--
2.32.0.571.gdba276db2c
Rename the only *show-branch* test file to indicate that more tests
belong it in than just the one-off octopus test it now contains.
The test was initially added in ce567d1867a (Add test to show that
show-branch misses out the 8th column, 2008-07-23) and
11ee57bc4c4 (sort_in_topological_order(): avoid setting a commit flag,
2008-07-23). Those two add almost the same content, one with a
test_expect_success and the other a test_expect_failure (a bug being
tested for was fixed on one of the branches).
Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
t/{t3202-show-branch-octopus.sh => t3202-show-branch.sh} | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
rename t/{t3202-show-branch-octopus.sh => t3202-show-branch.sh} (95%)
diff --git a/t/t3202-show-branch-octopus.sh b/t/t3202-show-branch.shsimilarity index 95%rename from t/t3202-show-branch-octopus.shrename to t/t3202-show-branch.shindex 5cb0126cfe..8cfbbf79c1 100755--- a/t/t3202-show-branch-octopus.sh+++ b/t/t3202-show-branch.sh
@@ -1,6 +1,6 @@#!/bin/sh-test_description='test show-branch with more than 8 heads'+test_description='test show-branch'GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=mainexportGIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
Modernize test code added in ce567d1867a (Add test to show that
show-branch misses out the 8th column, 2008-07-23) and
11ee57bc4c4 (sort_in_topological_order(): avoid setting a commit flag,
2008-07-23) to use test helpers.
I'm renaming "out" to "actual" for consistency with other tests, and
introducing a "branches.sorted" file in the setup, to make it clear
that it's important that the list be sorted in this particular way.
The "show-branch" output is indented with spaces, which would cause
complaints under "git show --check" with an indented here-doc
block. Let's prefix the lines with "> " to work around that, and to
make it clear that the leading whitespace is important.
We can also get rid of the hardcoding of "main" added here in
334afbc76fb (tests: mark tests relying on the current default for
`init.defaultBranch`, 2020-11-18). For this test we're setting up an
"initial" commit anyway, and now that we've moved over to test_commit
we can reference that instead.
Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
t/t3202-show-branch.sh | 92 ++++++++++++++++++------------------------
1 file changed, 40 insertions(+), 52 deletions(-)
Add missing tests for --remotes, --list and --merge-base. These are
not exhaustive, but better than the nothing we have now.
There were some tests for this command added in f76412ed6db ([PATCH]
Add 'git show-branch'., 2005-08-21) has never been properly tested,
namely for the --all option in t6432-merge-recursive-space-options.sh,
and some of --merge-base and --independent in t6010-merge-base.sh.
This fixes a few more blind spots, but there's still a lot of behavior
that's not tested for.
These new tests show the odd (and possibly unintentional) behavior of
--merge-base with one argument, and how its output is the same as "git
merge-base" with N bases in this particular case. See the test added
in f621a8454d1 (git-merge-base/git-show-branch --merge-base:
Documentation and test, 2009-08-05) for a case where the two aren't
the same.
Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
t/t3202-show-branch.sh | 61 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 61 insertions(+)
@@ -85,4 +85,65 @@ test_expect_success 'show-branch --color output' 'test_cmpexpectactual'+test_expect_success'show branch --remotes''+cat>expect.err<<-\EOF&&+Norevstobeshown.+EOF+gitshow-branch-r2>actual.err>actual.out&&+test_cmpexpect.erractual.err&&+test_must_be_emptyactual.out+'++test_expect_success'setup show branch --list''+sed"s/^> //">expect<<-\EOF+>[branch1]branch1+>[branch2]branch2+>[branch3]branch3+>[branch4]branch4+>[branch5]branch5+>[branch6]branch6+>[branch7]branch7+>[branch8]branch8+>[branch9]branch9+>*[branch10]branch10+EOF+'++test_expect_success'show branch --list''+gitshow-branch--list$(catbranches.sorted)>actual&&+test_cmpexpectactual+'++test_expect_success'show branch --list has no --color output''+gitshow-branch--color=always--list$(catbranches.sorted)>actual&&+test_cmpexpectactual+'++test_expect_success'show branch --merge-base with one argument''+forbranchin$(catbranches.sorted)+do+gitrev-parse$branch>expect&&+gitshow-branch--merge-base$branch>actual&&+test_cmpexpectactual+done+'++test_expect_success'show branch --merge-base with two arguments''+forbranchin$(catbranches.sorted)+do+gitrev-parseinitial>expect&&+gitshow-branch--merge-baseinitial$branch>actual&&+test_cmpexpectactual+done+'++test_expect_success'show branch --merge-base with N arguments''+gitrev-parseinitial>expect&&+gitshow-branch--merge-base$(catbranches.sorted)>actual&&+test_cmpexpectactual&&++gitmerge-base$(catbranches.sorted)>actual&&+test_cmpexpectactual+'+ test_done
Change the colored output introduced in ab07ba2a24 (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 <redacted>
---
builtin/show-branch.c | 9 ++++++---
t/t3202-show-branch.sh | 30 ++++++++++++++++++++++++++++++
2 files changed, 36 insertions(+), 3 deletions(-)
From: Felipe Contreras <hidden> Date: 2021-06-17 21:16:13
Ævar Arnfjörð Bjarmason wrote:
quoted hunk
diff --git a/t/t3202-show-branch-octopus.sh b/t/t3202-show-branch.shsimilarity index 95%rename from t/t3202-show-branch-octopus.shrename to t/t3202-show-branch.shindex 5cb0126cfe..8cfbbf79c1 100755--- a/t/t3202-show-branch-octopus.sh+++ b/t/t3202-show-branch.sh
From: Felipe Contreras <hidden> Date: 2021-06-17 21:29:06
Ævar Arnfjörð Bjarmason wrote:
Modernize test code added in ce567d1867a (Add test to show that
show-branch misses out the 8th column, 2008-07-23) and
11ee57bc4c4 (sort_in_topological_order(): avoid setting a commit flag,
2008-07-23) to use test helpers.
I'm renaming "out" to "actual" for consistency with other tests, and
introducing a "branches.sorted" file in the setup, to make it clear
that it's important that the list be sorted in this particular way.
That is better.
The "show-branch" output is indented with spaces, which would cause
complaints under "git show --check" with an indented here-doc
block. Let's prefix the lines with "> " to work around that, and to
make it clear that the leading whitespace is important.
I'm not sure this is an improvement. To me the original code is just
fine. Also, I don't think writing an 'expect' file belong in a setup
step.
Additionally I would do this change in a separate patch.
We can also get rid of the hardcoding of "main" added here in
334afbc76fb (tests: mark tests relying on the current default for
`init.defaultBranch`, 2020-11-18). For this test we're setting up an
"initial" commit anyway, and now that we've moved over to test_commit
we can reference that instead.
That's also good.
All the changes in this patch look good to me, however, they are smashed
together in a way that makes the review harder, I see:
1. Use test_commit
2. Rename out to actual
3. Use >actual instead of > actual
4. Use test_seq instead of $numbers
5. Use branches.sorted instead of branch$i
6. Use test_config instead of git config
7. Use internal sed 's/^ //' instead of outside cat
I'm on-board with 6 out of 7, but if these were done it at least 2
patches, they would be clearer. I in fact would prefer one patch per
change (although maybe squash 3 with 2).
Cheers.
--
Felipe Contreras
From: Felipe Contreras <hidden> Date: 2021-06-17 21:41:48
Ævar Arnfjörð Bjarmason wrote:
Change the colored output introduced in ab07ba2a24 (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.
Obviously a fix, but perhaps show the current behavior:
<RED>+<RESET><GREEN> <RESET><YELLOW> <RESET><BLUE> <RESET><MAGENTA> <RESET><CYAN> <RESET><BOLD;RED> <RESET><BOLD;GREEN> <RESET><BOLD;YELLOW> <RESET><BOLD;BLUE> <RESET> [branch1] branch1
Versus:
<RED>+<RESET> [branch1] branch1
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.
Please let's limit our worries to real users. Few people use
`git show-branch`, even less would rely on parsing its bogus output.
@@ -85,4 +85,65 @@ test_expect_success 'show-branch --color output' 'test_cmpexpectactual'+test_expect_success'show branch --remotes''+cat>expect.err<<-\EOF&&+Norevstobeshown.+EOF+gitshow-branch-r2>actual.err>actual.out&&+test_cmpexpect.erractual.err&&+test_must_be_emptyactual.out+'++test_expect_success'setup show branch --list''+sed"s/^> //">expect<<-\EOF+>[branch1]branch1+>[branch2]branch2+>[branch3]branch3+>[branch4]branch4+>[branch5]branch5+>[branch6]branch6+>[branch7]branch7+>[branch8]branch8+>[branch9]branch9+>*[branch10]branch10+EOF+'++test_expect_success'show branch --list''+gitshow-branch--list$(catbranches.sorted)>actual&&+test_cmpexpectactual+'++test_expect_success'show branch --list has no --color output''+gitshow-branch--color=always--list$(catbranches.sorted)>actual&&+test_cmpexpectactual+'++test_expect_success'show branch --merge-base with one argument''+forbranchin$(catbranches.sorted)+do+gitrev-parse$branch>expect&&+gitshow-branch--merge-base$branch>actual&&+test_cmpexpectactual+done+'++test_expect_success'show branch --merge-base with two arguments''+forbranchin$(catbranches.sorted)+do+gitrev-parseinitial>expect&&+gitshow-branch--merge-baseinitial$branch>actual&&+test_cmpexpectactual+done+'++test_expect_success'show branch --merge-base with N arguments''+gitrev-parseinitial>expect&&+gitshow-branch--merge-base$(catbranches.sorted)>actual&&+test_cmpexpectactual&&++gitmerge-base$(catbranches.sorted)>actual&&+test_cmpexpectactual+'+ test_done
All these look good to me.
Cheers.
--
Felipe Contreras
From: Felipe Contreras <hidden> Date: 2021-06-17 21:46:59
Ævar Arnfjörð Bjarmason wrote:
This v2 doesn't change any of the code (see range-diff), but better
explains the change per Michael J Gruber's feedback in
https://lore.kernel.org/git/162374905722.40525.516266574605586007.git@grubix.eu/
There's also a trivial grammar fix, s/add/odd/g.
Ævar Arnfjörð Bjarmason (4):
show-branch tests: rename the one "show-branch" test file
show-branch tests: modernize test code
show-branch: don't <COLOR></RESET> for space characters
show-branch tests: add missing tests
All these look good to me (I would prefer patch #2 to be split into
multiple patches, but that's not a deal-breaker).
Reviewed-by: Felipe Contreras <redacted>
--
Felipe Contreras