]>
Commit | Line | Data |
---|---|---|
0a1283bc JH |
1 | #!/bin/sh |
2 | ||
3 | test_description='checkout $tree -- $paths' | |
883b98ef | 4 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
334afbc7 JS |
5 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
6 | ||
9081a421 | 7 | TEST_PASSES_SANITIZE_LEAK=true |
0a1283bc JH |
8 | . ./test-lib.sh |
9 | ||
10 | test_expect_success setup ' | |
11 | mkdir dir && | |
883b98ef | 12 | >dir/main && |
0a1283bc | 13 | echo common >dir/common && |
883b98ef JS |
14 | git add dir/main dir/common && |
15 | test_tick && git commit -m "main has dir/main" && | |
0a1283bc | 16 | git checkout -b next && |
883b98ef | 17 | git mv dir/main dir/next0 && |
0a1283bc JH |
18 | echo next >dir/next1 && |
19 | git add dir && | |
883b98ef | 20 | test_tick && git commit -m "next has dir/next but not dir/main" |
0a1283bc JH |
21 | ' |
22 | ||
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 && | |
32 | ||
883b98ef | 33 | git checkout main dir && |
0a1283bc JH |
34 | |
35 | test_cmp expect.common dir/common && | |
883b98ef JS |
36 | test_path_is_file dir/main && |
37 | git diff --exit-code main dir/main && | |
0a1283bc JH |
38 | |
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 | |
44 | ' | |
45 | ||
e721c154 NTND |
46 | test_expect_success 'do not touch unmerged entries matching $path but not in $tree' ' |
47 | git checkout next && | |
48 | git reset --hard && | |
49 | ||
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 && | |
58 | ||
883b98ef | 59 | git checkout main dir && |
e721c154 NTND |
60 | |
61 | test_cmp expect.common dir/common && | |
883b98ef JS |
62 | test_path_is_file dir/main && |
63 | git diff --exit-code main dir/main && | |
e721c154 NTND |
64 | git ls-files -s dir/next0 >actual.next0 && |
65 | test_cmp expect.next0 actual.next0 | |
66 | ' | |
67 | ||
c5326bd6 JK |
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 && | |
0e496492 | 75 | test-tool chmtime =1000000000 file2 && |
c5326bd6 JK |
76 | git update-index -q --refresh && |
77 | git checkout HEAD -- file1 file2 && | |
78 | echo one >expect && | |
79 | test_cmp expect file1 && | |
decf711f | 80 | echo "1000000000" >expect && |
deb9845a | 81 | test-tool chmtime --get file2 >actual && |
c5326bd6 JK |
82 | test_cmp expect actual |
83 | ' | |
84 | ||
ecd72042 VN |
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 | |
94 | ' | |
95 | ||
0a1283bc | 96 | test_done |