1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-05-28 10:26:25 +02:00
git/t/t3203-branch-output.sh
Karthik Nayak aedcb7dc75 branch.c: use 'ref-filter' APIs
Make 'branch.c' use 'ref-filter' APIs for iterating through refs
sorting. This removes most of the code used in 'branch.c' replacing it
with calls to the 'ref-filter' library.

Make 'branch.c' use the 'filter_refs()' function provided by 'ref-filter'
to filter out tags based on the options set.

We provide a sorting option provided for 'branch.c' by using the
sorting options provided by 'ref-filter'. Also by default, we sort by
'refname'.  Since 'HEAD' is alphabatically before 'refs/...' we end up
with an array consisting of the 'HEAD' ref then the local branches and
finally the remote-tracking branches.

Also remove the 'ignore' variable from ref_array_item as it was
previously used for the '--merged' option and now that is handled by
ref-filter.

Modify some of the tests in t1430 to check the stderr for a warning
regarding the broken ref. This is done as ref-filter throws a warning
for broken refs rather than directly printing them.

Add tests and documentation for the same.

Mentored-by: Christian Couder <christian.couder@gmail.com>
Mentored-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>
Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-09-25 08:54:54 -07:00

158 lines
3.3 KiB
Bash
Executable File

#!/bin/sh
test_description='git branch display tests'
. ./test-lib.sh
test_expect_success 'make commits' '
echo content >file &&
git add file &&
git commit -m one &&
echo content >>file &&
git commit -a -m two
'
test_expect_success 'make branches' '
git branch branch-one &&
git branch branch-two HEAD^
'
test_expect_success 'make remote branches' '
git update-ref refs/remotes/origin/branch-one branch-one &&
git update-ref refs/remotes/origin/branch-two branch-two &&
git symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/branch-one
'
cat >expect <<'EOF'
branch-one
branch-two
* master
EOF
test_expect_success 'git branch shows local branches' '
git branch >actual &&
test_cmp expect actual
'
test_expect_success 'git branch --list shows local branches' '
git branch --list >actual &&
test_cmp expect actual
'
cat >expect <<'EOF'
branch-one
branch-two
EOF
test_expect_success 'git branch --list pattern shows matching local branches' '
git branch --list branch* >actual &&
test_cmp expect actual
'
cat >expect <<'EOF'
origin/HEAD -> origin/branch-one
origin/branch-one
origin/branch-two
EOF
test_expect_success 'git branch -r shows remote branches' '
git branch -r >actual &&
test_cmp expect actual
'
cat >expect <<'EOF'
branch-one
branch-two
* master
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
'
cat >expect <<'EOF'
two
one
two
EOF
test_expect_success 'git branch -v shows branch summaries' '
git branch -v >tmp &&
awk "{print \$NF}" <tmp >actual &&
test_cmp expect actual
'
cat >expect <<'EOF'
two
one
EOF
test_expect_success 'git branch --list -v pattern shows branch summaries' '
git branch --list -v branch* >tmp &&
awk "{print \$NF}" <tmp >actual &&
test_cmp expect actual
'
test_expect_success 'git branch -v pattern does not show branch summaries' '
test_must_fail git branch -v branch*
'
test_expect_success 'git branch shows detached HEAD properly' '
cat >expect <<EOF &&
* (HEAD detached at $(git rev-parse --short HEAD^0))
branch-one
branch-two
master
EOF
git checkout HEAD^0 &&
git branch >actual &&
test_i18ncmp expect actual
'
test_expect_success 'git branch shows detached HEAD properly after moving' '
cat >expect <<EOF &&
* (HEAD detached from $(git rev-parse --short HEAD))
branch-one
branch-two
master
EOF
git reset --hard HEAD^1 &&
git branch >actual &&
test_i18ncmp expect actual
'
test_expect_success 'git branch shows detached HEAD properly from tag' '
cat >expect <<EOF &&
* (HEAD detached at fromtag)
branch-one
branch-two
master
EOF
git tag fromtag master &&
git checkout fromtag &&
git branch >actual &&
test_i18ncmp expect actual
'
test_expect_success 'git branch shows detached HEAD properly after moving from tag' '
cat >expect <<EOF &&
* (HEAD detached from fromtag)
branch-one
branch-two
master
EOF
git reset --hard HEAD^1 &&
git branch >actual &&
test_i18ncmp expect actual
'
test_expect_success 'git branch `--sort` option' '
cat >expect <<-\EOF &&
branch-two
* (HEAD detached from fromtag)
branch-one
master
EOF
git branch --sort=objectsize >actual &&
test_i18ncmp expect actual
'
test_done