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

[PATCH v3 13/13] mergetool: fix running in subdir when rerere enabled

From
RHRichard Hansen <hansenr@google.com>
Date
Jan 9, 2017, 05:42 UTC
Message-ID
<20170109054238.42599-14-hansenr@google.com>
In-Reply-To
<20170109054238.42599-1-hansenr@google.com>

If rerere is enabled and no pathnames are given, run cd_to_toplevel before running 'git diff --name-only' so that 'git diff --name-only' sees the files named by 'git rerere remaining', which outputs pathnames relative to the top-level directory.

The cd_to_toplevel command could be run after 'git rerere remaining', but it is run before just in case 'git rerere remaining' is ever changed to print pathnames relative to the current working directory rather than relative to the top-level directory.

An alternative approach would be to unconditionally convert all relative pathnames (including the orderfile pathname) to be relative to the top-level directory and then run cd_to_toplevel before 'git diff --name-only', but unfortunately 'git rev-parse --prefix' requires valid pathnames, which would break some valid use cases.

This fixes a regression introduced in 57937f70a09c12ef484c290865dac4066d207c9c (v2.11.0).

Signed-off-by: Richard Hansen <hansenr@google.com>
---
 git-mergetool.sh     | 32 ++++++++++++++++++++++++++++++++
 t/t7610-mergetool.sh |  2 +-
 2 files changed, 33 insertions(+), 1 deletion(-)
