path: root/builtin-diff.c
diff options
authorWincent Colaiuta <>2007-12-13 20:24:52 (GMT)
committerJunio C Hamano <>2007-12-14 07:05:42 (GMT)
commit62c64895cfcf3bbf34969a69fa96a631f7d5b14e (patch)
treeba4176915a9320356f245f401913d2bfa9992b43 /builtin-diff.c
parent913b45f51b151d8e29f86df67d3e10853d831470 (diff)
"diff --check" should affect exit status
"git diff" has a --check option that can be used to check for whitespace problems but it only reported by printing warnings to the console. Now when the --check option is used we give a non-zero exit status, making "git diff --check" nicer to use in scripts and hooks. Signed-off-by: Wincent Colaiuta <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 'builtin-diff.c')
1 files changed, 4 insertions, 2 deletions
diff --git a/builtin-diff.c b/builtin-diff.c
index 55fb84c..9d878f6 100644
--- a/builtin-diff.c
+++ b/builtin-diff.c
@@ -247,7 +247,8 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
/* If the user asked for our exit code then don't start a
* pager or we would end up reporting its exit code instead.
- if (!DIFF_OPT_TST(&rev.diffopt, EXIT_WITH_STATUS))
+ if (!DIFF_OPT_TST(&rev.diffopt, EXIT_WITH_STATUS) &&
+ (!(rev.diffopt.output_format & DIFF_FORMAT_CHECKDIFF)))
/* Do we have --cached and not have a pending object, then
@@ -353,7 +354,8 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
ent, ents);
if (DIFF_OPT_TST(&rev.diffopt, EXIT_WITH_STATUS))
result = DIFF_OPT_TST(&rev.diffopt, HAS_CHANGES) != 0;
+ if (rev.diffopt.output_format & DIFF_FORMAT_CHECKDIFF)
+ return DIFF_OPT_TST(&rev.diffopt, CHECK_FAILED) != 0;
if (1 < rev.diffopt.skip_stat_unmatch)
return result;