git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: kelson@shysecurity.com
To: Git Mailing List <git@vger.kernel.org>
Cc: Junio C Hamano <gitster@pobox.com>,
	Philip Oakley <philipoakley@iee.org>,
	Duy Nguyen <pclouds@gmail.com>,
	Jonathan Nieder <jrnieder@gmail.com>
Subject: [PATCH 2/2] support for --no-relative and diff.relative
Date: Tue, 30 Dec 2014 14:32:34 -0500	[thread overview]
Message-ID: <54A2FDD2.3010707@shysecurity.com> (raw)
In-Reply-To: <54A2E748.3010008@shysecurity.com>

added diff.relative setting for git-diff (code, documentation, and tests)

`git-config diff.relative=true` causes `git diff` to behave like `git 
diff --relative`. Overridden by `git diff --no-relative`.

Signed-off-by: Brandon Phillips <kelson@shysecurity.com>
---
  Documentation/diff-config.txt |  6 ++++++
  diff.c                        |  8 ++++++++
  t/t4045-diff-relative.sh      | 20 ++++++++++++++++++++
  3 files changed, 34 insertions(+)

diff --git a/Documentation/diff-config.txt b/Documentation/diff-config.txt
index b001779..b8a7c60 100644
--- a/Documentation/diff-config.txt
+++ b/Documentation/diff-config.txt
@@ -103,6 +103,12 @@ diff.orderfile::
  	one shell glob pattern per line.
  	Can be overridden by the '-O' option to linkgit:git-diff[1].

+diff.relative::
+	Show pathnames relative to the current directory and exclude
+	changes outside this directory; equivalent to the 'git diff'
+	option '--relative'.
+	Overridden by the '--no-relative' linkgit:git-diff[1] option.
+
  diff.renameLimit::
  	The number of files to consider when performing the copy/rename
  	detection; equivalent to the 'git diff' option '-l'.
diff --git a/diff.c b/diff.c
index 7bceba8..9e4ec1f 100644
--- a/diff.c
+++ b/diff.c
@@ -223,6 +223,14 @@ int git_diff_ui_config(const char *var, const char 
*value, void *cb)
  		return 0;
  	}

+	if (!strcmp(var, "diff.relative")) {
+		if (git_config_bool(var, value))
+			DIFF_OPT_SET(&default_diff_options, RELATIVE_NAME);
+		else
+			DIFF_OPT_CLR(&default_diff_options, RELATIVE_NAME);
+		return 0;
+	}
+
  	if (git_color_config(var, value, cb) < 0)
  		return -1;

diff --git a/t/t4045-diff-relative.sh b/t/t4045-diff-relative.sh
index ccd67c7..c2c15e4 100755
--- a/t/t4045-diff-relative.sh
+++ b/t/t4045-diff-relative.sh
@@ -104,10 +104,30 @@ test_expect_success "--raw $*" "
  "
  }

+check_config() {
+store_diff_relative $1; shift
+test_expect_success "git-config diff.relative=true in $1" "
+	(cd $1; git -c diff.relative=true diff -p HEAD^ >../actual) &&
+	test_cmp expected actual
+"
+}
+
+check_config_no_relative() {
+store_diff_absolute $1; shift
+test_expect_success "--no-relative w/ git-config diff.relative=true in 
$1" "
+	(cd $1; git -c diff.relative=true diff --no-relative -p HEAD^ 
 >../actual) &&
+	test_cmp expected actual
+"
+}
+
  for type in diff numstat stat raw norel_pre norel_post; do
  	check_$type file2 --relative=subdir/
  	check_$type file2 --relative=subdir
  	check_$type dir/file2 --relative=sub
  done
+for type in config config_no_relative; do
+	check_$type file2 subdir/
+	check_$type file2 subdir
+done

  test_done
--
1.9.1

  reply	other threads:[~2014-12-30 19:32 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-21 20:23 [PATCH v3 2/2] git-config support for diff.relative setting kelson
2014-12-30 17:56 ` kelson
2014-12-30 19:32   ` kelson [this message]
2015-01-06 16:19     ` [PATCH 2/2] support for --no-relative and diff.relative kelson
2015-02-12 23:17     ` 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=54A2FDD2.3010707@shysecurity.com \
    --to=kelson@shysecurity.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jrnieder@gmail.com \
    --cc=pclouds@gmail.com \
    --cc=philipoakley@iee.org \
    /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).