git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tim Henigan <tim.henigan@gmail.com>
To: gitster@pobox.com, git@vger.kernel.org, peff@peff.net
Cc: Tim Henigan <tim.henigan@gmail.com>
Subject: [PATCH v2] diff-no-index: exit(1) if 'diff --quiet <repo file> <external file>' finds changes
Date: Fri, 15 Jun 2012 16:06:47 -0400	[thread overview]
Message-ID: <1339790807-28346-1-git-send-email-tim.henigan@gmail.com> (raw)

When running 'git diff --quiet <file1> <file2>', if file1 or file2
is outside the repository, it will exit(0) even if the files differ.
It should exit(1) when they differ.

Signed-off-by: Tim Henigan <tim.henigan@gmail.com>
---

Changes in v2:
  - Implemented the fix in diff-no-index.c as suggested by Junio
    Hamano.  The previous version affected the performance of all
    diff commands that used the '--quiet' option by forcing the
    code through the expensive (and in this case unneccesary)
    'diff_flush_patch' code path.
  - Updated the test to use 'test_expect_code' as suggested by
    Jeff King.


 diff-no-index.c       | 3 ++-
 t/t4035-diff-quiet.sh | 4 ++++
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/diff-no-index.c b/diff-no-index.c
index f0b0010..b935d2a 100644
--- a/diff-no-index.c
+++ b/diff-no-index.c
@@ -273,5 +273,6 @@ void diff_no_index(struct rev_info *revs,
 	 * The return code for --no-index imitates diff(1):
 	 * 0 = no changes, 1 = changes, else error
 	 */
-	exit(revs->diffopt.found_changes);
+	int result = diff_result_code(&revs->diffopt, 0);
+	exit(result);
 }
diff --git a/t/t4035-diff-quiet.sh b/t/t4035-diff-quiet.sh
index cdb9202..0b83235 100755
--- a/t/t4035-diff-quiet.sh
+++ b/t/t4035-diff-quiet.sh
@@ -76,4 +77,8 @@ test_expect_success 'git diff-index --cached HEAD' '
 	}
 '
 
+test_expect_success 'git diff <tracked file> <file outside repo>' '
+	test_expect_code 1 git diff --quiet c /dev/null
+'
+
 test_done
-- 
1.7.11.rc3.6.g894ec42.dirty

                 reply	other threads:[~2012-06-15 20:07 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1339790807-28346-1-git-send-email-tim.henigan@gmail.com \
    --to=tim.henigan@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=peff@peff.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).