From 3e8e691abe4e1cce73a8a2ef413dada0278e7b3b Mon Sep 17 00:00:00 2001 From: Jonathon Mah Date: Thu, 15 Sep 2011 19:12:10 -0700 Subject: 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 Acked-by: David Aguilar Signed-off-by: Junio C Hamano --- git-mergetool.sh | 76 +++++++++++++++++++++----------------------------------- 1 file changed, 28 insertions(+), 48 deletions(-) (limited to 'git-mergetool.sh') diff --git a/git-mergetool.sh b/git-mergetool.sh index 3aab5aae84..83551c70c7 100755 --- a/git-mergetool.sh +++ b/git-mergetool.sh @@ -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 +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 +if test -z "$files" ; then + echo "No files need merging" + exit 0 +fi - # Save original stdin - exec 3<&0 +# Save original stdin +exec 3<&0 - printf "Merging:\n" - printf "$files\n" +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 -fi +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 -- cgit v1.3-5-g9baa From 6d9990a959c0168ab6dfe75236980f95ac512ce5 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 16 Sep 2011 13:19:33 -0700 Subject: mergetool: no longer need to save standard input Earlier code wanted to run merge_file and prompt_after_failed_merge both of which wanted to read from the standard input of the entire script inside a while loop, which read from a pipe, and in order to do so, it redirected the original standard input to another file descriptor. We no longer need to do so after the previous change. Signed-off-by: Junio C Hamano --- git-mergetool.sh | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'git-mergetool.sh') diff --git a/git-mergetool.sh b/git-mergetool.sh index 83551c70c7..0a06bde843 100755 --- a/git-mergetool.sh +++ b/git-mergetool.sh @@ -362,20 +362,18 @@ if test -z "$files" ; then exit 0 fi -# Save original stdin -exec 3<&0 - printf "Merging:\n" printf "$files\n" IFS=' -'; for i in $files +' +for i in $files do if test $last_status -ne 0; then - prompt_after_failed_merge <&3 || exit 1 + prompt_after_failed_merge || exit 1 fi printf "\n" - merge_file "$i" <&3 + merge_file "$i" last_status=$? if test $last_status -ne 0; then rollup_status=1 -- cgit v1.3-5-g9baa