3 test_description='add -i basic tests'
6 if ! test_have_prereq PERL
8 skip_all='skipping add -i tests, perl not available'
12 test_expect_success 'setup (initial)' '
18 test_expect_success 'status works (initial)' '
19 git add -i </dev/null >output &&
20 grep "+1/-0 *+2/-0 file" output
23 test_expect_success 'setup expected' '
26 index 0000000..d95f3ad
34 test_expect_success 'diff works (initial)' '
35 (echo d; echo 1) | git add -i >output &&
36 sed -ne "/new file/,/content/p" <output >diff &&
37 test_cmp expected diff
39 test_expect_success 'revert works (initial)' '
41 (echo r; echo 1) | git add -i &&
42 git ls-files >output &&
46 test_expect_success 'setup (commit)' '
47 echo baseline >file &&
49 git commit -m commit &&
50 echo content >>file &&
55 test_expect_success 'status works (commit)' '
56 git add -i </dev/null >output &&
57 grep "+1/-0 *+2/-0 file" output
60 test_expect_success 'setup expected' '
62 index 180b47c..b6f2c08 100644
71 test_expect_success 'diff works (commit)' '
72 (echo d; echo 1) | git add -i >output &&
73 sed -ne "/^index/,/content/p" <output >diff &&
74 test_cmp expected diff
76 test_expect_success 'revert works (commit)' '
78 (echo r; echo 1) | git add -i &&
79 git add -i </dev/null >output &&
80 grep "unchanged *+3/-0 file" output
84 test_expect_success 'setup expected' '
89 test_expect_success 'setup fake editor' '
91 chmod a+x fake_editor.sh &&
92 test_set_editor "$(pwd)/fake_editor.sh"
95 test_expect_success 'dummy edit works' '
96 (echo e; echo a) | git add -p &&
98 test_cmp expected diff
101 test_expect_success 'setup patch' '
111 test_expect_success 'setup fake editor' '
112 echo "#!$SHELL_PATH" >fake_editor.sh &&
113 cat >>fake_editor.sh <<\EOF &&
114 mv -f "$1" oldpatch &&
117 chmod a+x fake_editor.sh &&
118 test_set_editor "$(pwd)/fake_editor.sh"
121 test_expect_success 'bad edit rejected' '
123 (echo e; echo n; echo d) | git add -p >output &&
124 grep "hunk does not apply" output
127 test_expect_success 'setup patch' '
134 test_expect_success 'garbage edit rejected' '
136 (echo e; echo n; echo d) | git add -p >output &&
137 grep "hunk does not apply" output
140 test_expect_success 'setup patch' '
150 test_expect_success 'setup expected' '
152 diff --git a/file b/file
153 index b5dd6c9..f910ae9 100644
165 test_expect_success 'real edit works' '
166 (echo e; echo n; echo d) | git add -p &&
168 test_cmp expected output
171 test_expect_success 'skip files similarly as commit -a' '
173 echo file >.gitignore &&
174 echo changed >file &&
175 echo y | git add -p file &&
178 git commit -am commit &&
179 git diff >expected &&
180 test_cmp expected output &&
181 git reset --hard HEAD^
185 test_expect_success FILEMODE 'patch does not affect mode' '
187 echo content >>file &&
189 printf "n\\ny\\n" | git add -p &&
190 git show :file | grep content &&
191 git diff file | grep "new mode"
194 test_expect_success FILEMODE 'stage mode but not hunk' '
196 echo content >>file &&
198 printf "y\\nn\\n" | git add -p &&
199 git diff --cached file | grep "new mode" &&
200 git diff file | grep "+content"
204 test_expect_success FILEMODE 'stage mode and hunk' '
206 echo content >>file &&
208 printf "y\\ny\\n" | git add -p &&
209 git diff --cached file | grep "new mode" &&
210 git diff --cached file | grep "+content" &&
211 test -z "$(git diff file)"
214 # end of tests disabled when filemode is not usable
216 test_expect_success 'setup again' '
218 test_chmod +x file &&
222 # Write the patch file with a new line at the top and bottom
223 test_expect_success 'setup patch' '
225 index 180b47c..b6f2c08 100644
236 # Expected output, similar to the patch but w/ diff at the top
237 test_expect_success 'setup expected' '
239 diff --git a/file b/file
240 index b6f2c08..61b9053 100755
251 # Test splitting the first patch, then adding both
252 test_expect_success 'add first line works' '
253 git commit -am "clear local changes" &&
255 (echo s; echo y; echo y) | git add -p file &&
256 git diff --cached > diff &&
257 test_cmp expected diff
260 test_expect_success 'setup expected' '
262 diff --git a/non-empty b/non-empty
263 deleted file mode 100644
264 index d95f3ad..0000000
272 test_expect_success 'deleting a non-empty file' '
274 echo content >non-empty &&
276 git commit -m non-empty &&
278 echo y | git add -p non-empty &&
279 git diff --cached >diff &&
280 test_cmp expected diff
283 test_expect_success 'setup expected' '
285 diff --git a/empty b/empty
286 deleted file mode 100644
287 index e69de29..0000000
291 test_expect_success 'deleting an empty file' '
295 git commit -m empty &&
297 echo y | git add -p empty &&
298 git diff --cached >diff &&
299 test_cmp expected diff
302 test_expect_success 'split hunk setup' '
304 for i in 10 20 30 40 50 60
310 git commit -m test &&
312 for i in 10 15 20 21 22 23 24 30 40 50 60
318 test_expect_success 'split hunk "add -p (edit)"' '
319 # Split, say Edit and do nothing. Then:
321 # 1. Broken version results in a patch that does not apply and
322 # only takes [y/n] (edit again) so the first q is discarded
323 # and then n attempts to discard the edit. Repeat q enough
326 # 2. Correct version applies the (not)edited version, and asks
327 # about the next hunk, against which we say q and program
333 EDITOR=: git add -p &&
338 test_expect_success 'patch mode ignores unmerged entries' '
340 test_commit conflict &&
341 test_commit non-conflict &&
342 git checkout -b side &&
343 test_commit side conflict.t &&
344 git checkout master &&
345 test_commit master conflict.t &&
346 test_must_fail git merge side &&
347 echo changed >non-conflict.t &&
348 echo y | git add -p >output &&
349 ! grep a/conflict.t output &&
350 cat >expected <<-\EOF &&
351 * Unmerged path conflict.t
352 diff --git a/non-conflict.t b/non-conflict.t
353 index f766221..5ea2ed4 100644
360 git diff --cached >diff &&
361 test_cmp expected diff