From 6977c250ac6cacb5ee441bff832fdeab4d0cd8f9 Mon Sep 17 00:00:00 2001 From: Larry D'Anna Date: Tue, 16 Feb 2010 01:55:21 -0500 Subject: [PATCH 1/2] git diff --quiet -w: check and report the status The option -w tells the diff machinery to inspect the contents to set the exit status, instead of checking the blob object level difference alone. However, --quiet tells the diff machinery not to look at the contents, which means DIFF_FROM_CONTENTS has no chance to inspect the change. Work it around by calling diff_flush_patch() with output sent to /dev/null. Signed-off-by: Larry D'Anna Signed-off-by: Junio C Hamano --- diff.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/diff.c b/diff.c index 381cc8d4fd..7216b1e8db 100644 --- a/diff.c +++ b/diff.c @@ -3520,6 +3520,29 @@ void diff_flush(struct diff_options *options) separator++; } + if (output_format & DIFF_FORMAT_NO_OUTPUT && + DIFF_OPT_TST(options, EXIT_WITH_STATUS) && + DIFF_OPT_TST(options, DIFF_FROM_CONTENTS)) { + /* + * run diff_flush_patch for the exit status. setting + * options->file to /dev/null should be safe, becaue we + * aren't supposed to produce any output anyway. + */ + if (options->close_file) + fclose(options->file); + options->file = fopen("/dev/null", "w"); + if (!options->file) + die_errno("Could not open /dev/null"); + options->close_file = 1; + for (i = 0; i < q->nr; i++) { + struct diff_filepair *p = q->queue[i]; + if (check_pair_status(p)) + diff_flush_patch(p, options); + if (options->found_changes) + break; + } + } + if (output_format & DIFF_FORMAT_PATCH) { if (separator) { putc(options->line_termination, options->file); From 1caaf225f86b7b1818103e72774e191fb1f3d0bb Mon Sep 17 00:00:00 2001 From: Larry D'Anna Date: Sun, 21 Feb 2010 21:58:44 -0500 Subject: [PATCH 2/2] git-diff: add a test for git diff --quiet -w This patch adds two test cases for: 6977c25 git diff --quiet -w: check and report the status Signed-off-by: Larry D'Anna Signed-off-by: Junio C Hamano --- t/t4017-diff-retval.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/t/t4017-diff-retval.sh b/t/t4017-diff-retval.sh index 60dd2014d5..0391a5827e 100755 --- a/t/t4017-diff-retval.sh +++ b/t/t4017-diff-retval.sh @@ -5,6 +5,9 @@ test_description='Return value of diffs' . ./test-lib.sh test_expect_success 'setup' ' + echo "1 " >a && + git add . && + git commit -m zeroth && echo 1 >a && git add . && git commit -m first && @@ -13,6 +16,18 @@ test_expect_success 'setup' ' git commit -a -m second ' +test_expect_success 'git diff --quiet -w HEAD^^ HEAD^' ' + git diff --quiet -w HEAD^^ HEAD^ +' + +test_expect_success 'git diff --quiet HEAD^^ HEAD^' ' + test_must_fail git diff --quiet HEAD^^ HEAD^ +' + +test_expect_success 'git diff --quiet -w HEAD^ HEAD' ' + test_must_fail git diff --quiet -w HEAD^ HEAD +' + test_expect_success 'git diff-tree HEAD^ HEAD' ' git diff-tree --exit-code HEAD^ HEAD test $? = 1