mirror of
https://github.com/git/git
synced 2024-10-02 14:45:21 +00:00
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()
This commit is contained in:
commit
068df18c90
30
diff.c
30
diff.c
|
@ -40,6 +40,7 @@
|
||||||
#include "setup.h"
|
#include "setup.h"
|
||||||
#include "strmap.h"
|
#include "strmap.h"
|
||||||
#include "ws.h"
|
#include "ws.h"
|
||||||
|
#include "write-or-die.h"
|
||||||
|
|
||||||
#ifdef NO_FAST_WORKING_DIRECTORY
|
#ifdef NO_FAST_WORKING_DIRECTORY
|
||||||
#define FAST_WORKING_DIRECTORY 0
|
#define FAST_WORKING_DIRECTORY 0
|
||||||
|
@ -4404,8 +4405,33 @@ static void run_external_diff(const char *pgm,
|
||||||
diff_free_filespec_data(one);
|
diff_free_filespec_data(one);
|
||||||
diff_free_filespec_data(two);
|
diff_free_filespec_data(two);
|
||||||
cmd.use_shell = 1;
|
cmd.use_shell = 1;
|
||||||
|
if (o->flags.diff_from_contents) {
|
||||||
|
int got_output = 0;
|
||||||
|
cmd.out = -1;
|
||||||
|
if (start_command(&cmd))
|
||||||
|
die(_("external diff died, stopping at %s"), name);
|
||||||
|
for (;;) {
|
||||||
|
char buffer[8192];
|
||||||
|
ssize_t len = xread(cmd.out, buffer, sizeof(buffer));
|
||||||
|
if (!len)
|
||||||
|
break;
|
||||||
|
if (len < 0)
|
||||||
|
die(_("unable to read from external diff,"
|
||||||
|
" stopping at %s"), name);
|
||||||
|
got_output = 1;
|
||||||
|
if (write_in_full(1, buffer, len) < 0)
|
||||||
|
die(_("unable to write output of external diff,"
|
||||||
|
" stopping at %s"), name);
|
||||||
|
}
|
||||||
|
close(cmd.out);
|
||||||
|
if (finish_command(&cmd))
|
||||||
|
die(_("external diff died, stopping at %s"), name);
|
||||||
|
if (got_output)
|
||||||
|
o->found_changes = 1;
|
||||||
|
} else {
|
||||||
if (run_command(&cmd))
|
if (run_command(&cmd))
|
||||||
die(_("external diff died, stopping at %s"), name);
|
die(_("external diff died, stopping at %s"), name);
|
||||||
|
}
|
||||||
|
|
||||||
remove_tempfile();
|
remove_tempfile();
|
||||||
}
|
}
|
||||||
|
@ -4555,6 +4581,7 @@ static void run_diff_cmd(const char *pgm,
|
||||||
o, complete_rewrite);
|
o, complete_rewrite);
|
||||||
} else {
|
} else {
|
||||||
fprintf(o->file, "* Unmerged path %s\n", name);
|
fprintf(o->file, "* Unmerged path %s\n", name);
|
||||||
|
o->found_changes = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4851,6 +4878,7 @@ void diff_setup_done(struct diff_options *options)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ((options->xdl_opts & XDF_WHITESPACE_FLAGS) ||
|
if ((options->xdl_opts & XDF_WHITESPACE_FLAGS) ||
|
||||||
|
options->flags.exit_with_status ||
|
||||||
options->ignore_regex_nr)
|
options->ignore_regex_nr)
|
||||||
options->flags.diff_from_contents = 1;
|
options->flags.diff_from_contents = 1;
|
||||||
else
|
else
|
||||||
|
@ -6741,7 +6769,7 @@ void diff_flush(struct diff_options *options)
|
||||||
if (output_format & DIFF_FORMAT_CALLBACK)
|
if (output_format & DIFF_FORMAT_CALLBACK)
|
||||||
options->format_callback(q, options, options->format_callback_data);
|
options->format_callback(q, options, options->format_callback_data);
|
||||||
|
|
||||||
if (output_format & DIFF_FORMAT_NO_OUTPUT &&
|
if ((!output_format || output_format & DIFF_FORMAT_NO_OUTPUT) &&
|
||||||
options->flags.exit_with_status &&
|
options->flags.exit_with_status &&
|
||||||
options->flags.diff_from_contents) {
|
options->flags.diff_from_contents) {
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -172,6 +172,14 @@ test_expect_success 'no diff with -diff' '
|
||||||
grep Binary out
|
grep Binary out
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'diff.external and --exit-code with output' '
|
||||||
|
test_expect_code 1 git -c diff.external=echo diff --exit-code
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'diff.external and --exit-code without output' '
|
||||||
|
git -c diff.external=true diff --exit-code
|
||||||
|
'
|
||||||
|
|
||||||
echo NULZbetweenZwords | perl -pe 'y/Z/\000/' > file
|
echo NULZbetweenZwords | perl -pe 'y/Z/\000/' > file
|
||||||
|
|
||||||
test_expect_success 'force diff with "diff"' '
|
test_expect_success 'force diff with "diff"' '
|
||||||
|
|
|
@ -98,4 +98,12 @@ test_expect_success 'diff --stat' '
|
||||||
test_cmp diff-stat.expect diff-stat.actual
|
test_cmp diff-stat.expect diff-stat.actual
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'diff --quiet' '
|
||||||
|
test_expect_code 1 git diff --cached --quiet
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'diff --quiet --ignore-all-space' '
|
||||||
|
test_expect_code 1 git diff --cached --quiet --ignore-all-space
|
||||||
|
'
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
|
Loading…
Reference in a new issue