The twelfth batch
[git/gitster.git] / t / t2022-checkout-paths.sh
blobf1b709d58bef0080c1e8067b4b6e725b8141d027
1 #!/bin/sh
3 test_description='checkout $tree -- $paths'
4 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
5 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7 TEST_PASSES_SANITIZE_LEAK=true
8 . ./test-lib.sh
10 test_expect_success setup '
11 mkdir dir &&
12 >dir/main &&
13 echo common >dir/common &&
14 git add dir/main dir/common &&
15 test_tick && git commit -m "main has dir/main" &&
16 git checkout -b next &&
17 git mv dir/main dir/next0 &&
18 echo next >dir/next1 &&
19 git add dir &&
20 test_tick && git commit -m "next has dir/next but not dir/main"
23 test_expect_success 'checking out paths out of a tree does not clobber unrelated paths' '
24 git checkout next &&
25 git reset --hard &&
26 rm dir/next0 &&
27 cat dir/common >expect.common &&
28 echo modified >expect.next1 &&
29 cat expect.next1 >dir/next1 &&
30 echo untracked >expect.next2 &&
31 cat expect.next2 >dir/next2 &&
33 git checkout main dir &&
35 test_cmp expect.common dir/common &&
36 test_path_is_file dir/main &&
37 git diff --exit-code main dir/main &&
39 test_path_is_missing dir/next0 &&
40 test_cmp expect.next1 dir/next1 &&
41 test_path_is_file dir/next2 &&
42 test_must_fail git ls-files --error-unmatch dir/next2 &&
43 test_cmp expect.next2 dir/next2
46 test_expect_success 'do not touch unmerged entries matching $path but not in $tree' '
47 git checkout next &&
48 git reset --hard &&
50 cat dir/common >expect.common &&
51 EMPTY_SHA1=$(git hash-object -w --stdin </dev/null) &&
52 git rm dir/next0 &&
53 cat >expect.next0 <<-EOF &&
54 100644 $EMPTY_SHA1 1 dir/next0
55 100644 $EMPTY_SHA1 2 dir/next0
56 EOF
57 git update-index --index-info <expect.next0 &&
59 git checkout main dir &&
61 test_cmp expect.common dir/common &&
62 test_path_is_file dir/main &&
63 git diff --exit-code main dir/main &&
64 git ls-files -s dir/next0 >actual.next0 &&
65 test_cmp expect.next0 actual.next0
68 test_expect_success 'do not touch files that are already up-to-date' '
69 git reset --hard &&
70 echo one >file1 &&
71 echo two >file2 &&
72 git add file1 file2 &&
73 git commit -m base &&
74 echo modified >file1 &&
75 test-tool chmtime =1000000000 file2 &&
76 git update-index -q --refresh &&
77 git checkout HEAD -- file1 file2 &&
78 echo one >expect &&
79 test_cmp expect file1 &&
80 echo "1000000000" >expect &&
81 test-tool chmtime --get file2 >actual &&
82 test_cmp expect actual
85 test_expect_success 'checkout HEAD adds deleted intent-to-add file back to index' '
86 echo "nonempty" >nonempty &&
87 >empty &&
88 git add nonempty empty &&
89 git commit -m "create files to be deleted" &&
90 git rm --cached nonempty empty &&
91 git add -N nonempty empty &&
92 git checkout HEAD nonempty empty &&
93 git diff --cached --exit-code
96 test_done