mergetool: fix running in subdir when rerere enabled

"git mergetool" (without any pathspec on the command line) that is not run from the top-level of the working tree no longer works in Git v2.11, failing to get the list of unmerged paths from the output of "git rerere remaining". This regression was introduced by 57937f70a0 ("mergetool: honor diff.orderFile", 2016-10-07). This is because the pathnames output by the 'git rerere remaining' command are relative to the top-level directory but the 'git diff --name-only' command expects its pathname arguments to be relative to the current working directory. To make everything consistent, cd_to_toplevel before running 'git diff --name-only' and adjust any relative pathnames. Signed-off-by: Richard Hansen <hansenr@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Richard Hansen committed Jan 10, 2017 at 15:42 UTC d0e0cfe745e0c88ca2f4d4ed9f1d2871b659d872
2 files changed +21 -3
git-mergetool.sh
+15 -2
@@ -454,6 +454,17 @@ main () {
454 merge_keep_backup="$(git config --bool mergetool.keepBackup || echo true)"
455 merge_keep_temporaries="$(git config --bool mergetool.keepTemporaries || echo false)"
456
457 + prefix=$(git rev-parse --show-prefix) || exit 1
458 + cd_to_toplevel
459 +
460 + if test -n "$orderfile"
461 + then
462 + orderfile=$(
463 + git rev-parse --prefix "$prefix" -- "$orderfile" |
464 + sed -e 1d
465 + )
466 + fi
467 +
468 if test $# -eq 0 && test -e "$GIT_DIR/MERGE_RR"
469 then
470 set -- $(git rerere remaining)
@@ -461,14 +472,16 @@ main () {
472 then
473 print_noop_and_exit
474 fi
475 + elif test $# -ge 0
476 + then
477 + # rev-parse provides the -- needed for 'set'
478 + eval "set $(git rev-parse --sq --prefix "$prefix" -- "$@")"
479 fi
480
481 files=$(git -c core.quotePath=false \
482 diff --name-only --diff-filter=U \
483 ${orderfile:+"-O$orderfile"} -- "$@")
484
470 - cd_to_toplevel
471 -
485 if test -z "$files"
486 then
487 print_noop_and_exit
t/t7610-mergetool.sh
+6 -1
@@ -234,7 +234,7 @@ test_expect_success 'mergetool merges all from subdir (rerere disabled)' '
234 )
235 '
236
237 -test_expect_failure 'mergetool merges all from subdir (rerere enabled)' '
237 +test_expect_success 'mergetool merges all from subdir (rerere enabled)' '
238 test_when_finished "git reset --hard" &&
239 git checkout -b test$test_count branch1 &&
240 test_config rerere.enabled true &&
@@ -678,6 +678,11 @@ test_expect_success 'diff.orderFile configuration is honored' '
678 b
679 a
680 EOF
681 +
682 + # make sure "order-file" that is ambiguous between
683 + # rev and path is understood correctly.
684 + git branch order-file HEAD &&
685 +
686 git mergetool --no-prompt --tool myecho >output &&
687 git grep --no-index -h -A2 Merging: output >actual &&
688 test_cmp expect actual