3 test_description='checkout $tree -- $paths'
4 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
5 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
9 test_expect_success setup '
12 echo common >dir/common &&
13 git add dir/main dir/common &&
14 test_tick && git commit -m "main has dir/main" &&
15 git checkout -b next &&
16 git mv dir/main dir/next0 &&
17 echo next >dir/next1 &&
19 test_tick && git commit -m "next has dir/next but not dir/main"
22 test_expect_success 'checking out paths out of a tree does not clobber unrelated paths' '
26 cat dir/common >expect.common &&
27 echo modified >expect.next1 &&
28 cat expect.next1 >dir/next1 &&
29 echo untracked >expect.next2 &&
30 cat expect.next2 >dir/next2 &&
32 git checkout main dir &&
34 test_cmp expect.common dir/common &&
35 test_path_is_file dir/main &&
36 git diff --exit-code main dir/main &&
38 test_path_is_missing dir/next0 &&
39 test_cmp expect.next1 dir/next1 &&
40 test_path_is_file dir/next2 &&
41 test_must_fail git ls-files --error-unmatch dir/next2 &&
42 test_cmp expect.next2 dir/next2
45 test_expect_success 'do not touch unmerged entries matching $path but not in $tree' '
49 cat dir/common >expect.common &&
50 EMPTY_SHA1=$(git hash-object -w --stdin </dev/null) &&
52 cat >expect.next0 <<-EOF &&
53 100644 $EMPTY_SHA1 1 dir/next0
54 100644 $EMPTY_SHA1 2 dir/next0
56 git update-index --index-info <expect.next0 &&
58 git checkout main dir &&
60 test_cmp expect.common dir/common &&
61 test_path_is_file dir/main &&
62 git diff --exit-code main dir/main &&
63 git ls-files -s dir/next0 >actual.next0 &&
64 test_cmp expect.next0 actual.next0
67 test_expect_success 'do not touch files that are already up-to-date' '
71 git add file1 file2 &&
73 echo modified >file1 &&
74 test-tool chmtime =1000000000 file2 &&
75 git update-index -q --refresh &&
76 git checkout HEAD -- file1 file2 &&
78 test_cmp expect file1 &&
79 echo "1000000000" >expect &&
80 test-tool chmtime --get file2 >actual &&
81 test_cmp expect actual
84 test_expect_success 'checkout HEAD adds deleted intent-to-add file back to index' '
85 echo "nonempty" >nonempty &&
87 git add nonempty empty &&
88 git commit -m "create files to be deleted" &&
89 git rm --cached nonempty empty &&
90 git add -N nonempty empty &&
91 git checkout HEAD nonempty empty &&
92 git diff --cached --exit-code