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

[PATCH 1/2] support for --no-relative and diff.relative

From
Kkelson@shysecurity.com <kelson@shysecurity.com>
Date
Dec 30, 2014, 19:32 UTC
Message-ID
<54A2FDC8.5010504@shysecurity.com>
In-Reply-To
<54A2E744.8010508@shysecurity.com>
added --no-relative option for git-diff (code, documentation, and tests)
--no-relative overrides --relative causing a return to standard behavior
Signed-off-by: Brandon Phillips <kelson@shysecurity.com>
---
  Documentation/diff-options.txt |  4 ++++
  diff.c                         |  2 ++
  t/t4045-diff-relative.sh       | 46 
+++++++++++++++++++++++++++++++++++++++---
  3 files changed, 49 insertions(+), 3 deletions(-)
diff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt
index 6cb083a..2b15050 100644
--- a/Documentation/diff-options.txt
+++ b/Documentation/diff-options.txt
@@ -448,6 +448,10 @@ ifndef::git-format-patch[]
  	not in a subdirectory (e.g. in a bare repository), you
  	can name which subdirectory to make the output relative
  	to by giving a <path> as an argument.
+
+--no-relative::
+	Turn off relative pathnames and include all changes in the
+	repository.
  endif::git-format-patch[]

  -a::
diff --git a/diff.c b/diff.c
index d1bd534..7bceba8 100644
--- a/diff.c
+++ b/diff.c
@@ -3695,6 +3695,8 @@ int diff_opt_parse(struct diff_options *options, 
const char **av, int ac)
  		DIFF_OPT_SET(options, RELATIVE_NAME);
  		options->prefix = arg;
  	}
+	else if (!strcmp(arg, "--no-relative"))
+		DIFF_OPT_CLR(options, RELATIVE_NAME);

  	/* xdiff options */
  	else if (!strcmp(arg, "--minimal"))
diff --git a/t/t4045-diff-relative.sh b/t/t4045-diff-relative.sh
index 3950f50..ccd67c7 100755
--- a/t/t4045-diff-relative.sh
+++ b/t/t4045-diff-relative.sh
@@ -12,8 +12,8 @@ test_expect_success 'setup' '
  	git commit -m one
  '

-check_diff() {
-expect=$1; shift
+store_diff_relative() {
+expect=$1;
  cat >expected <<EOF
  diff --git a/$expect b/$expect
  new file mode 100644
@@ -23,12 +23,52 @@ index 0000000..25c05ef
  @@ -0,0 +1 @@
  +other content
  EOF
+}
+
+store_diff_absolute() {
+expect=$1;
+cat >expected <<EOF
+diff --git a/file1 b/file1
+new file mode 100644
+index 0000000..d95f3ad
+--- /dev/null
++++ b/file1
+@@ -0,0 +1 @@
++content
+diff --git a/subdir/file2 b/subdir/file2
+new file mode 100644
+index 0000000..25c05ef
+--- /dev/null
++++ b/subdir/file2
+@@ -0,0 +1 @@
++other content
+EOF
+}
+
+check_diff() {
+store_diff_relative $1; shift
  test_expect_success "-p $*" "
  	git diff -p $* HEAD^ >actual &&
  	test_cmp expected actual
  "
  }

+check_norel_pre() {
+store_diff_relative $1; shift
+test_expect_success "-p --no-relative $*" "
+	git diff -p --no-relative $* HEAD^ >actual &&
+	test_cmp expected actual
+"
+}
+
+check_norel_post() {
+store_diff_absolute $1; shift
+test_expect_success "-p $* --no-relative" "
+	git diff -p $* --no-relative HEAD^ >actual &&
+	test_cmp expected actual
+"
+}
+
  check_numstat() {
  expect=$1; shift
  cat >expected <<EOF
@@ -64,7 +104,7 @@ test_expect_success "--raw $*" "
  "
  }

-for type in diff numstat stat raw; do
+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
--
1.9.1
Previous: Junio C HamanoNext: kelson@shysecurity.com
Message 8 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.