Merge branch 'js/t0001-case-insensitive'
[gitweb.git] / t / t3203-branch-output.sh
index ee6787614c80edb9b5b24065277dd413350a6fc6..71818b90f00d3727cb00e24da181fc9dec420f08 100755 (executable)
@@ -100,6 +100,53 @@ 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 &&
+       test_when_finished "
+               git worktree remove worktree_dir
+       " &&
+       git worktree add worktree_dir branch-two &&
+       {
+               git branch --show-current &&
+               git -C worktree_dir 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))
@@ -240,6 +287,24 @@ test_expect_success 'git branch --format option' '
        test_i18ncmp expect actual
 '
 
+test_expect_success 'worktree colors correct' '
+       cat >expect <<-EOF &&
+       * <GREEN>(HEAD detached from fromtag)<RESET>
+         ambiguous<RESET>
+         branch-one<RESET>
+       + <CYAN>branch-two<RESET>
+         master<RESET>
+         ref-to-branch<RESET> -> branch-one
+         ref-to-remote<RESET> -> origin/branch-one
+       EOF
+       git worktree add worktree_dir branch-two &&
+       git branch --color >actual.raw &&
+       rm -r worktree_dir &&
+       git worktree prune &&
+       test_decode_color <actual.raw >actual &&
+       test_i18ncmp expect actual
+'
+
 test_expect_success "set up color tests" '
        echo "<RED>master<RESET>" >expect.color &&
        echo "master" >expect.bare &&
@@ -264,4 +329,23 @@ test_expect_success '--color overrides auto-color' '
        test_cmp expect.color actual
 '
 
+test_expect_success 'verbose output lists worktree path' '
+       one=$(git rev-parse --short HEAD) &&
+       two=$(git rev-parse --short master) &&
+       cat >expect <<-EOF &&
+       * (HEAD detached from fromtag) $one one
+         ambiguous                    $one one
+         branch-one                   $two two
+       + branch-two                   $one ($(pwd)/worktree_dir) one
+         master                       $two two
+         ref-to-branch                $two two
+         ref-to-remote                $two two
+       EOF
+       git worktree add worktree_dir branch-two &&
+       git branch -vv >actual &&
+       rm -r worktree_dir &&
+       git worktree prune &&
+       test_i18ncmp expect actual
+'
+
 test_done