git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Choosing a mergetool according to file type

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 26, 2009, 16:57 UTC
Message-ID
<7viqijszjw.fsf@alter.siamese.dyndns.org>
In-Reply-To
<vpq7hyzqf1i.fsf@bauges.imag.fr>
Matthieu Moy <Matthieu.Moy@imag.fr> writes:
Show 18 quoted lines
> Gregory Jefferis <jefferis@gmail.com> writes:
>
>> This defines the merge driver but not the mergetool.  A mergetool is
>> presumably an interactive tool that helps you clean up failed automatic
>> merges.
>
> This is why I quoted the title of the section
>
>>>        Defining a custom merge driver
>
> Just tried it with 
>
> [merge "filfre"]
>        name = feel-free merge driver
>        driver = gedit %O %A %B
>        recursive = binary
>
> It did launch gedit interactively during the merge.

You are both correct. Your example runs "gedit" with three files before merge. If Gregory's custom mergetool expects the failed half-merge result as its input, this is not the interface he is looking for.

It shouldn't be hard to teach mergetool/difftool wrapper to support the per-path tool selection by running "git check-attr".

Right now it uses "diff.tool" and "merge.tool" configuration variables. In addition, it can arrange to consult "mergetool.$type.diff" and "mergetool.$type.merge". These new two variables will override the existing ones that are now treated as type-agnostic default.

IOW, something like this.
(1) In .gitattributes, define files whose name end with js is of type
    gjefferis in the mergetool namespace:
	*.js	mergetool=gjefferis
(2) In .git/config, define that gjefferis type is handled by diff-doc.js
    and merge-doc.js
    [mergetool "gjefferis"]
	diff = diff-doc.js
        merge = merge-doc.js
(3) Enhance get_configured_merge_tool() in git-mergetool--lib.sh and
    callchain that leads to it.
    type=$(git checkattr mergetool -- $file)
    if test -n "$type"
    then
    	mergetool=$(git config mergetool.$type.merge)
        difftool=$(git config mergetool.$type.diff)
    else
        mergetool=$(git config merge.tool)
        difftool=$(git config diff.tool)
    fi

It appears that right now the function does not know what file it is dealing with, so you may need to first restructure the callchain a bit, but it shouldn't be too painful.

Previous: Matthieu MoyNext: Gregory Jefferis
Message 6 of 8 in “Re: Choosing a mergetool according to file type”
  1. Gregory JefferisJun 26, 2009
  2. Johannes SixtJun 26, 2009
  3. Matthieu MoyJun 26, 2009
  4. Gregory JefferisJun 26, 2009
  5. Matthieu MoyJun 26, 2009
  6. Junio C HamanoJun 26, 2009
  7. Gregory JefferisJun 26, 2009
  8. Gregory JefferisJun 26, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.