checkout: don't require a work tree when checking out into a new one
[git/jrn.git] / t / t2025-checkout-to.sh
blobb0d97a05016c3ca91b0d50c16c58b22b5af7edb8
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 a new worktree' '
16 git rev-parse HEAD >expect &&
17 git checkout --to here master &&
19 cd here &&
20 test_cmp ../init.t init.t &&
21 test_must_fail git symbolic-ref HEAD &&
22 git rev-parse HEAD >actual &&
23 test_cmp ../expect actual &&
24 git fsck
28 test_expect_success 'checkout --to from a linked checkout' '
30 cd here &&
31 git checkout --to nested-here master
32 cd nested-here &&
33 git fsck
37 test_expect_success 'checkout --to a new worktree creating new branch' '
38 git checkout --to there -b newmaster master &&
40 cd there &&
41 test_cmp ../init.t init.t &&
42 git symbolic-ref HEAD >actual &&
43 echo refs/heads/newmaster >expect &&
44 test_cmp expect actual &&
45 git fsck
49 test_expect_success 'detach if the same branch is already checked out' '
51 cd here &&
52 git checkout newmaster &&
53 test_must_fail git symbolic-ref HEAD
57 test_expect_success 'not detach on re-checking out current branch' '
59 cd there &&
60 git checkout newmaster &&
61 git symbolic-ref HEAD
65 test_expect_success 'checkout --to from a bare repo' '
67 git clone --bare . bare &&
68 cd bare &&
69 git checkout --to ../there2 master
73 test_expect_success 'checkout from a bare repo without --to' '
75 cd bare &&
76 test_must_fail git checkout master
80 test_done