diff --git a/git-mergetool.sh b/git-mergetool.sh
index b506896dc..22f56c25a 100755
--- a/git-mergetool.sh
+++ b/git-mergetool.sh
@@ -456,6 +456,28 @@ main () {
 
 	if test $# -eq 0 && test -e "$GIT_DIR/MERGE_RR"
 	then
+		# The pathnames output by the 'git rerere remaining'
+		# command below are relative to the top-level
+		# directory but the 'git diff --name-only' command
+		# further below expects the pathnames to be relative
+		# to the current working directory.  Thus, we cd to
+		# the top-level directory before running 'git diff
+		# --name-only'.  We change directories even earlier
+		# (before running 'git rerere remaining') in case 'git
+		# rerere remaining' is ever changed to output
+		# pathnames relative to the current working directory.
+		#
+		# Changing directories breaks a relative $orderfile
+		# pathname argument, so fix it up to be relative to
+		# the top-level directory.
+
+		prefix=$(git rev-parse --show-prefix) || exit 1
+		cd_to_toplevel
+		if test -n "$orderfile"
+		then
+			orderfile=$(git rev-parse --prefix "$prefix" "$orderfile") || exit 1
+		fi
+
 		set -- $(git rerere remaining)
 		if test $# -eq 0
 		then
@@ -463,6 +485,16 @@ main () {
 		fi
 	fi
 
+	# Note:  The pathnames output by 'git diff --name-only' are
+	# relative to the top-level directory, but it expects input
+	# pathnames to be relative to the current working directory.
+	# Thus:
+	#   * Either cd_to_toplevel must not be run before this or all
+	#     relative input pathnames must be converted to be
+	#     relative to the top-level directory (or absolute).
+	#   * Either cd_to_toplevel must be run after this or all
+	#     relative output pathnames must be converted to be
+	#     relative to the current working directory (or absolute).
 	files=$(git -c core.quotePath=false \
 		diff --name-only --diff-filter=U \
 		${orderfile:+"-O$orderfile"} -- "$@")
diff --git a/t/t7610-mergetool.sh b/t/t7610-mergetool.sh
index b36fde1c0..a55bf67e1 100755
--- a/t/t7610-mergetool.sh
+++ b/t/t7610-mergetool.sh
@@ -234,7 +234,7 @@ test_expect_success 'mergetool merges all from subdir (rerere disabled)' '
 	)
 '
 
-test_expect_failure 'mergetool merges all from subdir (rerere enabled)' '
+test_expect_success 'mergetool merges all from subdir (rerere enabled)' '
 	test_when_finished "git reset --hard" &&
 	git checkout -b test$test_count branch1 &&
 	test_config rerere.enabled true &&
-- 
2.11.0.390.gc69c2f50cf-goog
Previous: Richard HansenNext: Junio C Hamano
Message 28 of 76 in “fix mergetool+rerere+subdir regression”
  1. 0/4 fix mergetool+rerere+subdir regressionRichard Hansen, Jan 4, 2017
  2. 2/4 t7610: make tests more independent and debuggableRichard Hansen, Jan 4, 2017
  3. Stefan BellerJan 4, 2017
  4. Richard HansenJan 5, 2017
  5. Richard HansenJan 5, 2017
  6. Simon RuderichJan 5, 2017
  7. Richard HansenJan 5, 2017
  8. 3/4 t7610: add test case for rerere+mergetool+subdir bugRichard Hansen, Jan 4, 2017
  9. 1/4 t7610: update branch names to match test numberRichard Hansen, Jan 4, 2017
  10. 4/4 mergetool: fix running in subdir when rerere enabledRichard Hansen, Jan 4, 2017
  11. 0/4 fix mergetool+rerere+subdir regressionRichard Hansen, Jan 6, 2017
  12. 4/4 mergetool: fix running in subdir when rerere enabledRichard Hansen, Jan 6, 2017
  13. Johannes SixtJan 6, 2017
  14. Richard HansenJan 7, 2017
  15. 3/4 t7610: add test case for rerere+mergetool+subdir bugRichard Hansen, Jan 6, 2017
  16. 1/4 t7610: update branch names to match test numberRichard Hansen, Jan 6, 2017
  17. 2/4 t7610: make tests more independent and debuggableRichard Hansen, Jan 6, 2017
  18. Stefan BellerJan 6, 2017
  19. Richard HansenJan 7, 2017
  20. 00/13 fix mergetool+rerere+subdir regressionRichard Hansen, Jan 9, 2017
  21. 01/13 .mailmap: Use my personal email address as my canonicalRichard Hansen, Jan 9, 2017
  22. 05/13 t7610: don't rely on state from previous testRichard Hansen, Jan 9, 2017
  23. 06/13 t7610: run 'git reset --hard' after each test to clean upRichard Hansen, Jan 9, 2017
  24. 03/13 t7610: Move setup code to the 'setup' test case.Richard Hansen, Jan 9, 2017
  25. 04/13 t7610: use test_when_finished for cleanup tasksRichard Hansen, Jan 9, 2017
  26. 07/13 t7610: delete some now-unnecessary 'git reset --hard' linesRichard Hansen, Jan 9, 2017
  27. 08/13 t7610: always work on a test-specific branchRichard Hansen, Jan 9, 2017
  28. 13/13 mergetool: fix running in subdir when rerere enabledRichard Hansen, Jan 9, 2017
  29. Junio C HamanoJan 9, 2017
  30. Junio C HamanoJan 9, 2017
  31. Johannes SixtJan 9, 2017
  32. Richard HansenJan 9, 2017
  33. Junio C HamanoJan 9, 2017
  34. Junio C HamanoJan 9, 2017
  35. Richard HansenJan 9, 2017
  36. 09/13 t7610: don't assume the checked-out commitRichard Hansen, Jan 9, 2017
  37. 12/13 mergetool: take the "-O" out of $orderfileRichard Hansen, Jan 9, 2017
  38. 11/13 t7610: add test case for rerere+mergetool+subdir bugRichard Hansen, Jan 9, 2017
  39. 10/13 t7610: spell 'git reset --hard' consistentlyRichard Hansen, Jan 9, 2017
  40. 02/13 t7610: update branch names to match test numberRichard Hansen, Jan 9, 2017
  41. Stefan BellerJan 9, 2017
  42. 00/14 fix mergetool+rerere+subdir regressionRichard Hansen, Jan 9, 2017
  43. 01/14 .mailmap: Use my personal email address as my canonicalRichard Hansen, Jan 9, 2017
  44. 02/14 rev-parse doc: use "--" in the --prefix exampleRichard Hansen, Jan 9, 2017
  45. 04/14 t7610: Move setup code to the 'setup' test case.Richard Hansen, Jan 9, 2017
  46. 05/14 t7610: use test_when_finished for cleanup tasksRichard Hansen, Jan 9, 2017
  47. 08/14 t7610: delete some now-unnecessary 'git reset --hard' linesRichard Hansen, Jan 9, 2017
  48. 10/14 t7610: don't assume the checked-out commitRichard Hansen, Jan 9, 2017
  49. 13/14 mergetool: take the "-O" out of $orderfileRichard Hansen, Jan 9, 2017
  50. 11/14 t7610: spell 'git reset --hard' consistentlyRichard Hansen, Jan 9, 2017
  51. 14/14 mergetool: fix running in subdir when rerere enabledRichard Hansen, Jan 9, 2017
  52. Johannes SixtJan 10, 2017
  53. Richard HansenJan 10, 2017
  54. Junio C HamanoJan 10, 2017
  55. Johannes SixtJan 10, 2017
  56. 12/14 t7610: add test case for rerere+mergetool+subdir bugRichard Hansen, Jan 9, 2017
  57. 09/14 t7610: always work on a test-specific branchRichard Hansen, Jan 9, 2017
  58. 07/14 t7610: run 'git reset --hard' after each test to clean upRichard Hansen, Jan 9, 2017
  59. 06/14 t7610: don't rely on state from previous testRichard Hansen, Jan 9, 2017
  60. 03/14 t7610: update branch names to match test numberRichard Hansen, Jan 9, 2017
  61. 00/14 fix mergetool+rerere+subdir regressionRichard Hansen, Jan 10, 2017
  62. 01/14 .mailmap: Use my personal email address as my canonicalRichard Hansen, Jan 10, 2017
  63. 09/14 t7610: always work on a test-specific branchRichard Hansen, Jan 10, 2017
  64. 11/14 t7610: spell 'git reset --hard' consistentlyRichard Hansen, Jan 10, 2017
  65. 10/14 t7610: don't assume the checked-out commitRichard Hansen, Jan 10, 2017
  66. 12/14 t7610: add test case for rerere+mergetool+subdir bugRichard Hansen, Jan 10, 2017
  67. 13/14 mergetool: take the "-O" out of $orderfileRichard Hansen, Jan 10, 2017
  68. 14/14 mergetool: fix running in subdir when rerere enabledRichard Hansen, Jan 10, 2017
  69. 08/14 t7610: delete some now-unnecessary 'git reset --hard' linesRichard Hansen, Jan 10, 2017
  70. 07/14 t7610: run 'git reset --hard' after each test to clean upRichard Hansen, Jan 10, 2017
  71. 06/14 t7610: don't rely on state from previous testRichard Hansen, Jan 10, 2017
  72. 05/14 t7610: use test_when_finished for cleanup tasksRichard Hansen, Jan 10, 2017
  73. 04/14 t7610: Move setup code to the 'setup' test case.Richard Hansen, Jan 10, 2017
  74. 03/14 t7610: update branch names to match test numberRichard Hansen, Jan 10, 2017
  75. 02/14 rev-parse doc: pass "--" to rev-parse in the --prefix exampleRichard Hansen, Jan 10, 2017
  76. David AguilarJan 10, 2017

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.