checkout: fix bug with --to and relative HEAD
[git/mingw.git] / t / t2025-checkout-to.sh
blob0fd731b4bc5d53fe63a7dd8a73457a6e916b7b98
1 #!/bin/sh
3 test_description='test git checkout --to'
5 . ./test-lib.sh
7 test_expect_success 'setup' '
8 test_commit init
11 test_expect_success 'checkout --to not updating paths' '
12 test_must_fail git checkout --to -- init.t
15 test_expect_success 'checkout --to an existing worktree' '
16 mkdir -p existing/subtree &&
17 test_must_fail git checkout --detach --to existing master
20 test_expect_success 'checkout --to an existing empty worktree' '
21 mkdir existing_empty &&
22 git checkout --detach --to existing_empty master
25 test_expect_success 'checkout --to refuses to checkout locked branch' '
26 test_must_fail git checkout --to zere master &&
27 ! test -d zere &&
28 ! test -d .git/worktrees/zere
31 test_expect_success 'checking out paths not complaining about linked checkouts' '
33 cd existing_empty &&
34 echo dirty >>init.t &&
35 git checkout master -- init.t
39 test_expect_success 'checkout --to a new worktree' '
40 git rev-parse HEAD >expect &&
41 git checkout --detach --to here master &&
43 cd here &&
44 test_cmp ../init.t init.t &&
45 test_must_fail git symbolic-ref HEAD &&
46 git rev-parse HEAD >actual &&
47 test_cmp ../expect actual &&
48 git fsck
52 test_expect_success 'checkout --to a new worktree from a subdir' '
54 mkdir sub &&
55 cd sub &&
56 git checkout --detach --to here master &&
57 cd here &&
58 test_cmp ../../init.t init.t
62 test_expect_success 'checkout --to from a linked checkout' '
64 cd here &&
65 git checkout --detach --to nested-here master &&
66 cd nested-here &&
67 git fsck
71 test_expect_success 'checkout --to a new worktree creating new branch' '
72 git checkout --to there -b newmaster master &&
74 cd there &&
75 test_cmp ../init.t init.t &&
76 git symbolic-ref HEAD >actual &&
77 echo refs/heads/newmaster >expect &&
78 test_cmp expect actual &&
79 git fsck
83 test_expect_success 'die the same branch is already checked out' '
85 cd here &&
86 test_must_fail git checkout newmaster
90 test_expect_success 'not die the same branch is already checked out' '
92 cd here &&
93 git checkout --ignore-other-worktrees --to anothernewmaster newmaster
97 test_expect_success 'not die on re-checking out current branch' '
99 cd there &&
100 git checkout newmaster
104 test_expect_success 'checkout --to from a bare repo' '
106 git clone --bare . bare &&
107 cd bare &&
108 git checkout --to ../there2 -b bare-master master
112 test_expect_success 'checkout from a bare repo without --to' '
114 cd bare &&
115 test_must_fail git checkout master
119 test_expect_success 'checkout with grafts' '
120 test_when_finished rm .git/info/grafts &&
121 test_commit abc &&
122 SHA1=`git rev-parse HEAD` &&
123 test_commit def &&
124 test_commit xyz &&
125 echo "`git rev-parse HEAD` $SHA1" >.git/info/grafts &&
126 cat >expected <<-\EOF &&
130 git log --format=%s -2 >actual &&
131 test_cmp expected actual &&
132 git checkout --detach --to grafted master &&
133 git --git-dir=grafted/.git log --format=%s -2 >actual &&
134 test_cmp expected actual
137 test_expect_success 'checkout --to from relative HEAD' '
138 test_commit a &&
139 test_commit b &&
140 test_commit c &&
141 git rev-parse HEAD~1 >expected &&
142 git checkout --to relhead HEAD~1 &&
143 git -C relhead rev-parse HEAD >actual &&
144 test_cmp expected actual
147 test_done