Skip to content

Commit

Permalink
mergetool: fix running in subdir when rerere enabled
Browse files Browse the repository at this point in the history
"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>
  • Loading branch information
rhansen authored and gitster committed Jan 10, 2017
1 parent c1b0d3a commit d0e0cfe
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
17 changes: 15 additions & 2 deletions git-mergetool.sh
Expand Up @@ -454,21 +454,34 @@ main () {
merge_keep_backup="$(git config --bool mergetool.keepBackup || echo true)"
merge_keep_temporaries="$(git config --bool mergetool.keepTemporaries || echo false)"

prefix=$(git rev-parse --show-prefix) || exit 1
cd_to_toplevel

if test -n "$orderfile"
then
orderfile=$(
git rev-parse --prefix "$prefix" -- "$orderfile" |
sed -e 1d
)
fi

if test $# -eq 0 && test -e "$GIT_DIR/MERGE_RR"
then
set -- $(git rerere remaining)
if test $# -eq 0
then
print_noop_and_exit
fi
elif test $# -ge 0
then
# rev-parse provides the -- needed for 'set'
eval "set $(git rev-parse --sq --prefix "$prefix" -- "$@")"
fi

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

cd_to_toplevel

if test -z "$files"
then
print_noop_and_exit
Expand Down
7 changes: 6 additions & 1 deletion t/t7610-mergetool.sh
Expand Up @@ -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 &&
Expand Down Expand Up @@ -678,6 +678,11 @@ test_expect_success 'diff.orderFile configuration is honored' '
b
a
EOF
# make sure "order-file" that is ambiguous between
# rev and path is understood correctly.
git branch order-file HEAD &&
git mergetool --no-prompt --tool myecho >output &&
git grep --no-index -h -A2 Merging: output >actual &&
test_cmp expect actual
Expand Down

0 comments on commit d0e0cfe

Please sign in to comment.