t2025: add a test to make sure grafts is working from a linked checkout
[alt-git.git] / t / t2025-checkout-to.sh
blobeddd3251f1faede8cbfb0c9f6db501f0facfe063
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 existing &&
17 test_must_fail git checkout --detach --to existing master
20 test_expect_success 'checkout --to refuses to checkout locked branch' '
21 test_must_fail git checkout --to zere master &&
22 ! test -d zere &&
23 ! test -d .git/worktrees/zere
26 test_expect_success 'checkout --to a new worktree' '
27 git rev-parse HEAD >expect &&
28 git checkout --detach --to here master &&
30 cd here &&
31 test_cmp ../init.t init.t &&
32 test_must_fail git symbolic-ref HEAD &&
33 git rev-parse HEAD >actual &&
34 test_cmp ../expect actual &&
35 git fsck
39 test_expect_success 'checkout --to a new worktree from a subdir' '
41 mkdir sub &&
42 cd sub &&
43 git checkout --detach --to here master &&
44 cd here &&
45 test_cmp ../../init.t init.t
49 test_expect_success 'checkout --to from a linked checkout' '
51 cd here &&
52 git checkout --detach --to nested-here master &&
53 cd nested-here &&
54 git fsck
58 test_expect_success 'checkout --to a new worktree creating new branch' '
59 git checkout --to there -b newmaster master &&
61 cd there &&
62 test_cmp ../init.t init.t &&
63 git symbolic-ref HEAD >actual &&
64 echo refs/heads/newmaster >expect &&
65 test_cmp expect actual &&
66 git fsck
70 test_expect_success 'die the same branch is already checked out' '
72 cd here &&
73 test_must_fail git checkout newmaster
77 test_expect_success 'not die on re-checking out current branch' '
79 cd there &&
80 git checkout newmaster
84 test_expect_success 'checkout --to from a bare repo' '
86 git clone --bare . bare &&
87 cd bare &&
88 git checkout --to ../there2 -b bare-master master
92 test_expect_success 'checkout from a bare repo without --to' '
94 cd bare &&
95 test_must_fail git checkout master
99 test_expect_success 'checkout with grafts' '
100 test_when_finished rm .git/info/grafts &&
101 test_commit abc &&
102 SHA1=`git rev-parse HEAD` &&
103 test_commit def &&
104 test_commit xyz &&
105 echo "`git rev-parse HEAD` $SHA1" >.git/info/grafts &&
106 cat >expected <<-\EOF &&
110 git log --format=%s -2 >actual &&
111 test_cmp expected actual &&
112 git checkout --detach --to grafted master &&
113 git --git-dir=grafted/.git log --format=%s -2 >actual &&
114 test_cmp expected actual
117 test_done