worktree: prepare for more checks of whether path can become worktree
[gitweb.git] / git-mergetool.sh
index e52b4e4f24088d7552d88aa5a3c9ffc308f6a4cf..d07c7f387cf478bbd93d1dada1afa1de80db0fbf 100755 (executable)
@@ -421,7 +421,7 @@ main () {
                        prompt=true
                        ;;
                -O*)
-                       orderfile="$1"
+                       orderfile="${1#-O}"
                        ;;
                --)
                        shift
@@ -454,6 +454,17 @@ 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)
@@ -461,13 +472,15 @@ main () {
                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:+"$orderfile"} -- "$@")
-
-       cd_to_toplevel
+               ${orderfile:+"-O$orderfile"} -- "$@")
 
        if test -z "$files"
        then
@@ -478,14 +491,16 @@ main () {
        printf "%s\n" "$files"
 
        rc=0
-       for i in $files
+       set -- $files
+       while test $# -ne 0
        do
                printf "\n"
-               if ! merge_file "$i"
+               if ! merge_file "$1"
                then
                        rc=1
-                       prompt_after_failed_merge || exit 1
+                       test $# -ne 1 && prompt_after_failed_merge || exit 1
                fi
+               shift
        done
 
        exit $rc