Skip to content

Commit 33be6cf

Browse files
rscharfegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1b76f06 commit 33be6cf

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

Documentation/diff-options.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,7 @@ ifndef::git-log[]
820820

821821
--quiet::
822822
Disable all output of the program. Implies `--exit-code`.
823+
Disables execution of external diff helpers.
823824
endif::git-log[]
824825
endif::git-format-patch[]
825826

t/t4020-diff-external.sh

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,59 @@ test_expect_success 'no diff with -diff' '
172172
grep Binary out
173173
'
174174

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+
175228
echo NULZbetweenZwords | perl -pe 'y/Z/\000/' > file
176229

177230
test_expect_success 'force diff with "diff"' '

0 commit comments

Comments
 (0)