Imported Upstream version 2.22.0
[platform/upstream/git.git] / t / t3203-branch-output.sh
index a428ae6..be55148 100755 (executable)
@@ -2,6 +2,7 @@
 
 test_description='git branch display tests'
 . ./test-lib.sh
+. "$TEST_DIRECTORY"/lib-terminal.sh
 
 test_expect_success 'make commits' '
        echo content >file &&
@@ -99,6 +100,50 @@ test_expect_success 'git branch -v pattern does not show branch summaries' '
        test_must_fail git branch -v branch*
 '
 
+test_expect_success 'git branch `--show-current` shows current branch' '
+       cat >expect <<-\EOF &&
+       branch-two
+       EOF
+       git checkout branch-two &&
+       git branch --show-current >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'git branch `--show-current` is silent when detached HEAD' '
+       git checkout HEAD^0 &&
+       git branch --show-current >actual &&
+       test_must_be_empty actual
+'
+
+test_expect_success 'git branch `--show-current` works properly when tag exists' '
+       cat >expect <<-\EOF &&
+       branch-and-tag-name
+       EOF
+       test_when_finished "
+               git checkout branch-one
+               git branch -D branch-and-tag-name
+       " &&
+       git checkout -b branch-and-tag-name &&
+       test_when_finished "git tag -d branch-and-tag-name" &&
+       git tag branch-and-tag-name &&
+       git branch --show-current >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'git branch `--show-current` works properly with worktrees' '
+       cat >expect <<-\EOF &&
+       branch-one
+       branch-two
+       EOF
+       git checkout branch-one &&
+       git worktree add worktree branch-two &&
+       {
+               git branch --show-current &&
+               git -C worktree branch --show-current
+       } >actual &&
+       test_cmp expect actual
+'
+
 test_expect_success 'git branch shows detached HEAD properly' '
        cat >expect <<EOF &&
 * (HEAD detached at $(git rev-parse --short HEAD^0))
@@ -239,4 +284,28 @@ test_expect_success 'git branch --format option' '
        test_i18ncmp expect actual
 '
 
+test_expect_success "set up color tests" '
+       echo "<RED>master<RESET>" >expect.color &&
+       echo "master" >expect.bare &&
+       color_args="--format=%(color:red)%(refname:short) --list master"
+'
+
+test_expect_success '%(color) omitted without tty' '
+       TERM=vt100 git branch $color_args >actual.raw &&
+       test_decode_color <actual.raw >actual &&
+       test_cmp expect.bare actual
+'
+
+test_expect_success TTY '%(color) present with tty' '
+       test_terminal git branch $color_args >actual.raw &&
+       test_decode_color <actual.raw >actual &&
+       test_cmp expect.color actual
+'
+
+test_expect_success '--color overrides auto-color' '
+       git branch --color $color_args >actual.raw &&
+       test_decode_color <actual.raw >actual &&
+       test_cmp expect.color actual
+'
+
 test_done