From: Tim Henigan <tim.henigan@gmail.com>
To: gitster@pobox.com, git@vger.kernel.org
Cc: Tim Henigan <tim.henigan@gmail.com>
Subject: [PATCH] diff: exit(1) if 'diff --quiet <repo file> <external file>' finds changes
Date: Fri, 15 Jun 2012 13:31:03 -0400 [thread overview]
Message-ID: <1339781463-13536-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>
---
This was the least invasive fix that I found. I considered adding
the following when the '--quiet' option is parsed instead:
+ DIFF_OPT_SET(options, EXIT_WITH_STATUS)
+ DIFF_OPT_SET(options, DIFF_FROM_CONTENTS)
diff.c | 5 +++--
t/t4035-diff-quiet.sh | 5 +++++
2 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/diff.c b/diff.c
index 77edd50..b1d74fe 100644
--- a/diff.c
+++ b/diff.c
@@ -4432,9 +4432,10 @@ void diff_flush(struct diff_options *options)
separator++;
}
- if (output_format & DIFF_FORMAT_NO_OUTPUT &&
+ if ((output_format & DIFF_FORMAT_NO_OUTPUT &&
DIFF_OPT_TST(options, EXIT_WITH_STATUS) &&
- DIFF_OPT_TST(options, DIFF_FROM_CONTENTS)) {
+ DIFF_OPT_TST(options, DIFF_FROM_CONTENTS)) ||
+ DIFF_OPT_TST(options, QUICK)) {
/*
* run diff_flush_patch for the exit status. setting
* options->file to /dev/null should be safe, becaue we
diff --git a/t/t4035-diff-quiet.sh b/t/t4035-diff-quiet.sh
index cdb9202..e14e676 100755
--- a/t/t4035-diff-quiet.sh
+++ b/t/t4035-diff-quiet.sh
@@ -77,4 +77,9 @@ test_expect_success 'git diff-index --cached HEAD' '
}
'
+test_expect_success 'git diff <tracked file> <file outside repo>' '
+ git diff --quiet c /dev/null
+ test $? = 1
+'
+
test_done
--
1.7.11.rc3.6.g501bf14
next reply other threads:[~2012-06-15 17:31 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-06-15 17:31 Tim Henigan [this message]
2012-06-15 18:40 ` [PATCH] diff: exit(1) if 'diff --quiet <repo file> <external file>' finds changes Jeff King
2012-06-15 19:13 ` Jeff King
2012-06-15 18:45 ` Junio C Hamano
2012-06-15 19:37 ` Jeff King
2012-06-15 19:56 ` Tim Henigan
2012-06-15 20:08 ` Junio C Hamano
2012-06-15 20:24 ` Jeff King
2012-06-15 20:44 ` Junio C Hamano
2012-06-15 20:10 ` Junio C Hamano
2012-06-18 17:51 ` Tim Henigan
2012-06-18 18:00 ` Junio C Hamano
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=1339781463-13536-1-git-send-email-tim.henigan@gmail.com \
--to=tim.henigan@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/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).