Skip to content

Commit 068df18

Browse files
committed
Merge branch 'rs/external-diff-with-exit-code'
The "--exit-code" option of "git diff" command learned to work with the "--ext-diff" option. * rs/external-diff-with-exit-code: diff: fix --exit-code with external diff diff: report unmerged paths as changes in run_diff_cmd()
2 parents 3fc99d0 + 11be65c commit 068df18

File tree

3 files changed

+47
-3
lines changed

3 files changed

+47
-3
lines changed

diff.c

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include "setup.h"
4141
#include "strmap.h"
4242
#include "ws.h"
43+
#include "write-or-die.h"
4344

4445
#ifdef NO_FAST_WORKING_DIRECTORY
4546
#define FAST_WORKING_DIRECTORY 0
@@ -4404,8 +4405,33 @@ static void run_external_diff(const char *pgm,
44044405
diff_free_filespec_data(one);
44054406
diff_free_filespec_data(two);
44064407
cmd.use_shell = 1;
4407-
if (run_command(&cmd))
4408-
die(_("external diff died, stopping at %s"), name);
4408+
if (o->flags.diff_from_contents) {
4409+
int got_output = 0;
4410+
cmd.out = -1;
4411+
if (start_command(&cmd))
4412+
die(_("external diff died, stopping at %s"), name);
4413+
for (;;) {
4414+
char buffer[8192];
4415+
ssize_t len = xread(cmd.out, buffer, sizeof(buffer));
4416+
if (!len)
4417+
break;
4418+
if (len < 0)
4419+
die(_("unable to read from external diff,"
4420+
" stopping at %s"), name);
4421+
got_output = 1;
4422+
if (write_in_full(1, buffer, len) < 0)
4423+
die(_("unable to write output of external diff,"
4424+
" stopping at %s"), name);
4425+
}
4426+
close(cmd.out);
4427+
if (finish_command(&cmd))
4428+
die(_("external diff died, stopping at %s"), name);
4429+
if (got_output)
4430+
o->found_changes = 1;
4431+
} else {
4432+
if (run_command(&cmd))
4433+
die(_("external diff died, stopping at %s"), name);
4434+
}
44094435

44104436
remove_tempfile();
44114437
}
@@ -4555,6 +4581,7 @@ static void run_diff_cmd(const char *pgm,
45554581
o, complete_rewrite);
45564582
} else {
45574583
fprintf(o->file, "* Unmerged path %s\n", name);
4584+
o->found_changes = 1;
45584585
}
45594586
}
45604587

@@ -4851,6 +4878,7 @@ void diff_setup_done(struct diff_options *options)
48514878
*/
48524879

48534880
if ((options->xdl_opts & XDF_WHITESPACE_FLAGS) ||
4881+
options->flags.exit_with_status ||
48544882
options->ignore_regex_nr)
48554883
options->flags.diff_from_contents = 1;
48564884
else
@@ -6741,7 +6769,7 @@ void diff_flush(struct diff_options *options)
67416769
if (output_format & DIFF_FORMAT_CALLBACK)
67426770
options->format_callback(q, options, options->format_callback_data);
67436771

6744-
if (output_format & DIFF_FORMAT_NO_OUTPUT &&
6772+
if ((!output_format || output_format & DIFF_FORMAT_NO_OUTPUT) &&
67456773
options->flags.exit_with_status &&
67466774
options->flags.diff_from_contents) {
67476775
/*

t/t4020-diff-external.sh

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

175+
test_expect_success 'diff.external and --exit-code with output' '
176+
test_expect_code 1 git -c diff.external=echo diff --exit-code
177+
'
178+
179+
test_expect_success 'diff.external and --exit-code without output' '
180+
git -c diff.external=true diff --exit-code
181+
'
182+
175183
echo NULZbetweenZwords | perl -pe 'y/Z/\000/' > file
176184

177185
test_expect_success 'force diff with "diff"' '

t/t4046-diff-unmerged.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,12 @@ test_expect_success 'diff --stat' '
9898
test_cmp diff-stat.expect diff-stat.actual
9999
'
100100

101+
test_expect_success 'diff --quiet' '
102+
test_expect_code 1 git diff --cached --quiet
103+
'
104+
105+
test_expect_success 'diff --quiet --ignore-all-space' '
106+
test_expect_code 1 git diff --cached --quiet --ignore-all-space
107+
'
108+
101109
test_done

0 commit comments

Comments
 (0)