Documentation/stash: remove mention of git reset --hard
[git.git] / t / t3203-branch-output.sh
blobc6a3ccba1b992cff7412bcf8139da7557981de94
1 #!/bin/sh
3 test_description='git branch display tests'
4 . ./test-lib.sh
6 test_expect_success 'make commits' '
7 echo content >file &&
8 git add file &&
9 git commit -m one &&
10 echo content >>file &&
11 git commit -a -m two
14 test_expect_success 'make branches' '
15 git branch branch-one &&
16 git branch branch-two HEAD^
19 test_expect_success 'make remote branches' '
20 git update-ref refs/remotes/origin/branch-one branch-one &&
21 git update-ref refs/remotes/origin/branch-two branch-two &&
22 git symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/branch-one
25 cat >expect <<'EOF'
26 branch-one
27 branch-two
28 * master
29 EOF
30 test_expect_success 'git branch shows local branches' '
31 git branch >actual &&
32 test_cmp expect actual
35 test_expect_success 'git branch --list shows local branches' '
36 git branch --list >actual &&
37 test_cmp expect actual
40 cat >expect <<'EOF'
41 branch-one
42 branch-two
43 EOF
44 test_expect_success 'git branch --list pattern shows matching local branches' '
45 git branch --list branch* >actual &&
46 test_cmp expect actual
49 cat >expect <<'EOF'
50 origin/HEAD -> origin/branch-one
51 origin/branch-one
52 origin/branch-two
53 EOF
54 test_expect_success 'git branch -r shows remote branches' '
55 git branch -r >actual &&
56 test_cmp expect actual
59 cat >expect <<'EOF'
60 branch-one
61 branch-two
62 * master
63 remotes/origin/HEAD -> origin/branch-one
64 remotes/origin/branch-one
65 remotes/origin/branch-two
66 EOF
67 test_expect_success 'git branch -a shows local and remote branches' '
68 git branch -a >actual &&
69 test_cmp expect actual
72 cat >expect <<'EOF'
73 two
74 one
75 two
76 EOF
77 test_expect_success 'git branch -v shows branch summaries' '
78 git branch -v >tmp &&
79 awk "{print \$NF}" <tmp >actual &&
80 test_cmp expect actual
83 cat >expect <<'EOF'
84 two
85 one
86 EOF
87 test_expect_success 'git branch --list -v pattern shows branch summaries' '
88 git branch --list -v branch* >tmp &&
89 awk "{print \$NF}" <tmp >actual &&
90 test_cmp expect actual
93 test_expect_success 'git branch -v pattern does not show branch summaries' '
94 test_must_fail git branch -v branch*
97 test_expect_success 'git branch shows detached HEAD properly' '
98 cat >expect <<EOF &&
99 * (HEAD detached at $(git rev-parse --short HEAD^0))
100 branch-one
101 branch-two
102 master
104 git checkout HEAD^0 &&
105 git branch >actual &&
106 test_i18ncmp expect actual
109 test_expect_success 'git branch shows detached HEAD properly after checkout --detach' '
110 git checkout master &&
111 cat >expect <<EOF &&
112 * (HEAD detached at $(git rev-parse --short HEAD^0))
113 branch-one
114 branch-two
115 master
117 git checkout --detach &&
118 git branch >actual &&
119 test_i18ncmp expect actual
122 test_expect_success 'git branch shows detached HEAD properly after moving' '
123 cat >expect <<EOF &&
124 * (HEAD detached from $(git rev-parse --short HEAD))
125 branch-one
126 branch-two
127 master
129 git reset --hard HEAD^1 &&
130 git branch >actual &&
131 test_i18ncmp expect actual
134 test_expect_success 'git branch shows detached HEAD properly from tag' '
135 cat >expect <<EOF &&
136 * (HEAD detached at fromtag)
137 branch-one
138 branch-two
139 master
141 git tag fromtag master &&
142 git checkout fromtag &&
143 git branch >actual &&
144 test_i18ncmp expect actual
147 test_expect_success 'git branch shows detached HEAD properly after moving from tag' '
148 cat >expect <<EOF &&
149 * (HEAD detached from fromtag)
150 branch-one
151 branch-two
152 master
154 git reset --hard HEAD^1 &&
155 git branch >actual &&
156 test_i18ncmp expect actual
159 test_expect_success 'git branch `--sort` option' '
160 cat >expect <<-\EOF &&
161 * (HEAD detached from fromtag)
162 branch-two
163 branch-one
164 master
166 git branch --sort=objectsize >actual &&
167 test_i18ncmp expect actual
170 test_expect_success 'git branch --points-at option' '
171 cat >expect <<-\EOF &&
172 branch-one
173 master
175 git branch --points-at=branch-one >actual &&
176 test_cmp expect actual
179 test_expect_success 'ambiguous branch/tag not marked' '
180 git tag ambiguous &&
181 git branch ambiguous &&
182 echo " ambiguous" >expect &&
183 git branch --list ambiguous >actual &&
184 test_cmp expect actual
187 test_expect_success 'local-branch symrefs shortened properly' '
188 git symbolic-ref refs/heads/ref-to-branch refs/heads/branch-one &&
189 git symbolic-ref refs/heads/ref-to-remote refs/remotes/origin/branch-one &&
190 cat >expect <<-\EOF &&
191 ref-to-branch -> branch-one
192 ref-to-remote -> refs/remotes/origin/branch-one
194 git branch >actual.raw &&
195 grep ref-to <actual.raw >actual &&
196 test_cmp expect actual
199 test_done