debian: git-daemon-sysvinit: Depend lsb-base (>= 3.0-6)
[git/debian/andersk.git] / t / t2025-worktree-add.sh
blob3a22fc55fc324fbfbfdcdf39fb71e829c89729b5
1 #!/bin/sh
3 test_description='test git worktree add'
5 . ./test-lib.sh
7 . "$TEST_DIRECTORY"/lib-rebase.sh
9 test_expect_success 'setup' '
10 test_commit init
13 test_expect_success '"add" an existing worktree' '
14 mkdir -p existing/subtree &&
15 test_must_fail git worktree add --detach existing master
18 test_expect_success '"add" an existing empty worktree' '
19 mkdir existing_empty &&
20 git worktree add --detach existing_empty master
23 test_expect_success '"add" refuses to checkout locked branch' '
24 test_must_fail git worktree add zere master &&
25 ! test -d zere &&
26 ! test -d .git/worktrees/zere
29 test_expect_success 'checking out paths not complaining about linked checkouts' '
31 cd existing_empty &&
32 echo dirty >>init.t &&
33 git checkout master -- init.t
37 test_expect_success '"add" worktree' '
38 git rev-parse HEAD >expect &&
39 git worktree add --detach here master &&
41 cd here &&
42 test_cmp ../init.t init.t &&
43 test_must_fail git symbolic-ref HEAD &&
44 git rev-parse HEAD >actual &&
45 test_cmp ../expect actual &&
46 git fsck
50 test_expect_success '"add" worktree from a subdir' '
52 mkdir sub &&
53 cd sub &&
54 git worktree add --detach here master &&
55 cd here &&
56 test_cmp ../../init.t init.t
60 test_expect_success '"add" from a linked checkout' '
62 cd here &&
63 git worktree add --detach nested-here master &&
64 cd nested-here &&
65 git fsck
69 test_expect_success '"add" worktree creating new branch' '
70 git worktree add -b newmaster there master &&
72 cd there &&
73 test_cmp ../init.t init.t &&
74 git symbolic-ref HEAD >actual &&
75 echo refs/heads/newmaster >expect &&
76 test_cmp expect actual &&
77 git fsck
81 test_expect_success 'die the same branch is already checked out' '
83 cd here &&
84 test_must_fail git checkout newmaster
88 test_expect_success SYMLINKS 'die the same branch is already checked out (symlink)' '
89 head=$(git -C there rev-parse --git-path HEAD) &&
90 ref=$(git -C there symbolic-ref HEAD) &&
91 rm "$head" &&
92 ln -s "$ref" "$head" &&
93 test_must_fail git -C here checkout newmaster
96 test_expect_success 'not die the same branch is already checked out' '
98 cd here &&
99 git worktree add --force anothernewmaster newmaster
103 test_expect_success 'not die on re-checking out current branch' '
105 cd there &&
106 git checkout newmaster
110 test_expect_success '"add" from a bare repo' '
112 git clone --bare . bare &&
113 cd bare &&
114 git worktree add -b bare-master ../there2 master
118 test_expect_success 'checkout from a bare repo without "add"' '
120 cd bare &&
121 test_must_fail git checkout master
125 test_expect_success 'checkout with grafts' '
126 test_when_finished rm .git/info/grafts &&
127 test_commit abc &&
128 SHA1=$(git rev-parse HEAD) &&
129 test_commit def &&
130 test_commit xyz &&
131 echo "$(git rev-parse HEAD) $SHA1" >.git/info/grafts &&
132 cat >expected <<-\EOF &&
136 git log --format=%s -2 >actual &&
137 test_cmp expected actual &&
138 git worktree add --detach grafted master &&
139 git --git-dir=grafted/.git log --format=%s -2 >actual &&
140 test_cmp expected actual
143 test_expect_success '"add" from relative HEAD' '
144 test_commit a &&
145 test_commit b &&
146 test_commit c &&
147 git rev-parse HEAD~1 >expected &&
148 git worktree add relhead HEAD~1 &&
149 git -C relhead rev-parse HEAD >actual &&
150 test_cmp expected actual
153 test_expect_success '"add -b" with <branch> omitted' '
154 git worktree add -b burble flornk &&
155 test_cmp_rev HEAD burble
158 test_expect_success '"add --detach" with <branch> omitted' '
159 git worktree add --detach fishhook &&
160 git rev-parse HEAD >expected &&
161 git -C fishhook rev-parse HEAD >actual &&
162 test_cmp expected actual &&
163 test_must_fail git -C fishhook symbolic-ref HEAD
166 test_expect_success '"add" with <branch> omitted' '
167 git worktree add wiffle/bat &&
168 test_cmp_rev HEAD bat
171 test_expect_success '"add" auto-vivify does not clobber existing branch' '
172 test_commit c1 &&
173 test_commit c2 &&
174 git branch precious HEAD~1 &&
175 test_must_fail git worktree add precious &&
176 test_cmp_rev HEAD~1 precious &&
177 test_path_is_missing precious
180 test_expect_success '"add" no auto-vivify with --detach and <branch> omitted' '
181 git worktree add --detach mish/mash &&
182 test_must_fail git rev-parse mash -- &&
183 test_must_fail git -C mish/mash symbolic-ref HEAD
186 test_expect_success '"add" -b/-B mutually exclusive' '
187 test_must_fail git worktree add -b poodle -B poodle bamboo master
190 test_expect_success '"add" -b/--detach mutually exclusive' '
191 test_must_fail git worktree add -b poodle --detach bamboo master
194 test_expect_success '"add" -B/--detach mutually exclusive' '
195 test_must_fail git worktree add -B poodle --detach bamboo master
198 test_expect_success '"add -B" fails if the branch is checked out' '
199 git rev-parse newmaster >before &&
200 test_must_fail git worktree add -B newmaster bamboo master &&
201 git rev-parse newmaster >after &&
202 test_cmp before after
205 test_expect_success 'add -B' '
206 git worktree add -B poodle bamboo2 master^ &&
207 git -C bamboo2 symbolic-ref HEAD >actual &&
208 echo refs/heads/poodle >expected &&
209 test_cmp expected actual &&
210 test_cmp_rev master^ poodle
213 test_expect_success 'local clone from linked checkout' '
214 git clone --local here here-clone &&
215 ( cd here-clone && git fsck )
218 test_expect_success '"add" worktree with --no-checkout' '
219 git worktree add --no-checkout -b swamp swamp &&
220 ! test -e swamp/init.t &&
221 git -C swamp reset --hard &&
222 test_cmp init.t swamp/init.t
225 test_expect_success '"add" worktree with --checkout' '
226 git worktree add --checkout -b swmap2 swamp2 &&
227 test_cmp init.t swamp2/init.t
230 test_expect_success 'put a worktree under rebase' '
231 git worktree add under-rebase &&
233 cd under-rebase &&
234 set_fake_editor &&
235 FAKE_LINES="edit 1" git rebase -i HEAD^ &&
236 git worktree list | grep "under-rebase.*detached HEAD"
240 test_expect_success 'add a worktree, checking out a rebased branch' '
241 test_must_fail git worktree add new-rebase under-rebase &&
242 ! test -d new-rebase
245 test_expect_success 'checking out a rebased branch from another worktree' '
246 git worktree add new-place &&
247 test_must_fail git -C new-place checkout under-rebase
250 test_expect_success 'not allow to delete a branch under rebase' '
252 cd under-rebase &&
253 test_must_fail git branch -D under-rebase
257 test_expect_success 'rename a branch under rebase not allowed' '
258 test_must_fail git branch -M under-rebase rebase-with-new-name
261 test_expect_success 'check out from current worktree branch ok' '
263 cd under-rebase &&
264 git checkout under-rebase &&
265 git checkout - &&
266 git rebase --abort
270 test_expect_success 'checkout a branch under bisect' '
271 git worktree add under-bisect &&
273 cd under-bisect &&
274 git bisect start &&
275 git bisect bad &&
276 git bisect good HEAD~2 &&
277 git worktree list | grep "under-bisect.*detached HEAD" &&
278 test_must_fail git worktree add new-bisect under-bisect &&
279 ! test -d new-bisect
283 test_expect_success 'rename a branch under bisect not allowed' '
284 test_must_fail git branch -M under-bisect bisect-with-new-name
287 test_done