Skip to content

Commit d0e0cfe

Browse files
rhansengitster
authored andcommitted
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 57937f7 ("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>
1 parent c1b0d3a commit d0e0cfe

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

git-mergetool.sh

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,21 +454,34 @@ main () {
454454
merge_keep_backup="$(git config --bool mergetool.keepBackup || echo true)"
455455
merge_keep_temporaries="$(git config --bool mergetool.keepTemporaries || echo false)"
456456

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+
457468
if test $# -eq 0 && test -e "$GIT_DIR/MERGE_RR"
458469
then
459470
set -- $(git rerere remaining)
460471
if test $# -eq 0
461472
then
462473
print_noop_and_exit
463474
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" -- "$@")"
464479
fi
465480

466481
files=$(git -c core.quotePath=false \
467482
diff --name-only --diff-filter=U \
468483
${orderfile:+"-O$orderfile"} -- "$@")
469484

470-
cd_to_toplevel
471-
472485
if test -z "$files"
473486
then
474487
print_noop_and_exit

t/t7610-mergetool.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ test_expect_success 'mergetool merges all from subdir (rerere disabled)' '
234234
)
235235
'
236236

237-
test_expect_failure 'mergetool merges all from subdir (rerere enabled)' '
237+
test_expect_success 'mergetool merges all from subdir (rerere enabled)' '
238238
test_when_finished "git reset --hard" &&
239239
git checkout -b test$test_count branch1 &&
240240
test_config rerere.enabled true &&
@@ -678,6 +678,11 @@ test_expect_success 'diff.orderFile configuration is honored' '
678678
b
679679
a
680680
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+
681686
git mergetool --no-prompt --tool myecho >output &&
682687
git grep --no-index -h -A2 Merging: output >actual &&
683688
test_cmp expect actual

0 commit comments

Comments
 (0)