]> git.ipfire.org Git - thirdparty/git.git/blame - t/t3200-branch.sh
Update stale documentation links from the main documentation.
[thirdparty/git.git] / t / t3200-branch.sh
CommitLineData
a3b427b9
AW
1#!/bin/sh
2#
3# Copyright (c) 2005 Amos Waterland
4#
5
6test_description='git branch --foo should not create bogus branch
7
8This test runs git branch --help and checks that the argument is properly
9handled. Specifically, that a bogus branch is not created.
10'
11. ./test-lib.sh
12
13test_expect_success \
4c84f0dc 14 'prepare a trivial repository' \
a3b427b9 15 'echo Hello > A &&
5be60078 16 git update-index --add A &&
d7fb7a37 17 git-commit -m "Initial commit." &&
5be60078 18 HEAD=$(git rev-parse --verify HEAD)'
a3b427b9 19
a3b427b9
AW
20test_expect_failure \
21 'git branch --help should not have created a bogus branch' \
5be60078 22 'git branch --help </dev/null >/dev/null 2>/dev/null || :
5d9e8ee7 23 test -f .git/refs/heads/--help'
a3b427b9 24
08db81a9
AR
25test_expect_success \
26 'git branch abc should create a branch' \
5be60078 27 'git branch abc && test -f .git/refs/heads/abc'
08db81a9
AR
28
29test_expect_success \
30 'git branch a/b/c should create a branch' \
5be60078 31 'git branch a/b/c && test -f .git/refs/heads/a/b/c'
08db81a9 32
d7fb7a37 33cat >expect <<EOF
5d9e8ee7 340000000000000000000000000000000000000000 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master
d7fb7a37
SP
35EOF
36test_expect_success \
37 'git branch -l d/e/f should create a branch and a log' \
38 'GIT_COMMITTER_DATE="2005-05-26 23:30" \
5be60078 39 git branch -l d/e/f &&
d7fb7a37
SP
40 test -f .git/refs/heads/d/e/f &&
41 test -f .git/logs/refs/heads/d/e/f &&
42 diff expect .git/logs/refs/heads/d/e/f'
43
44test_expect_success \
45 'git branch -d d/e/f should delete a branch and a log' \
5be60078 46 'git branch -d d/e/f &&
d7fb7a37
SP
47 test ! -f .git/refs/heads/d/e/f &&
48 test ! -f .git/logs/refs/heads/d/e/f'
49
9c7b0b3f
CC
50test_expect_success \
51 'git branch j/k should work after branch j has been deleted' \
5be60078
JH
52 'git branch j &&
53 git branch -d j &&
54 git branch j/k'
9c7b0b3f
CC
55
56test_expect_success \
57 'git branch l should work after branch l/m has been deleted' \
5be60078
JH
58 'git branch l/m &&
59 git branch -d l/m &&
60 git branch l'
9c7b0b3f 61
c976d415
LH
62test_expect_success \
63 'git branch -m m m/m should work' \
5be60078
JH
64 'git branch -l m &&
65 git branch -m m m/m &&
c976d415
LH
66 test -f .git/logs/refs/heads/m/m'
67
68test_expect_success \
69 'git branch -m n/n n should work' \
5be60078
JH
70 'git branch -l n/n &&
71 git branch -m n/n n
c976d415
LH
72 test -f .git/logs/refs/heads/n'
73
74test_expect_failure \
75 'git branch -m o/o o should fail when o/p exists' \
5be60078
JH
76 'git branch o/o &&
77 git branch o/p &&
78 git branch -m o/o o'
c976d415
LH
79
80test_expect_failure \
81 'git branch -m q r/q should fail when r exists' \
5be60078
JH
82 'git branch q &&
83 git branch r &&
84 git branch -m q r/q'
c976d415 85
01ebb9dc
GB
86mv .git/config .git/config-saved
87
08b984fb 88test_expect_success 'git branch -m q q2 without config should succeed' '
5be60078
JH
89 git branch -m q q2 &&
90 git branch -m q2 q
01ebb9dc
GB
91'
92
93mv .git/config-saved .git/config
94
5be60078 95git config branch.s/s.dummy Hello
dc81c58c 96
c976d415
LH
97test_expect_success \
98 'git branch -m s/s s should work when s/t is deleted' \
5be60078 99 'git branch -l s/s &&
c976d415 100 test -f .git/logs/refs/heads/s/s &&
5be60078 101 git branch -l s/t &&
c976d415 102 test -f .git/logs/refs/heads/s/t &&
5be60078
JH
103 git branch -d s/t &&
104 git branch -m s/s s &&
c976d415
LH
105 test -f .git/logs/refs/heads/s'
106
dc81c58c 107test_expect_success 'config information was renamed, too' \
5be60078
JH
108 "test $(git config branch.s.dummy) = Hello &&
109 ! git config branch.s/s/dummy"
dc81c58c 110
16c2bfbb 111test_expect_failure \
5be60078
JH
112 'git branch -m u v should fail when the reflog for u is a symlink' \
113 'git branch -l u &&
16c2bfbb
LH
114 mv .git/logs/refs/heads/u real-u &&
115 ln -s real-u .git/logs/refs/heads/u &&
5be60078 116 git branch -m u v'
16c2bfbb 117
0746d19a 118test_expect_success 'test tracking setup via --track' \
5be60078
JH
119 'git config remote.local.url . &&
120 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
121 (git show-ref -q refs/remotes/local/master || git-fetch local) &&
122 git branch --track my1 local/master &&
123 test $(git config branch.my1.remote) = local &&
124 test $(git config branch.my1.merge) = refs/heads/master'
0746d19a
PB
125
126test_expect_success 'test tracking setup (non-wildcard, matching)' \
5be60078
JH
127 'git config remote.local.url . &&
128 git config remote.local.fetch refs/heads/master:refs/remotes/local/master &&
129 (git show-ref -q refs/remotes/local/master || git-fetch local) &&
130 git branch --track my4 local/master &&
131 test $(git config branch.my4.remote) = local &&
132 test $(git config branch.my4.merge) = refs/heads/master'
0746d19a
PB
133
134test_expect_success 'test tracking setup (non-wildcard, not matching)' \
5be60078
JH
135 'git config remote.local.url . &&
136 git config remote.local.fetch refs/heads/s:refs/remotes/local/s &&
137 (git show-ref -q refs/remotes/local/master || git-fetch local) &&
138 git branch --track my5 local/master &&
139 ! test "$(git config branch.my5.remote)" = local &&
140 ! test "$(git config branch.my5.merge)" = refs/heads/master'
0746d19a
PB
141
142test_expect_success 'test tracking setup via config' \
5be60078
JH
143 'git config branch.autosetupmerge true &&
144 git config remote.local.url . &&
145 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
146 (git show-ref -q refs/remotes/local/master || git-fetch local) &&
147 git branch my3 local/master &&
148 test $(git config branch.my3.remote) = local &&
149 test $(git config branch.my3.merge) = refs/heads/master'
0746d19a 150
6f084a56 151test_expect_success 'avoid ambiguous track' '
4017761f 152 git config branch.autosetupmerge true &&
6f084a56
JS
153 git config remote.ambi1.url = lalala &&
154 git config remote.ambi1.fetch = refs/heads/lalala:refs/heads/master &&
155 git config remote.ambi2.url = lilili &&
156 git config remote.ambi2.fetch = refs/heads/lilili:refs/heads/master &&
4017761f 157 git branch all1 master &&
6f084a56 158 test -z "$(git config branch.all1.merge)"
4017761f
JS
159'
160
0746d19a 161test_expect_success 'test overriding tracking setup via --no-track' \
5be60078
JH
162 'git config branch.autosetupmerge true &&
163 git config remote.local.url . &&
164 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
165 (git show-ref -q refs/remotes/local/master || git-fetch local) &&
166 git branch --no-track my2 local/master &&
167 git config branch.autosetupmerge false &&
168 ! test "$(git config branch.my2.remote)" = local &&
169 ! test "$(git config branch.my2.merge)" = refs/heads/master'
0746d19a 170
6f084a56 171test_expect_success 'no tracking without .fetch entries' \
9debc324 172 'git branch --track my6 s &&
6f084a56
JS
173 test -z "$(git config branch.my6.remote)" &&
174 test -z "$(git config branch.my6.merge)"'
9debc324 175
11f68d90 176test_expect_success 'test tracking setup via --track but deeper' \
5be60078
JH
177 'git config remote.local.url . &&
178 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
179 (git show-ref -q refs/remotes/local/o/o || git-fetch local) &&
180 git branch --track my7 local/o/o &&
181 test "$(git config branch.my7.remote)" = local &&
182 test "$(git config branch.my7.merge)" = refs/heads/o/o'
11f68d90 183
f1eccbab 184test_expect_success 'test deleting branch deletes branch config' \
5be60078 185 'git branch -d my7 &&
6f084a56
JS
186 test -z "$(git config branch.my7.remote)" &&
187 test -z "$(git config branch.my7.merge)"'
f1eccbab
GP
188
189test_expect_success 'test deleting branch without config' \
5be60078
JH
190 'git branch my7 s &&
191 test "$(git branch -d my7 2>&1)" = "Deleted branch my7."'
f1eccbab 192
0746d19a
PB
193# Keep this test last, as it changes the current branch
194cat >expect <<EOF
1950000000000000000000000000000000000000000 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master
196EOF
197test_expect_success \
198 'git checkout -b g/h/i -l should create a branch and a log' \
199 'GIT_COMMITTER_DATE="2005-05-26 23:30" \
200 git-checkout -b g/h/i -l master &&
201 test -f .git/refs/heads/g/h/i &&
202 test -f .git/logs/refs/heads/g/h/i &&
203 diff expect .git/logs/refs/heads/g/h/i'
204
a3b427b9 205test_done