t4020: test exit code with external diffs
Add tests to check the exit code of git diff with its options --quiet and --exit-code when using an external diff program. Currently we cannot tell whether it found significant changes or not. While at it, document briefly that --quiet turns off execution of external diff programs because that behavior surprised me for a moment while writing the tests. Signed-off-by: René Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
René Scharfe committed
Jun 9, 2024 at 09:38 UTC
33be6cf51acf74e623fb3c4e287f7aebbedf5c09
2 files changed
+54
Documentation/diff-options.txt
+1
@@ -820,6 +820,7 @@ ifndef::git-log[]
820
821
--quiet::
822
Disable all output of the program. Implies `--exit-code`.
823
+ Disables execution of external diff helpers.
824
endif::git-log[]
825
endif::git-format-patch[]
826
t/t4020-diff-external.sh
+53
@@ -172,6 +172,59 @@ test_expect_success 'no diff with -diff' '
172
grep Binary out
173
'
174
175
+check_external_diff () {
176
+ expect_code=$1
177
+ expect_out=$2
178
+ expect_err=$3
179
+ command_code=$4
180
+ shift 4
181
+ options="$@"
182
+
183
+ command="echo output; exit $command_code;"
184
+ desc="external diff '$command'"
185
+ with_options="${options:+ with }$options"
186
+
187
+ test_expect_success "$desc via attribute$with_options" "
188
+ test_config diff.foo.command \"$command\" &&
189
+ echo \"file diff=foo\" >.gitattributes &&
190
+ test_expect_code $expect_code git diff $options >out 2>err &&
191
+ test_cmp $expect_out out &&
192
+ test_cmp $expect_err err
193
+ "
194
+
195
+ test_expect_success "$desc via diff.external$with_options" "
196
+ test_config diff.external \"$command\" &&
197
+ >.gitattributes &&
198
+ test_expect_code $expect_code git diff $options >out 2>err &&
199
+ test_cmp $expect_out out &&
200
+ test_cmp $expect_err err
201
+ "
202
+
203
+ test_expect_success "$desc via GIT_EXTERNAL_DIFF$with_options" "
204
+ >.gitattributes &&
205
+ test_expect_code $expect_code env \
206
+ GIT_EXTERNAL_DIFF=\"$command\" \
207
+ git diff $options >out 2>err &&
208
+ test_cmp $expect_out out &&
209
+ test_cmp $expect_err err
210
+ "
211
+}
212
+
213
+test_expect_success 'setup output files' '
214
+ : >empty &&
215
+ echo output >output &&
216
+ echo "fatal: external diff died, stopping at file" >error
217
+'
218
+
219
+check_external_diff 0 output empty 0
220
+check_external_diff 128 output error 1
221
+
222
+check_external_diff 1 output empty 0 --exit-code
223
+check_external_diff 128 output error 1 --exit-code
224
+
225
+check_external_diff 1 empty empty 0 --quiet
226
+check_external_diff 1 empty empty 1 --quiet # we don't even call the program
227
+
228
echo NULZbetweenZwords | perl -pe 'y/Z/\000/' > file
229
230
test_expect_success 'force diff with "diff"' '