completion: put matching ctags symbol names directly into COMPREPLY
[gitweb.git] / git-mergetool.sh
index b2cd0a497bb7c9d55c5b81bbd3349e56815b1f09..c062e3de3a503bd01203f2a6aef63eea63cae5c5 100755 (executable)
@@ -9,7 +9,7 @@
 # at the discretion of Junio C Hamano.
 #
 
-USAGE='[--tool=tool] [--tool-help] [-y|--no-prompt|--prompt] [file to merge] ...'
+USAGE='[--tool=tool] [--tool-help] [-y|--no-prompt|--prompt] [-O<orderfile>] [file to merge] ...'
 SUBDIRECTORY_OK=Yes
 NONGIT_OK=Yes
 OPTIONS_SPEC=
@@ -382,9 +382,15 @@ prompt_after_failed_merge () {
        done
 }
 
+print_noop_and_exit () {
+       echo "No files need merging"
+       exit 0
+}
+
 main () {
        prompt=$(git config --bool mergetool.prompt)
        guessed_merge_tool=false
+       orderfile=
 
        while test $# != 0
        do
@@ -414,6 +420,9 @@ main () {
                --prompt)
                        prompt=true
                        ;;
+               -O*)
+                       orderfile="${1#-O}"
+                       ;;
                --)
                        shift
                        break
@@ -445,28 +454,37 @@ main () {
        merge_keep_backup="$(git config --bool mergetool.keepBackup || echo true)"
        merge_keep_temporaries="$(git config --bool mergetool.keepTemporaries || echo false)"
 
-       files=
+       prefix=$(git rev-parse --show-prefix) || exit 1
+       cd_to_toplevel
 
-       if test $# -eq 0
+       if test -n "$orderfile"
        then
-               cd_to_toplevel
+               orderfile=$(
+                       git rev-parse --prefix "$prefix" -- "$orderfile" |
+                       sed -e 1d
+               )
+       fi
 
-               if test -e "$GIT_DIR/MERGE_RR"
+       if test $# -eq 0 && test -e "$GIT_DIR/MERGE_RR"
+       then
+               set -- $(git rerere remaining)
+               if test $# -eq 0
                then
-                       files=$(git rerere remaining)
-               else
-                       files=$(git ls-files -u |
-                               sed -e 's/^[^   ]*      //' | sort -u)
+                       print_noop_and_exit
                fi
-       else
-               files=$(git ls-files -u -- "$@" |
-                       sed -e 's/^[^   ]*      //' | sort -u)
+       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"} -- "$@")
+
        if test -z "$files"
        then
-               echo "No files need merging"
-               exit 0
+               print_noop_and_exit
        fi
 
        printf "Merging:\n"