unit-tests: do not mistake `.pdb` files for being executable
[git.git] / t / t7012-skip-worktree-writing.sh
blobcd5c20fe51b3727035d56245c17568030f87d455
1 #!/bin/sh
3 # Copyright (c) 2008 Nguyễn Thái Ngọc Duy
6 test_description='test worktree writing operations when skip-worktree is used'
8 . ./test-lib.sh
10 test_expect_success 'setup' '
11 test_commit init &&
12 echo modified >> init.t &&
13 touch added &&
14 git add init.t added &&
15 git commit -m "modified and added" &&
16 git tag top
19 test_expect_success 'read-tree updates worktree, absent case' '
20 git checkout -f top &&
21 git update-index --skip-worktree init.t &&
22 rm init.t &&
23 git read-tree -m -u HEAD^ &&
24 echo init > expected &&
25 test_cmp expected init.t
28 test_expect_success 'read-tree updates worktree, dirty case' '
29 git checkout -f top &&
30 git update-index --skip-worktree init.t &&
31 echo dirty >> init.t &&
32 test_must_fail git read-tree -m -u HEAD^ &&
33 grep -q dirty init.t &&
34 test "$(git ls-files -t init.t)" = "S init.t" &&
35 git update-index --no-skip-worktree init.t
38 test_expect_success 'read-tree removes worktree, absent case' '
39 git checkout -f top &&
40 git update-index --skip-worktree added &&
41 rm added &&
42 git read-tree -m -u HEAD^ &&
43 test ! -f added
46 test_expect_success 'read-tree removes worktree, dirty case' '
47 git checkout -f top &&
48 git update-index --skip-worktree added &&
49 echo dirty >> added &&
50 test_must_fail git read-tree -m -u HEAD^ &&
51 grep -q dirty added &&
52 test "$(git ls-files -t added)" = "S added" &&
53 git update-index --no-skip-worktree added
56 setup_absent() {
57 test -f 1 && rm 1
58 git update-index --remove 1 &&
59 git update-index --add --cacheinfo 100644 $EMPTY_BLOB 1 &&
60 git update-index --skip-worktree 1
63 setup_dirty() {
64 git update-index --force-remove 1 &&
65 echo dirty > 1 &&
66 git update-index --add --cacheinfo 100644 $EMPTY_BLOB 1 &&
67 git update-index --skip-worktree 1
70 test_dirty() {
71 echo "100644 $EMPTY_BLOB 0 1" > expected &&
72 git ls-files --stage 1 > result &&
73 test_cmp expected result &&
74 echo dirty > expected
75 test_cmp expected 1
78 cat >expected <<EOF
79 S 1
80 H 2
81 H init.t
82 S sub/1
83 H sub/2
84 EOF
86 test_expect_success 'index setup' '
87 git checkout -f init &&
88 mkdir sub &&
89 touch ./1 ./2 sub/1 sub/2 &&
90 git add 1 2 sub/1 sub/2 &&
91 git update-index --skip-worktree 1 sub/1 &&
92 git ls-files -t > result &&
93 test_cmp expected result
96 test_expect_success 'git-rm fails if worktree is dirty' '
97 setup_dirty &&
98 test_must_fail git rm 1 &&
99 test_dirty
102 cat >expected <<EOF
103 Would remove expected
104 Would remove result
106 test_expect_success 'git-clean, absent case' '
107 setup_absent &&
108 git clean -n > result &&
109 test_cmp expected result
112 test_expect_success 'git-clean, dirty case' '
113 setup_dirty &&
114 git clean -n > result &&
115 test_cmp expected result
118 test_expect_success '--ignore-skip-worktree-entries leaves worktree alone' '
119 test_commit keep-me &&
120 git update-index --skip-worktree keep-me.t &&
121 rm keep-me.t &&
123 : ignoring the worktree &&
124 git update-index --remove --ignore-skip-worktree-entries keep-me.t &&
125 git diff-index --cached --exit-code HEAD &&
127 : not ignoring the worktree, a deletion is staged &&
128 git update-index --remove keep-me.t &&
129 test_must_fail git diff-index --cached --exit-code HEAD \
130 --diff-filter=D -- keep-me.t
133 test_expect_success 'stash restore in sparse checkout' '
134 test_create_repo stash-restore &&
136 cd stash-restore &&
138 mkdir subdir &&
139 echo A >subdir/A &&
140 echo untouched >untouched &&
141 echo removeme >removeme &&
142 echo modified >modified &&
143 git add . &&
144 git commit -m Initial &&
146 echo AA >>subdir/A &&
147 echo addme >addme &&
148 echo tweaked >>modified &&
149 rm removeme &&
150 git add addme &&
152 git stash push &&
154 git sparse-checkout set --no-cone subdir &&
156 # Ensure after sparse-checkout we only have expected files
157 cat >expect <<-EOF &&
158 S modified
159 S removeme
160 H subdir/A
161 S untouched
163 git ls-files -t >actual &&
164 test_cmp expect actual &&
166 test_path_is_missing addme &&
167 test_path_is_missing modified &&
168 test_path_is_missing removeme &&
169 test_path_is_file subdir/A &&
170 test_path_is_missing untouched &&
172 # Put a file in the working directory in the way
173 echo in the way >modified &&
174 test_must_fail git stash apply 2>error&&
176 grep "changes.*would be overwritten by merge" error &&
178 echo in the way >expect &&
179 test_cmp expect modified &&
180 git diff --quiet HEAD ":!modified" &&
182 # ...and that working directory reflects the files correctly
183 test_path_is_missing addme &&
184 test_path_is_file modified &&
185 test_path_is_missing removeme &&
186 test_path_is_file subdir/A &&
187 test_path_is_missing untouched
191 #TODO test_expect_failure 'git-apply adds file' false
192 #TODO test_expect_failure 'git-apply updates file' false
193 #TODO test_expect_failure 'git-apply removes file' false
194 #TODO test_expect_failure 'git-mv to skip-worktree' false
195 #TODO test_expect_failure 'git-mv from skip-worktree' false
196 #TODO test_expect_failure 'git-checkout' false
198 test_done