diff --no-index: also imitate the exit status of diff(1)
diff sets the exit status to 0 when no changes were found, to 1 when changes were found, and 2 means error. We imitate this to be able to use "git diff" in the test scripts. (Actually, keeping in line with the rest of git, -1 is returned on error, which corresponds to an exit status 255). To find out if the diff is not empty, a member called "found_changes" was introduced in struct diff_options, which is set in builtin_diff() and fn_out_consume(). Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <junkio@cox.net>
This commit is contained in:
committed by
Junio C Hamano
parent
048f48a2fd
commit
34a5e1a2d9
11
diff-lib.c
11
diff-lib.c
@ -210,11 +210,16 @@ int run_diff_files_cmd(struct rev_info *revs, int argc, const char **argv)
|
||||
if (revs->max_count == -2) {
|
||||
if (revs->diffopt.nr_paths != 2)
|
||||
return error("need two files/directories with --no-index");
|
||||
queue_diff(&revs->diffopt, revs->diffopt.paths[0],
|
||||
revs->diffopt.paths[1]);
|
||||
if (queue_diff(&revs->diffopt, revs->diffopt.paths[0],
|
||||
revs->diffopt.paths[1]))
|
||||
return -1;
|
||||
diffcore_std(&revs->diffopt);
|
||||
diff_flush(&revs->diffopt);
|
||||
return 0;
|
||||
/*
|
||||
* The return code for --no-index imitates diff(1):
|
||||
* 0 = no changes, 1 = changes, else error
|
||||
*/
|
||||
return revs->diffopt.found_changes;
|
||||
}
|
||||
|
||||
if (read_cache() < 0) {
|
||||
|
||||
Reference in New Issue
Block a user