1

This question is based on VonC's comment at the thread.

Is Git's auto-detection for difftool or mergetool scripted or is it within some Git executable?

Community
  • 1
  • 1
Léo Léopold Hertz 준영
  • 126,923
  • 172
  • 430
  • 675
  • Jakub Narębski just find the right section in the Git script: See my completed answer. – VonC Jun 30 '09 at 16:51

2 Answers2

4

It's scripted in git-mergetool. I found this at line 344 of my copy.

if test -z "$merge_tool"; then
    merge_tool=`git config merge.tool`
    if test -n "$merge_tool" && ! valid_tool "$merge_tool"; then
        echo >&2 "git config option merge.tool set to unknown tool: $merge_tool"
        echo >&2 "Resetting to default..."
        unset merge_tool
    fi
fi

if test -z "$merge_tool" ; then
    if test -n "$DISPLAY"; then
        merge_tool_candidates="kdiff3 tkdiff xxdiff meld gvimdiff"
        if test -n "$GNOME_DESKTOP_SESSION_ID" ; then
            merge_tool_candidates="meld $merge_tool_candidates"
        fi
        if test "$KDE_FULL_SESSION" = "true"; then
            merge_tool_candidates="kdiff3 $merge_tool_candidates"
        fi
    fi
    if echo "${VISUAL:-$EDITOR}" | grep 'emacs' > /dev/null 2>&1; then
        merge_tool_candidates="$merge_tool_candidates emerge"
    fi
(snip)
kwatford
  • 21,848
  • 2
  • 43
  • 60
  • I need to download a new Git and see its source. My git is in a compiled format such that it is impossible to read it. @ How can you see your Git's source code without downloading a new one? – Léo Léopold Hertz 준영 Jul 04 '09 at 00:12
  • @Masi: While git itself is compiled, a lot of the commands (like mergetool) are in fact just scripts tucked away somewhere. On my system these are mostly stored in /usr/lib/git-core/ – kwatford Jul 04 '09 at 01:58
2

As mentioned in the git mergetool man page,

--tool=<tool>

Use the merge resolution program specified by .
Valid merge tools are: kdiff3, tkdiff, meld, xxdiff, emerge, vimdiff, gvimdiff, ecmerge, diffuse, tortoisemerge, opendiff and araxis.

Now, where does that list comes from?

Actually, those tools (and their custom options) are used in the script:

<Git>/libexec/git-core/git-mergetool--lib

and used by the script git-mergetool, which does the selection based on git config merge.tool command.

But there is a bit of 'auto-selection' based on the valid_tool() function in git-mergetool--lib:

valid_tool ()

It uses get_merge_tool_cmd() which is based on mergetool.<aMergeToolName>.cmd.
If that setting remain in one of the git config files... that tool will be selected.


Right..., Jakub Narębski just pointed out the right section in the git-mergetool--lib script:

get_merge_tool () {
    # Check if a merge tool has been configured
    merge_tool=$(get_configured_merge_tool)
    # Try to guess an appropriate merge tool if no tool has been set.
    if test -z "$merge_tool"; then
        merge_tool="$(guess_merge_tool)" || exit
    fi
    echo "$merge_tool"
}

That function aptly named guess_merge_tool() (you think I should be able to find it!...) does amongst other thing, the following, which could explain it detects opendiff:

# Loop over each candidate and stop when a valid merge tool is found.
for i in $tools
do
    merge_tool_path="$(translate_merge_tool_path "$i")"
    if type "$merge_tool_path" > /dev/null 2>&1; then
        echo "$i"
        return 0
    fi
done
Community
  • 1
  • 1
VonC
  • 1,129,465
  • 480
  • 4,036
  • 4,755