git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2] added git-config support for diff.relative setting

From
KKelson <kelson@shysecurity.com>
Date
Dec 12, 2014, 23:25 UTC
Message-ID
<548B7967.3060201@shysecurity.com>
In-Reply-To
<548947A0.7000608@shysecurity.com>

By default, git-diff shows changes and pathnames relative to the repository root. Setting the diff.relative config option to "true" shows pathnames relative to the current directory and excludes changes outside this directory.

Signed-off-by: Brandon Phillips <kelson@shysecurity.com>
---
  Documentation/diff-config.txt |  6 ++++++
  diff.c                        |  8 ++++++++
  t/t4045-diff-relative.sh      | 21 +++++++++++++++++++++
  3 files changed, 35 insertions(+)
diff --git a/Documentation/diff-config.txt b/Documentation/diff-config.txt
index b001779..10f183f 100644
--- a/Documentation/diff-config.txt
+++ b/Documentation/diff-config.txt
@@ -182,3 +182,9 @@ diff.algorithm::
  	low-occurrence common elements".
  --
  +
+
+diff.relative::
+	By default, linkgit:git-diff[1] shows changes and pathnames
+	relative to the repository root. Setting this variable to
+	`true` shows pathnames relative to the current directory and
+	excludes changes outside this directory.
diff --git a/diff.c b/diff.c
index d1bd534..03697a9 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 3950f50..8c8fe0b 100755
--- a/t/t4045-diff-relative.sh
+++ b/t/t4045-diff-relative.sh
@@ -29,6 +29,23 @@ test_expect_success "-p $*" "
  "
  }

+check_config() {
+expect=$1; shift
+cat >expected <<EOF
+diff --git a/$expect b/$expect
+new file mode 100644
+index 0000000..25c05ef
+--- /dev/null
++++ b/$expect
+@@ -0,0 +1 @@
++other content
+EOF
+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_numstat() {
  expect=$1; shift
  cat >expected <<EOF
@@ -69,5 +86,9 @@ for type in diff numstat stat raw; do
  	check_$type file2 --relative=subdir
  	check_$type dir/file2 --relative=sub
  done
+for type in config; do
+	check_$type file2 subdir/
+	check_$type file2 subdir
+done

  test_done
-- 
1.9.1
Previous: KelsonNext: kelson@shysecurity.com
Message 4 of 13 in “added git-config support for diff.relative setting”
  1. added git-config support for diff.relative settingKelson, Dec 11, 2014
  2. Duy NguyenDec 11, 2014
  3. KelsonDec 11, 2014
  4. added git-config support for diff.relative settingKelson, Dec 12, 2014
  5. 1/2 git-config support for diff.relative settingkelson@shysecurity.com, Dec 21, 2014
  6. 1/2 git-config support for diff.relative settingkelson@shysecurity.com, Dec 30, 2014
  7. Junio C HamanoDec 30, 2014
  8. 1/2 support for --no-relative and diff.relativekelson@shysecurity.com, Dec 30, 2014
  9. 1/2 support for --no-relative and diff.relativekelson@shysecurity.com, Jan 6, 2015
  10. Junio C HamanoJan 7, 2015
  11. kelson@shysecurity.comJan 7, 2015
  12. Junio C HamanoJan 7, 2015
  13. Junio C HamanoJan 7, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.