summaryrefslogtreecommitdiff
path: root/t/t3203-branch-output.sh
diff options
context:
space:
mode:
Diffstat (limited to 't/t3203-branch-output.sh')
-rwxr-xr-xt/t3203-branch-output.sh170
1 files changed, 139 insertions, 31 deletions
diff --git a/t/t3203-branch-output.sh b/t/t3203-branch-output.sh
index 71818b9..758963b 100755
--- a/t/t3203-branch-output.sh
+++ b/t/t3203-branch-output.sh
@@ -8,6 +8,7 @@ test_expect_success 'make commits' '
echo content >file &&
git add file &&
git commit -m one &&
+ git branch -M main &&
echo content >>file &&
git commit -a -m two
'
@@ -26,7 +27,7 @@ test_expect_success 'make remote branches' '
cat >expect <<'EOF'
branch-one
branch-two
-* master
+* main
EOF
test_expect_success 'git branch shows local branches' '
git branch >actual &&
@@ -54,22 +55,38 @@ cat >expect <<'EOF'
EOF
test_expect_success 'git branch -r shows remote branches' '
git branch -r >actual &&
+ test_cmp expect actual &&
+
+ git branch --remotes >actual &&
test_cmp expect actual
'
+test_expect_success 'git branch --no-remotes is rejected' '
+ test_must_fail git branch --no-remotes 2>err &&
+ grep "unknown option .no-remotes." err
+'
+
cat >expect <<'EOF'
branch-one
branch-two
-* master
+* main
remotes/origin/HEAD -> origin/branch-one
remotes/origin/branch-one
remotes/origin/branch-two
EOF
test_expect_success 'git branch -a shows local and remote branches' '
git branch -a >actual &&
+ test_cmp expect actual &&
+
+ git branch --all >actual &&
test_cmp expect actual
'
+test_expect_success 'git branch --no-all is rejected' '
+ test_must_fail git branch --no-all 2>err &&
+ grep "unknown option .no-all." err
+'
+
cat >expect <<'EOF'
two
one
@@ -152,24 +169,24 @@ test_expect_success 'git branch shows detached HEAD properly' '
* (HEAD detached at $(git rev-parse --short HEAD^0))
branch-one
branch-two
- master
+ main
EOF
git checkout HEAD^0 &&
git branch >actual &&
- test_i18ncmp expect actual
+ test_cmp expect actual
'
test_expect_success 'git branch shows detached HEAD properly after checkout --detach' '
- git checkout master &&
+ git checkout main &&
cat >expect <<EOF &&
* (HEAD detached at $(git rev-parse --short HEAD^0))
branch-one
branch-two
- master
+ main
EOF
git checkout --detach &&
git branch >actual &&
- test_i18ncmp expect actual
+ test_cmp expect actual
'
test_expect_success 'git branch shows detached HEAD properly after moving' '
@@ -177,11 +194,11 @@ test_expect_success 'git branch shows detached HEAD properly after moving' '
* (HEAD detached from $(git rev-parse --short HEAD))
branch-one
branch-two
- master
+ main
EOF
git reset --hard HEAD^1 &&
git branch >actual &&
- test_i18ncmp expect actual
+ test_cmp expect actual
'
test_expect_success 'git branch shows detached HEAD properly from tag' '
@@ -189,12 +206,12 @@ test_expect_success 'git branch shows detached HEAD properly from tag' '
* (HEAD detached at fromtag)
branch-one
branch-two
- master
+ main
EOF
- git tag fromtag master &&
+ git tag fromtag main &&
git checkout fromtag &&
git branch >actual &&
- test_i18ncmp expect actual
+ test_cmp expect actual
'
test_expect_success 'git branch shows detached HEAD properly after moving from tag' '
@@ -202,28 +219,77 @@ test_expect_success 'git branch shows detached HEAD properly after moving from t
* (HEAD detached from fromtag)
branch-one
branch-two
- master
+ main
EOF
git reset --hard HEAD^1 &&
git branch >actual &&
- test_i18ncmp expect actual
+ test_cmp expect actual
'
-test_expect_success 'git branch `--sort` option' '
+test_expect_success 'git branch `--sort=[-]objectsize` option' '
cat >expect <<-\EOF &&
* (HEAD detached from fromtag)
branch-two
branch-one
- master
+ main
EOF
git branch --sort=objectsize >actual &&
- test_i18ncmp expect actual
+ test_cmp expect actual &&
+
+ cat >expect <<-\EOF &&
+ * (HEAD detached from fromtag)
+ branch-one
+ main
+ branch-two
+ EOF
+ git branch --sort=-objectsize >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'git branch `--sort=[-]type` option' '
+ cat >expect <<-\EOF &&
+ * (HEAD detached from fromtag)
+ branch-one
+ branch-two
+ main
+ EOF
+ git branch --sort=type >actual &&
+ test_cmp expect actual &&
+
+ cat >expect <<-\EOF &&
+ * (HEAD detached from fromtag)
+ branch-one
+ branch-two
+ main
+ EOF
+ git branch --sort=-type >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'git branch `--sort=[-]version:refname` option' '
+ cat >expect <<-\EOF &&
+ * (HEAD detached from fromtag)
+ branch-one
+ branch-two
+ main
+ EOF
+ git branch --sort=version:refname >actual &&
+ test_cmp expect actual &&
+
+ cat >expect <<-\EOF &&
+ * (HEAD detached from fromtag)
+ main
+ branch-two
+ branch-one
+ EOF
+ git branch --sort=-version:refname >actual &&
+ test_cmp expect actual
'
test_expect_success 'git branch --points-at option' '
cat >expect <<-\EOF &&
branch-one
- master
+ main
EOF
git branch --points-at=branch-one >actual &&
test_cmp expect actual
@@ -251,7 +317,7 @@ test_expect_success 'local-branch symrefs shortened properly' '
test_expect_success 'sort branches, ignore case' '
(
- git init sort-icase &&
+ git init -b main sort-icase &&
cd sort-icase &&
test_commit initial &&
git branch branch-one &&
@@ -260,14 +326,14 @@ test_expect_success 'sort branches, ignore case' '
cat >expected <<-\EOF &&
BRANCH-two
branch-one
- master
+ main
EOF
test_cmp expected actual &&
git branch --list -i | awk "{print \$NF}" >actual &&
cat >expected <<-\EOF &&
branch-one
BRANCH-two
- master
+ main
EOF
test_cmp expected actual
)
@@ -279,12 +345,54 @@ test_expect_success 'git branch --format option' '
Refname is refs/heads/ambiguous
Refname is refs/heads/branch-one
Refname is refs/heads/branch-two
- Refname is refs/heads/master
+ Refname is refs/heads/main
Refname is refs/heads/ref-to-branch
Refname is refs/heads/ref-to-remote
EOF
git branch --format="Refname is %(refname)" >actual &&
- test_i18ncmp expect actual
+ test_cmp expect actual
+'
+
+test_expect_success 'git branch --format with ahead-behind' '
+ cat >expect <<-\EOF &&
+ (HEAD detached from fromtag) 0 0
+ refs/heads/ambiguous 0 0
+ refs/heads/branch-one 1 0
+ refs/heads/branch-two 0 0
+ refs/heads/main 1 0
+ refs/heads/ref-to-branch 1 0
+ refs/heads/ref-to-remote 1 0
+ EOF
+ git branch --format="%(refname) %(ahead-behind:HEAD)" >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'git branch with --format=%(rest) must fail' '
+ test_must_fail git branch --format="%(rest)" >actual
+'
+
+test_expect_success 'git branch --format --omit-empty' '
+ cat >expect <<-\EOF &&
+ Refname is (HEAD detached from fromtag)
+ Refname is refs/heads/ambiguous
+ Refname is refs/heads/branch-one
+ Refname is refs/heads/branch-two
+
+ Refname is refs/heads/ref-to-branch
+ Refname is refs/heads/ref-to-remote
+ EOF
+ git branch --format="%(if:notequals=refs/heads/main)%(refname)%(then)Refname is %(refname)%(end)" >actual &&
+ test_cmp expect actual &&
+ cat >expect <<-\EOF &&
+ Refname is (HEAD detached from fromtag)
+ Refname is refs/heads/ambiguous
+ Refname is refs/heads/branch-one
+ Refname is refs/heads/branch-two
+ Refname is refs/heads/ref-to-branch
+ Refname is refs/heads/ref-to-remote
+ EOF
+ git branch --omit-empty --format="%(if:notequals=refs/heads/main)%(refname)%(then)Refname is %(refname)%(end)" >actual &&
+ test_cmp expect actual
'
test_expect_success 'worktree colors correct' '
@@ -293,7 +401,7 @@ test_expect_success 'worktree colors correct' '
ambiguous<RESET>
branch-one<RESET>
+ <CYAN>branch-two<RESET>
- master<RESET>
+ main<RESET>
ref-to-branch<RESET> -> branch-one
ref-to-remote<RESET> -> origin/branch-one
EOF
@@ -302,13 +410,13 @@ test_expect_success 'worktree colors correct' '
rm -r worktree_dir &&
git worktree prune &&
test_decode_color <actual.raw >actual &&
- test_i18ncmp expect actual
+ test_cmp 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"
+ echo "<RED>main<RESET>" >expect.color &&
+ echo "main" >expect.bare &&
+ color_args="--format=%(color:red)%(refname:short) --list main"
'
test_expect_success '%(color) omitted without tty' '
@@ -331,13 +439,13 @@ test_expect_success '--color overrides auto-color' '
test_expect_success 'verbose output lists worktree path' '
one=$(git rev-parse --short HEAD) &&
- two=$(git rev-parse --short master) &&
+ two=$(git rev-parse --short main) &&
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
+ main $two two
ref-to-branch $two two
ref-to-remote $two two
EOF
@@ -345,7 +453,7 @@ test_expect_success 'verbose output lists worktree path' '
git branch -vv >actual &&
rm -r worktree_dir &&
git worktree prune &&
- test_i18ncmp expect actual
+ test_cmp expect actual
'
test_done