Merge branch 'jk/diff-tree-t-fix' into next
[git/jrn.git] / t / t2025-checkout-to.sh
blob508993f8134a2deb3cc975c7c1e42a367df4296f
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 refuses to checkout locked branch' '
16 test_must_fail git checkout --to zere master &&
17 ! test -d zere &&
18 ! test -d .git/repos/zere
21 test_expect_success 'checkout --to a new worktree' '
22 git rev-parse HEAD >expect &&
23 git checkout --detach --to here master &&
25 cd here &&
26 test_cmp ../init.t init.t &&
27 test_must_fail git symbolic-ref HEAD &&
28 git rev-parse HEAD >actual &&
29 test_cmp ../expect actual &&
30 git fsck
34 test_expect_success 'checkout --to from a linked checkout' '
36 cd here &&
37 git checkout --detach --to nested-here master
38 cd nested-here &&
39 git fsck
43 test_expect_success 'checkout --to a new worktree creating new branch' '
44 git checkout --to there -b newmaster master &&
46 cd there &&
47 test_cmp ../init.t init.t &&
48 git symbolic-ref HEAD >actual &&
49 echo refs/heads/newmaster >expect &&
50 test_cmp expect actual &&
51 git fsck
55 test_expect_success 'die the same branch is already checked out' '
57 cd here &&
58 test_must_fail git checkout newmaster
62 test_expect_success 'not die on re-checking out current branch' '
64 cd there &&
65 git checkout newmaster
69 test_expect_success 'checkout --to from a bare repo' '
71 git clone --bare . bare &&
72 cd bare &&
73 git checkout --to ../there2 -b bare-master master
77 test_expect_success 'checkout from a bare repo without --to' '
79 cd bare &&
80 test_must_fail git checkout master
84 test_expect_success 'checkout with grafts' '
85 test_when_finished rm .git/info/grafts &&
86 test_commit abc &&
87 SHA1=`git rev-parse HEAD` &&
88 test_commit def &&
89 test_commit xyz &&
90 echo "`git rev-parse HEAD` $SHA1" >.git/info/grafts &&
91 cat >expected <<-\EOF &&
92 xyz
93 abc
94 EOF
95 git log --format=%s -2 >actual &&
96 test_cmp expected actual &&
97 git checkout --detach --to grafted master &&
98 git --git-dir=grafted/.git log --format=%s -2 >actual &&
99 test_cmp expected actual
102 test_done