From 41bbf9d58575095234c64df979ee884334469758 Mon Sep 17 00:00:00 2001 From: Alex Riesen Date: Wed, 14 Mar 2007 01:17:04 +0100 Subject: Allow git-diff exit with codes similar to diff(1) This introduces a new command-line option: --exit-code. The diff programs will return 1 for differences, return 0 for equality, and something else for errors. Signed-off-by: Alex Riesen Signed-off-by: Junio C Hamano --- diff.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'diff.c') diff --git a/diff.c b/diff.c index 954ca83e0b..cc818011b9 100644 --- a/diff.c +++ b/diff.c @@ -2134,6 +2134,8 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac) options->color_diff = options->color_diff_words = 1; else if (!strcmp(arg, "--no-renames")) options->detect_rename = 0; + else if (!strcmp(arg, "--exit-code")) + options->exit_with_status = 1; else return 0; return 1; @@ -2910,6 +2912,8 @@ void diffcore_std(struct diff_options *options) diffcore_order(options->orderfile); diff_resolve_rename_copy(); diffcore_apply_filter(options->filter); + if (options->exit_with_status) + options->has_changes = !!diff_queued_diff.nr; } @@ -2920,6 +2924,8 @@ void diffcore_std_no_resolve(struct diff_options *options) if (options->orderfile) diffcore_order(options->orderfile); diffcore_apply_filter(options->filter); + if (options->exit_with_status) + options->has_changes = !!diff_queued_diff.nr; } void diff_addremove(struct diff_options *options, -- cgit v1.2.3