3 test_description
='add -i basic tests'
5 .
"$TEST_DIRECTORY"/lib-prereq-FILEMODE.sh
7 test_expect_success PERL
'setup (initial)' '
13 test_expect_success PERL
'status works (initial)' '
14 git add -i </dev/null >output &&
15 grep "+1/-0 *+2/-0 file" output
18 test_expect_success PERL
'setup expected' '
21 index 0000000..d95f3ad
29 test_expect_success PERL
'diff works (initial)' '
30 (echo d; echo 1) | git add -i >output &&
31 sed -ne "/new file/,/content/p" <output >diff &&
32 test_cmp expected diff
34 test_expect_success PERL
'revert works (initial)' '
36 (echo r; echo 1) | git add -i &&
37 git ls-files >output &&
41 test_expect_success PERL
'setup (commit)' '
42 echo baseline >file &&
44 git commit -m commit &&
45 echo content >>file &&
50 test_expect_success PERL
'status works (commit)' '
51 git add -i </dev/null >output &&
52 grep "+1/-0 *+2/-0 file" output
55 test_expect_success PERL
'setup expected' '
57 index 180b47c..b6f2c08 100644
66 test_expect_success PERL
'diff works (commit)' '
67 (echo d; echo 1) | git add -i >output &&
68 sed -ne "/^index/,/content/p" <output >diff &&
69 test_cmp expected diff
71 test_expect_success PERL
'revert works (commit)' '
73 (echo r; echo 1) | git add -i &&
74 git add -i </dev/null >output &&
75 grep "unchanged *+3/-0 file" output
79 test_expect_success PERL
'setup expected' '
84 test_expect_success PERL
'setup fake editor' '
86 chmod a+x fake_editor.sh &&
87 test_set_editor "$(pwd)/fake_editor.sh"
90 test_expect_success PERL
'dummy edit works' '
91 (echo e; echo a) | git add -p &&
93 test_cmp expected diff
96 test_expect_success PERL
'setup patch' '
106 test_expect_success PERL
'setup fake editor' '
107 echo "#!$SHELL_PATH" >fake_editor.sh &&
108 cat >>fake_editor.sh <<\EOF &&
109 mv -f "$1" oldpatch &&
112 chmod a+x fake_editor.sh &&
113 test_set_editor "$(pwd)/fake_editor.sh"
116 test_expect_success PERL
'bad edit rejected' '
118 (echo e; echo n; echo d) | git add -p >output &&
119 grep "hunk does not apply" output
122 test_expect_success PERL
'setup patch' '
129 test_expect_success PERL
'garbage edit rejected' '
131 (echo e; echo n; echo d) | git add -p >output &&
132 grep "hunk does not apply" output
135 test_expect_success PERL
'setup patch' '
145 test_expect_success PERL
'setup expected' '
147 diff --git a/file b/file
148 index b5dd6c9..f910ae9 100644
160 test_expect_success PERL
'real edit works' '
161 (echo e; echo n; echo d) | git add -p &&
163 test_cmp expected output
166 test_expect_success PERL
'skip files similarly as commit -a' '
168 echo file >.gitignore &&
169 echo changed >file &&
170 echo y | git add -p file &&
173 git commit -am commit &&
174 git diff >expected &&
175 test_cmp expected output &&
176 git reset --hard HEAD^
180 test_expect_success PERL
,FILEMODE
'patch does not affect mode' '
182 echo content >>file &&
184 printf "n\\ny\\n" | git add -p &&
185 git show :file | grep content &&
186 git diff file | grep "new mode"
189 test_expect_success PERL
,FILEMODE
'stage mode but not hunk' '
191 echo content >>file &&
193 printf "y\\nn\\n" | git add -p &&
194 git diff --cached file | grep "new mode" &&
195 git diff file | grep "+content"
199 test_expect_success PERL
,FILEMODE
'stage mode and hunk' '
201 echo content >>file &&
203 printf "y\\ny\\n" | git add -p &&
204 git diff --cached file | grep "new mode" &&
205 git diff --cached file | grep "+content" &&
206 test -z "$(git diff file)"
209 # end of tests disabled when filemode is not usable
211 test_expect_success PERL
'setup again' '
213 test_chmod +x file &&
217 # Write the patch file with a new line at the top and bottom
218 test_expect_success PERL
'setup patch' '
220 index 180b47c..b6f2c08 100644
231 # Expected output, similar to the patch but w/ diff at the top
232 test_expect_success PERL
'setup expected' '
234 diff --git a/file b/file
235 index b6f2c08..61b9053 100755
246 # Test splitting the first patch, then adding both
247 test_expect_success PERL
'add first line works' '
248 git commit -am "clear local changes" &&
250 (echo s; echo y; echo y) | git add -p file &&
251 git diff --cached > diff &&
252 test_cmp expected diff
255 test_expect_success PERL
'setup expected' '
257 diff --git a/non-empty b/non-empty
258 deleted file mode 100644
259 index d95f3ad..0000000
267 test_expect_success PERL
'deleting a non-empty file' '
269 echo content >non-empty &&
271 git commit -m non-empty &&
273 echo y | git add -p non-empty &&
274 git diff --cached >diff &&
275 test_cmp expected diff
278 test_expect_success PERL
'setup expected' '
280 diff --git a/empty b/empty
281 deleted file mode 100644
282 index e69de29..0000000
286 test_expect_success PERL
'deleting an empty file' '
290 git commit -m empty &&
292 echo y | git add -p empty &&
293 git diff --cached >diff &&
294 test_cmp expected diff
297 test_expect_success PERL
'split hunk setup' '
299 for i in 10 20 30 40 50 60
305 git commit -m test &&
307 for i in 10 15 20 21 22 23 24 30 40 50 60
313 test_expect_success PERL
'split hunk "add -p (edit)"' '
314 # Split, say Edit and do nothing. Then:
316 # 1. Broken version results in a patch that does not apply and
317 # only takes [y/n] (edit again) so the first q is discarded
318 # and then n attempts to discard the edit. Repeat q enough
321 # 2. Correct version applies the (not)edited version, and asks
322 # about the next hunk, against wich we say q and program
328 EDITOR=: git add -p &&
333 test_expect_success
'patch mode ignores unmerged entries' '
335 test_commit conflict &&
336 test_commit non-conflict &&
337 git checkout -b side &&
338 test_commit side conflict.t &&
339 git checkout master &&
340 test_commit master conflict.t &&
341 test_must_fail git merge side &&
342 echo changed >non-conflict.t &&
343 echo y | git add -p >output &&
344 ! grep a/conflict.t output &&
345 cat >expected <<-\EOF &&
346 * Unmerged path conflict.t
347 diff --git a/non-conflict.t b/non-conflict.t
348 index f766221..5ea2ed4 100644
355 git diff --cached >diff &&
356 test_cmp expected diff