summaryrefslogtreecommitdiff
path: root/git-mergetool.sh
diff options
context:
space:
mode:
authorCharles Bailey <charles@hashpling.org>2008-02-21 23:31:12 +0000
committerJunio C Hamano <gitster@pobox.com>2008-03-05 12:07:04 -0800
commit964473a0429f625d019c69ab55644540174acf85 (patch)
tree6ac82242299008b623677665cee2fce8bb7e0a39 /git-mergetool.sh
parentb3ea27e4de24c7006969f493ba6bfbbc5b572d80 (diff)
downloadgit-964473a0429f625d019c69ab55644540174acf85.tar.gz
Teach git mergetool to use custom commands defined at config time
Currently git mergetool is restricted to a set of commands defined in the script. You can subvert the mergetool.<tool>.path to force git mergetool to use a different command, but if you have a command whose invocation syntax does not match one of the current tools then you would have to write a wrapper script for it. This patch adds two git config variable patterns which allow a more flexible choice of merge tool. If you run git mergetool with -t/--tool or the merge.tool config variable set to an unrecognized tool then git mergetool will query the mergetool.<tool>.cmd config variable. If this variable exists, then git mergetool will treat the specified tool as a custom command and will use a shell eval to run the command with the documented shell variables set. mergetool.<tool>.trustExitCode can be used to indicate that the exit code of the custom command can be used to determine the success of the merge. Signed-off-by: Charles Bailey <charles@hashpling.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'git-mergetool.sh')
-rwxr-xr-xgit-mergetool.sh28
1 files changed, 26 insertions, 2 deletions
diff --git a/git-mergetool.sh b/git-mergetool.sh
index 2199c625c6..5c86f69229 100755
--- a/git-mergetool.sh
+++ b/git-mergetool.sh
@@ -251,6 +251,18 @@ merge_file () {
fi
status=$?
;;
+ *)
+ if test -n "$merge_tool_cmd"; then
+ if test "$merge_tool_trust_exit_code" = "false"; then
+ touch "$BACKUP"
+ ( eval $merge_tool_cmd )
+ check_unchanged
+ else
+ ( eval $merge_tool_cmd )
+ status=$?
+ fi
+ fi
+ ;;
esac
if test "$status" -ne 0; then
echo "merge of $MERGED failed" 1>&2
@@ -296,12 +308,20 @@ do
shift
done
+valid_custom_tool()
+{
+ merge_tool_cmd="$(git config mergetool.$1.cmd)"
+ test -n "$merge_tool_cmd"
+}
+
valid_tool() {
case "$1" in
kdiff3 | tkdiff | xxdiff | meld | opendiff | emerge | vimdiff | gvimdiff | ecmerge)
;; # happy
*)
- return 1
+ if ! valid_custom_tool "$1"; then
+ return 1
+ fi
;;
esac
}
@@ -369,10 +389,14 @@ else
merge_keep_backup="$(git config --bool merge.keepBackup || echo true)"
- if ! type "$merge_tool_path" > /dev/null 2>&1; then
+ if test -z "$merge_tool_cmd" && ! type "$merge_tool_path" > /dev/null 2>&1; then
echo "The merge tool $merge_tool is not available as '$merge_tool_path'"
exit 1
fi
+
+ if ! test -z "$merge_tool_cmd"; then
+ merge_tool_trust_exit_code="$(git config --bool mergetool.$merge_tool.trustExitCode || echo false)"
+ fi
fi