3 test_description='compare full workdir to sparse workdir'
7 test_expect_success 'setup' '
8 git init initial-repo &&
12 echo "after deep" >e &&
13 echo "after folder1" >g &&
15 mkdir folder1 folder2 deep x &&
16 mkdir deep/deeper1 deep/deeper2 &&
17 mkdir deep/deeper1/deepest &&
18 echo "after deeper1" >deep/e &&
19 echo "after deepest" >deep/deeper1/e &&
26 cp a deep/deeper1/deepest &&
27 cp -r deep/deeper1/deepest deep/deeper2 &&
29 git commit -m "initial commit" &&
30 git checkout -b base &&
31 for dir in folder1 folder2 deep
33 git checkout -b update-$dir &&
34 echo "updated $dir" >$dir/a &&
35 git commit -a -m "update $dir" || return 1
38 git checkout -b rename-base base &&
39 echo >folder1/larger-content <<-\EOF &&
46 cp folder1/larger-content folder2/ &&
47 cp folder1/larger-content deep/deeper1/ &&
49 git commit -m "add interesting rename content" &&
51 git checkout -b rename-out-to-out rename-base &&
52 mv folder1/a folder2/b &&
53 mv folder1/larger-content folder2/edited-content &&
54 echo >>folder2/edited-content &&
56 git commit -m "rename folder1/... to folder2/..." &&
58 git checkout -b rename-out-to-in rename-base &&
59 mv folder1/a deep/deeper1/b &&
60 mv folder1/larger-content deep/deeper1/edited-content &&
61 echo >>deep/deeper1/edited-content &&
63 git commit -m "rename folder1/... to deep/deeper1/..." &&
65 git checkout -b rename-in-to-out rename-base &&
66 mv deep/deeper1/a folder1/b &&
67 mv deep/deeper1/larger-content folder1/edited-content &&
68 echo >>folder1/edited-content &&
70 git commit -m "rename deep/deeper1/... to folder1/..." &&
72 git checkout -b deepest base &&
73 echo "updated deepest" >deep/deeper1/deepest/a &&
74 git commit -a -m "update deepest" &&
76 git checkout -f base &&
82 rm -rf full-checkout sparse-checkout sparse-index &&
84 # create repos in initial state
85 cp -r initial-repo full-checkout &&
86 git -C full-checkout reset --hard &&
88 cp -r initial-repo sparse-checkout &&
89 git -C sparse-checkout reset --hard &&
90 git -C sparse-checkout sparse-checkout init --cone &&
92 # initialize sparse-checkout definitions
93 git -C sparse-checkout sparse-checkout set deep
99 $* >../sparse-checkout-out 2>../sparse-checkout-err
106 $* >../full-checkout-out 2>../full-checkout-err
113 test_cmp full-checkout-out sparse-checkout-out &&
114 test_cmp full-checkout-err sparse-checkout-err
117 test_expect_success 'status with options' '
119 test_all_match git status --porcelain=v2 &&
120 test_all_match git status --porcelain=v2 -z -u &&
121 test_all_match git status --porcelain=v2 -uno &&
122 run_on_all "touch README.md" &&
123 test_all_match git status --porcelain=v2 &&
124 test_all_match git status --porcelain=v2 -z -u &&
125 test_all_match git status --porcelain=v2 -uno &&
126 test_all_match git add README.md &&
127 test_all_match git status --porcelain=v2 &&
128 test_all_match git status --porcelain=v2 -z -u &&
129 test_all_match git status --porcelain=v2 -uno
132 test_expect_success 'add, commit, checkout' '
135 write_script edit-contents <<-\EOF &&
138 run_on_all "../edit-contents README.md" &&
140 test_all_match git add README.md &&
141 test_all_match git status --porcelain=v2 &&
142 test_all_match git commit -m "Add README.md" &&
144 test_all_match git checkout HEAD~1 &&
145 test_all_match git checkout - &&
147 run_on_all "../edit-contents README.md" &&
149 test_all_match git add -A &&
150 test_all_match git status --porcelain=v2 &&
151 test_all_match git commit -m "Extend README.md" &&
153 test_all_match git checkout HEAD~1 &&
154 test_all_match git checkout - &&
156 run_on_all "../edit-contents deep/newfile" &&
158 test_all_match git status --porcelain=v2 -uno &&
159 test_all_match git status --porcelain=v2 &&
160 test_all_match git add . &&
161 test_all_match git status --porcelain=v2 &&
162 test_all_match git commit -m "add deep/newfile" &&
164 test_all_match git checkout HEAD~1 &&
165 test_all_match git checkout -
168 test_expect_success 'checkout and reset --hard' '
171 test_all_match git checkout update-folder1 &&
172 test_all_match git status --porcelain=v2 &&
174 test_all_match git checkout update-deep &&
175 test_all_match git status --porcelain=v2 &&
177 test_all_match git checkout -b reset-test &&
178 test_all_match git reset --hard deepest &&
179 test_all_match git reset --hard update-folder1 &&
180 test_all_match git reset --hard update-folder2
183 test_expect_success 'diff --staged' '
186 write_script edit-contents <<-\EOF &&
187 echo text >>README.md
189 run_on_all "../edit-contents" &&
191 test_all_match git diff &&
192 test_all_match git diff --staged &&
193 test_all_match git add README.md &&
194 test_all_match git diff &&
195 test_all_match git diff --staged
198 test_expect_success 'diff with renames' '
201 for branch in rename-out-to-out rename-out-to-in rename-in-to-out
203 test_all_match git checkout rename-base &&
204 test_all_match git checkout $branch -- .&&
205 test_all_match git diff --staged --no-renames &&
206 test_all_match git diff --staged --find-renames || return 1
210 test_expect_success 'log with pathspec outside sparse definition' '
213 test_all_match git log -- a &&
214 test_all_match git log -- folder1/a &&
215 test_all_match git log -- folder2/a &&
216 test_all_match git log -- deep/a &&
217 test_all_match git log -- deep/deeper1/a &&
218 test_all_match git log -- deep/deeper1/deepest/a &&
220 test_all_match git checkout update-folder1 &&
221 test_all_match git log -- folder1/a
224 test_expect_success 'blame with pathspec inside sparse definition' '
227 test_all_match git blame a &&
228 test_all_match git blame deep/a &&
229 test_all_match git blame deep/deeper1/a &&
230 test_all_match git blame deep/deeper1/deepest/a
233 # TODO: blame currently does not support blaming files outside of the
234 # sparse definition. It complains that the file doesn't exist locally.
235 test_expect_failure 'blame with pathspec outside sparse definition' '
238 test_all_match git blame folder1/a &&
239 test_all_match git blame folder2/a &&
240 test_all_match git blame deep/deeper2/a &&
241 test_all_match git blame deep/deeper2/deepest/a
244 # TODO: reset currently does not behave as expected when in a
246 test_expect_failure 'checkout and reset (mixed)' '
249 test_all_match git checkout -b reset-test update-deep &&
250 test_all_match git reset deepest &&
251 test_all_match git reset update-folder1 &&
252 test_all_match git reset update-folder2
255 test_expect_success 'merge' '
258 test_all_match git checkout -b merge update-deep &&
259 test_all_match git merge -m "folder1" update-folder1 &&
260 test_all_match git rev-parse HEAD^{tree} &&
261 test_all_match git merge -m "folder2" update-folder2 &&
262 test_all_match git rev-parse HEAD^{tree}
265 test_expect_success 'merge with outside renames' '
268 for type in out-to-out out-to-in in-to-out
270 test_all_match git reset --hard &&
271 test_all_match git checkout -f -b merge-$type update-deep &&
272 test_all_match git merge -m "$type" rename-$type &&
273 test_all_match git rev-parse HEAD^{tree} || return 1
277 test_expect_success 'clean' '
280 echo bogus >>.gitignore &&
281 run_on_all cp ../.gitignore . &&
282 test_all_match git add .gitignore &&
283 test_all_match git commit -m ignore-bogus-files &&
285 run_on_sparse mkdir folder1 &&
286 run_on_all touch folder1/bogus &&
288 test_all_match git status --porcelain=v2 &&
289 test_all_match git clean -f &&
290 test_all_match git status --porcelain=v2 &&
292 test_all_match git clean -xf &&
293 test_all_match git status --porcelain=v2 &&
295 test_all_match git clean -xdf &&
296 test_all_match git status --porcelain=v2 &&
298 test_path_is_dir sparse-checkout/folder1