diff options
Diffstat (limited to 'git-mergetool--lib.sh')
-rw-r--r-- | git-mergetool--lib.sh | 92 |
1 files changed, 40 insertions, 52 deletions
diff --git a/git-mergetool--lib.sh b/git-mergetool--lib.sh index e338be5e57..c45a020301 100644 --- a/git-mergetool--lib.sh +++ b/git-mergetool--lib.sh @@ -1,5 +1,4 @@ -#!/bin/sh -# git-mergetool--lib is a library for common merge tool functions +# git-mergetool--lib is a shell library for common merge tool functions : ${MERGE_TOOLS_DIR=$(git --exec-path)/mergetools} @@ -114,10 +113,37 @@ valid_tool () { test -n "$cmd" } +setup_user_tool () { + merge_tool_cmd=$(get_merge_tool_cmd "$tool") + test -n "$merge_tool_cmd" || return 1 + + diff_cmd () { + ( eval $merge_tool_cmd ) + status=$? + return $status + } + + merge_cmd () { + trust_exit_code=$(git config --bool \ + "mergetool.$1.trustExitCode" || echo false) + if test "$trust_exit_code" = "false" + then + touch "$BACKUP" + ( eval $merge_tool_cmd ) + status=$? + check_unchanged + else + ( eval $merge_tool_cmd ) + status=$? + fi + return $status + } +} + setup_tool () { tool="$1" - # Fallback definitions, to be overriden by tools. + # Fallback definitions, to be overridden by tools. can_merge () { return 0 } @@ -142,15 +168,15 @@ setup_tool () { if ! test -f "$MERGE_TOOLS_DIR/$tool" then - # Use a special return code for this case since we want to - # source "defaults" even when an explicit tool path is - # configured since the user can use that to override the - # default path in the scriptlet. - return 2 + setup_user_tool + return $? fi # Load the redefined functions . "$MERGE_TOOLS_DIR/$tool" + # Now let the user override the default command for the tool. If + # they have not done so then this will return 1 which we ignore. + setup_user_tool if merge_mode && ! can_merge then @@ -187,20 +213,7 @@ run_merge_tool () { status=0 # Bring tool-specific functions into scope - setup_tool "$1" - exitcode=$? - case $exitcode in - 0) - : - ;; - 2) - # The configured tool is not a built-in tool. - test -n "$merge_tool_path" || return 1 - ;; - *) - return $exitcode - ;; - esac + setup_tool "$1" || return 1 if merge_mode then @@ -213,38 +226,12 @@ run_merge_tool () { # Run a either a configured or built-in diff tool run_diff_cmd () { - merge_tool_cmd=$(get_merge_tool_cmd "$1") - if test -n "$merge_tool_cmd" - then - ( eval $merge_tool_cmd ) - status=$? - return $status - else - diff_cmd "$1" - fi + diff_cmd "$1" } # Run a either a configured or built-in merge tool run_merge_cmd () { - merge_tool_cmd=$(get_merge_tool_cmd "$1") - if test -n "$merge_tool_cmd" - then - trust_exit_code=$(git config --bool \ - "mergetool.$1.trustExitCode" || echo false) - if test "$trust_exit_code" = "false" - then - touch "$BACKUP" - ( eval $merge_tool_cmd ) - status=$? - check_unchanged - else - ( eval $merge_tool_cmd ) - status=$? - fi - return $status - else - merge_cmd "$1" - fi + merge_cmd "$1" } list_merge_tool_candidates () { @@ -262,7 +249,8 @@ list_merge_tool_candidates () { else tools="opendiff kdiff3 tkdiff xxdiff meld $tools" fi - tools="$tools gvimdiff diffuse ecmerge p4merge araxis bc3 codecompare" + tools="$tools gvimdiff diffuse diffmerge ecmerge" + tools="$tools p4merge araxis bc3 codecompare" fi case "${VISUAL:-$EDITOR}" in *vim*) @@ -275,7 +263,7 @@ list_merge_tool_candidates () { } show_tool_help () { - tool_opt="'git ${TOOL_MODE}tool --tool-<tool>'" + tool_opt="'git ${TOOL_MODE}tool --tool=<tool>'" tab=' ' LF=' |