mergetool: Use args as pathspec to unmerged files

Mergetool now treats its path arguments as a pathspec (like other git
subcommands), restricting action to the given files and directories.
Files matching the pathspec are filtered so mergetool only acts on
unmerged paths; previously it would assume each path argument was in an
unresolved state, and get confused when it couldn't check out their
other stages.

Running "git mergetool subdir" will prompt to resolve all conflicted
blobs under subdir.

Signed-off-by: Jonathon Mah <me@JonathonMah.com>
Acked-by: David Aguilar <davvid@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Jonathon Mah
2011-09-15 19:12:10 -07:00
committed by Junio C Hamano
parent 2765233c64
commit 3e8e691abe
3 changed files with 74 additions and 71 deletions

View File

@@ -342,64 +342,44 @@ merge_keep_temporaries="$(git config --bool mergetool.keepTemporaries || echo fa
last_status=0
rollup_status=0
rerere=false
files_to_merge() {
if test "$rerere" = true
then
git rerere remaining
else
git ls-files -u | sed -e 's/^[^ ]* //' | sort -u
fi
}
files=
if test $# -eq 0 ; then
cd_to_toplevel
if test -e "$GIT_DIR/MERGE_RR"
then
rerere=true
files=$(git rerere remaining)
else
files=$(git ls-files -u | sed -e 's/^[^ ]* //' | sort -u)
fi
files=$(files_to_merge)
if test -z "$files" ; then
echo "No files need merging"
exit 0
fi
# Save original stdin
exec 3<&0
printf "Merging:\n"
printf "$files\n"
files_to_merge |
while IFS= read i
do
if test $last_status -ne 0; then
prompt_after_failed_merge <&3 || exit 1
fi
printf "\n"
merge_file "$i" <&3
last_status=$?
if test $last_status -ne 0; then
rollup_status=1
fi
done
else
while test $# -gt 0; do
if test $last_status -ne 0; then
prompt_after_failed_merge || exit 1
fi
printf "\n"
merge_file "$1"
last_status=$?
if test $last_status -ne 0; then
rollup_status=1
fi
shift
done
files=$(git ls-files -u -- "$@" | sed -e 's/^[^ ]* //' | sort -u)
fi
if test -z "$files" ; then
echo "No files need merging"
exit 0
fi
# Save original stdin
exec 3<&0
printf "Merging:\n"
printf "$files\n"
IFS='
'; for i in $files
do
if test $last_status -ne 0; then
prompt_after_failed_merge <&3 || exit 1
fi
printf "\n"
merge_file "$i" <&3
last_status=$?
if test $last_status -ne 0; then
rollup_status=1
fi
done
exit $rollup_status