Jeff King | 34d820e | 2017-07-09 05:59:33 -0400 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='basic branch output coloring' |
Ævar Arnfjörð Bjarmason | 288a480 | 2021-10-12 15:56:44 +0200 | [diff] [blame] | 4 | TEST_PASSES_SANITIZE_LEAK=true |
Jeff King | 34d820e | 2017-07-09 05:59:33 -0400 | [diff] [blame] | 5 | . ./test-lib.sh |
| 6 | |
| 7 | test_expect_success 'set up some sample branches' ' |
| 8 | test_commit foo && |
Johannes Schindelin | 654bd7e | 2020-12-17 01:07:04 +0000 | [diff] [blame] | 9 | git branch -M main && |
| 10 | git update-ref refs/remotes/origin/main HEAD && |
Jeff King | 34d820e | 2017-07-09 05:59:33 -0400 | [diff] [blame] | 11 | git update-ref refs/heads/other HEAD |
| 12 | ' |
| 13 | |
| 14 | # choose non-default colors to make sure config |
| 15 | # is taking effect |
| 16 | test_expect_success 'set up some color config' ' |
Jeff King | 34d820e | 2017-07-09 05:59:33 -0400 | [diff] [blame] | 17 | git config color.branch.local blue && |
| 18 | git config color.branch.remote yellow && |
| 19 | git config color.branch.current cyan |
| 20 | ' |
| 21 | |
| 22 | test_expect_success 'regular output shows colors' ' |
| 23 | cat >expect <<-\EOF && |
Johannes Schindelin | 654bd7e | 2020-12-17 01:07:04 +0000 | [diff] [blame] | 24 | * <CYAN>main<RESET> |
Jeff King | 34d820e | 2017-07-09 05:59:33 -0400 | [diff] [blame] | 25 | <BLUE>other<RESET> |
Johannes Schindelin | 654bd7e | 2020-12-17 01:07:04 +0000 | [diff] [blame] | 26 | <YELLOW>remotes/origin/main<RESET> |
Jeff King | 34d820e | 2017-07-09 05:59:33 -0400 | [diff] [blame] | 27 | EOF |
Jeff King | 8126b12 | 2017-10-03 09:45:18 -0400 | [diff] [blame] | 28 | git branch --color -a >actual.raw && |
Jeff King | 34d820e | 2017-07-09 05:59:33 -0400 | [diff] [blame] | 29 | test_decode_color <actual.raw >actual && |
| 30 | test_cmp expect actual |
| 31 | ' |
| 32 | |
Johannes Schindelin | 654bd7e | 2020-12-17 01:07:04 +0000 | [diff] [blame] | 33 | test_expect_success 'verbose output shows colors' ' |
Jeff King | 34d820e | 2017-07-09 05:59:33 -0400 | [diff] [blame] | 34 | oid=$(git rev-parse --short HEAD) && |
| 35 | cat >expect <<-EOF && |
Johannes Schindelin | 66713e8 | 2020-10-23 14:00:05 +0000 | [diff] [blame] | 36 | * <CYAN>main <RESET> $oid foo |
| 37 | <BLUE>other <RESET> $oid foo |
| 38 | <YELLOW>remotes/origin/main<RESET> $oid foo |
Jeff King | 34d820e | 2017-07-09 05:59:33 -0400 | [diff] [blame] | 39 | EOF |
Jeff King | 8126b12 | 2017-10-03 09:45:18 -0400 | [diff] [blame] | 40 | git branch --color -v -a >actual.raw && |
Jeff King | 34d820e | 2017-07-09 05:59:33 -0400 | [diff] [blame] | 41 | test_decode_color <actual.raw >actual && |
| 42 | test_cmp expect actual |
| 43 | ' |
| 44 | |
| 45 | test_done |