3 test_description
='add -i basic tests'
6 test_expect_success
'setup (initial)' '
12 test_expect_success
'status works (initial)' '
13 git add -i </dev/null >output &&
14 grep "+1/-0 *+2/-0 file" output
18 index 0000000..d95f3ad
24 test_expect_success
'diff works (initial)' '
25 (echo d; echo 1) | git add -i >output &&
26 sed -ne "/new file/,/content/p" <output >diff &&
27 test_cmp expected diff
29 test_expect_success
'revert works (initial)' '
31 (echo r; echo 1) | git add -i &&
32 git ls-files >output &&
36 test_expect_success
'setup (commit)' '
37 echo baseline >file &&
39 git commit -m commit &&
40 echo content >>file &&
45 test_expect_success
'status works (commit)' '
46 git add -i </dev/null >output &&
47 grep "+1/-0 *+2/-0 file" output
50 index 180b47c..b6f2c08 100644
57 test_expect_success
'diff works (commit)' '
58 (echo d; echo 1) | git add -i >output &&
59 sed -ne "/^index/,/content/p" <output >diff &&
60 test_cmp expected diff
62 test_expect_success
'revert works (commit)' '
64 (echo r; echo 1) | git add -i &&
65 git add -i </dev/null >output &&
66 grep "unchanged *+3/-0 file" output
71 cat >fake_editor.sh
<<EOF
73 chmod a
+x fake_editor.sh
74 test_set_editor
"$(pwd)/fake_editor.sh"
75 test_expect_success
'dummy edit works' '
76 (echo e; echo a) | git add -p &&
78 test_cmp expected diff
88 echo "#!$SHELL_PATH" >fake_editor.sh
89 cat >>fake_editor.sh
<<\EOF
90 mv -f "$1" oldpatch
&&
93 chmod a
+x fake_editor.sh
94 test_set_editor
"$(pwd)/fake_editor.sh"
95 test_expect_success
'bad edit rejected' '
97 (echo e; echo n; echo d) | git add -p >output &&
98 grep "hunk does not apply" output
105 test_expect_success
'garbage edit rejected' '
107 (echo e; echo n; echo d) | git add -p >output &&
108 grep "hunk does not apply" output
119 diff --git a/file b/file
120 index b5dd6c9..f910ae9 100644
130 test_expect_success
'real edit works' '
131 (echo e; echo n; echo d) | git add -p &&
133 test_cmp expected output
136 if test "$(git config --bool core.filemode)" = false
138 say
'skipping filemode tests (filesystem does not properly support modes)'
140 test_set_prereq FILEMODE
143 test_expect_success FILEMODE
'patch does not affect mode' '
145 echo content >>file &&
147 printf "n\\ny\\n" | git add -p &&
148 git show :file | grep content &&
149 git diff file | grep "new mode"
152 test_expect_success FILEMODE
'stage mode but not hunk' '
154 echo content >>file &&
156 printf "y\\nn\\n" | git add -p &&
157 git diff --cached file | grep "new mode" &&
158 git diff file | grep "+content"
161 # end of tests disabled when filemode is not usable