3 test_description='add -i basic tests'
6 if ! test_have_prereq PERL; then
7 say 'skipping git add -i tests, perl not available'
11 test_expect_success 'setup (initial)' '
17 test_expect_success 'status works (initial)' '
18 git add -i </dev/null >output &&
19 grep "+1/-0 *+2/-0 file" output
23 index 0000000..d95f3ad
29 test_expect_success '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 'revert works (initial)' '
36 (echo r; echo 1) | git add -i &&
37 git ls-files >output &&
41 test_expect_success 'setup (commit)' '
42 echo baseline >file &&
44 git commit -m commit &&
45 echo content >>file &&
50 test_expect_success 'status works (commit)' '
51 git add -i </dev/null >output &&
52 grep "+1/-0 *+2/-0 file" output
55 index 180b47c..b6f2c08 100644
62 test_expect_success 'diff works (commit)' '
63 (echo d; echo 1) | git add -i >output &&
64 sed -ne "/^index/,/content/p" <output >diff &&
65 test_cmp expected diff
67 test_expect_success 'revert works (commit)' '
69 (echo r; echo 1) | git add -i &&
70 git add -i </dev/null >output &&
71 grep "unchanged *+3/-0 file" output
76 cat >fake_editor.sh <<EOF
78 chmod a+x fake_editor.sh
79 test_set_editor "$(pwd)/fake_editor.sh"
80 test_expect_success 'dummy edit works' '
81 (echo e; echo a) | git add -p &&
83 test_cmp expected diff
93 echo "#!$SHELL_PATH" >fake_editor.sh
94 cat >>fake_editor.sh <<\EOF
95 mv -f "$1" oldpatch &&
98 chmod a+x fake_editor.sh
99 test_set_editor "$(pwd)/fake_editor.sh"
100 test_expect_success 'bad edit rejected' '
102 (echo e; echo n; echo d) | git add -p >output &&
103 grep "hunk does not apply" output
110 test_expect_success 'garbage edit rejected' '
112 (echo e; echo n; echo d) | git add -p >output &&
113 grep "hunk does not apply" output
124 diff --git a/file b/file
125 index b5dd6c9..f910ae9 100644
135 test_expect_success 'real edit works' '
136 (echo e; echo n; echo d) | git add -p &&
138 test_cmp expected output
141 if test "$(git config --bool core.filemode)" = false
143 say 'skipping filemode tests (filesystem does not properly support modes)'
145 test_set_prereq FILEMODE
148 test_expect_success FILEMODE 'patch does not affect mode' '
150 echo content >>file &&
152 printf "n\\ny\\n" | git add -p &&
153 git show :file | grep content &&
154 git diff file | grep "new mode"
157 test_expect_success FILEMODE 'stage mode but not hunk' '
159 echo content >>file &&
161 printf "y\\nn\\n" | git add -p &&
162 git diff --cached file | grep "new mode" &&
163 git diff file | grep "+content"
166 # end of tests disabled when filemode is not usable
168 test_expect_success 'setup again' '
170 test_chmod +x file &&
174 # Write the patch file with a new line at the top and bottom
176 index 180b47c..b6f2c08 100644
185 # Expected output, similar to the patch but w/ diff at the top
187 diff --git a/file b/file
188 index b6f2c08..61b9053 100755
197 # Test splitting the first patch, then adding both
198 test_expect_success 'add first line works' '
199 git commit -am "clear local changes" &&
201 (echo s; echo y; echo y) | git add -p file &&
202 git diff --cached > diff &&
203 test_cmp expected diff