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' '
85 cat >fake_editor.sh <<EOF
87 chmod a+x fake_editor.sh &&
88 test_set_editor "$(pwd)/fake_editor.sh" &&
91 test_expect_success PERL
'dummy edit works' '
92 (echo e; echo a) | git add -p &&
94 test_cmp expected diff
97 test_expect_success PERL
'setup patch' '
107 test_expect_success PERL
'setup fake editor' '
108 echo "#!$SHELL_PATH" >fake_editor.sh &&
109 cat >>fake_editor.sh <<\EOF &&
110 mv -f "$1" oldpatch &&
113 chmod a+x fake_editor.sh &&
114 test_set_editor "$(pwd)/fake_editor.sh"
117 test_expect_success PERL
'bad edit rejected' '
119 (echo e; echo n; echo d) | git add -p >output &&
120 grep "hunk does not apply" output
123 test_expect_success PERL
'setup patch' '
130 test_expect_success PERL
'garbage edit rejected' '
132 (echo e; echo n; echo d) | git add -p >output &&
133 grep "hunk does not apply" output
136 test_expect_success PERL
'setup patch' '
146 test_expect_success PERL
'setup expected' '
148 diff --git a/file b/file
149 index b5dd6c9..f910ae9 100644
161 test_expect_success PERL
'real edit works' '
162 (echo e; echo n; echo d) | git add -p &&
164 test_cmp expected output
167 test_expect_success PERL
'skip files similarly as commit -a' '
169 echo file >.gitignore &&
170 echo changed >file &&
171 echo y | git add -p file &&
174 git commit -am commit &&
175 git diff >expected &&
176 test_cmp expected output &&
177 git reset --hard HEAD^
181 test_expect_success PERL
,FILEMODE
'patch does not affect mode' '
183 echo content >>file &&
185 printf "n\\ny\\n" | git add -p &&
186 git show :file | grep content &&
187 git diff file | grep "new mode"
190 test_expect_success PERL
,FILEMODE
'stage mode but not hunk' '
192 echo content >>file &&
194 printf "y\\nn\\n" | git add -p &&
195 git diff --cached file | grep "new mode" &&
196 git diff file | grep "+content"
200 test_expect_success PERL
,FILEMODE
'stage mode and hunk' '
202 echo content >>file &&
204 printf "y\\ny\\n" | git add -p &&
205 git diff --cached file | grep "new mode" &&
206 git diff --cached file | grep "+content" &&
207 test -z "$(git diff file)"
210 # end of tests disabled when filemode is not usable
212 test_expect_success PERL
'setup again' '
214 test_chmod +x file &&
218 # Write the patch file with a new line at the top and bottom
219 test_expect_success PERL
'setup patch' '
221 index 180b47c..b6f2c08 100644
232 # Expected output, similar to the patch but w/ diff at the top
233 test_expect_success PERL
'setup expected' '
235 diff --git a/file b/file
236 index b6f2c08..61b9053 100755
247 # Test splitting the first patch, then adding both
248 test_expect_success PERL
'add first line works' '
249 git commit -am "clear local changes" &&
251 (echo s; echo y; echo y) | git add -p file &&
252 git diff --cached > diff &&
253 test_cmp expected diff
256 test_expect_success PERL
'setup expected' '
258 diff --git a/non-empty b/non-empty
259 deleted file mode 100644
260 index d95f3ad..0000000
268 test_expect_success PERL
'deleting a non-empty file' '
270 echo content >non-empty &&
272 git commit -m non-empty &&
274 echo y | git add -p non-empty &&
275 git diff --cached >diff &&
276 test_cmp expected diff
279 test_expect_success PERL
'setup expected' '
281 diff --git a/empty b/empty
282 deleted file mode 100644
283 index e69de29..0000000
287 test_expect_success PERL
'deleting an empty file' '
291 git commit -m empty &&
293 echo y | git add -p empty &&
294 git diff --cached >diff &&
295 test_cmp expected diff