# Re: Choosing a mergetool according to file type

8 messages from 2009-06-26 to 2009-06-26. Participants: Gregory Jefferis, Johannes Sixt, Matthieu Moy, Junio C Hamano.
Thread: https://gitlist.dev/t/19942

## Gregory Jefferis, 2009-06-26 11:04

Subject: Re: Choosing a mergetool according to file type
Message-ID: <C66A69E6.205F2%jefferis@gmail.com>
URL: https://gitlist.dev/e/C66A69E6.205F2%25jefferis%40gmail.com
In-Reply-To: <4A44A66B.10906@viscovery.net>

```
Hi Johannes,

On 2009-06-26 11:43, "Johannes Sixt" <j.sixt@viscovery.net> wrote:

> I don't think that you can choose the merge tool by setting attributes.

OK, that was my impression, but I wanted to check.

 > The reason I write to you is: Can you tell me what 'wordgitmerge' and
> 'wordgitdiff' are?
> 
> I, too, have a number of Word files that I need to merge every now and then.

Ah!  Well they are nothing fancy, I'm afraid, just scripts that call Word
itself, but that turns out to work pretty well.  For Mac (my platform) they
have to be in applescript.  For Windows I imagine they could be pretty much
the same as the scripts here:

http://tortoisesvn.tigris.org/svn/tortoisesvn/trunk/contrib/diff-scripts/

diff-doc.js
merge-doc.js

Perhaps tortoisegit already exposes this.  Those scripts include fallbacks
for openoffice so I suppose one could use that on linux.

Best,

Greg.

```

## Johannes Sixt, 2009-06-26 11:29

Subject: Re: Choosing a mergetool according to file type
Message-ID: <4A44B128.6040800@viscovery.net>
URL: https://gitlist.dev/e/4A44B128.6040800%40viscovery.net
In-Reply-To: <C66A69E6.205F2%jefferis@gmail.com>

```
Gregory Jefferis schrieb:
> http://tortoisesvn.tigris.org/svn/tortoisesvn/trunk/contrib/diff-scripts/
> 
> diff-doc.js
> merge-doc.js
> 
> Perhaps tortoisegit already exposes this.  Those scripts include fallbacks
> for openoffice so I suppose one could use that on linux.

Thanks a lot for the pointer.

The interesting one is merge-doc.js. Unfortunately, it still only just
compares "their" and "our" versions, and the user must go through all
marked changes and reject everything that would undo "our" changes and
accept all "their" changes. That's exactly what I already do. :-(

That said, the scripts are written *much* nicer than what I have written
myself.

-- Hannes

```

## Matthieu Moy, 2009-06-26 12:04

Subject: Re: Choosing a mergetool according to file type
Message-ID: <vpqd48rw68k.fsf@bauges.imag.fr>
URL: https://gitlist.dev/e/vpqd48rw68k.fsf%40bauges.imag.fr
In-Reply-To: <C66A69E6.205F2%jefferis@gmail.com>

```
Gregory Jefferis <jefferis@gmail.com> writes:

> Hi Johannes,
>
> On 2009-06-26 11:43, "Johannes Sixt" <j.sixt@viscovery.net> wrote:
>
>> I don't think that you can choose the merge tool by setting attributes.
>
> OK, that was my impression, but I wanted to check.

Never used it, but man gitattributes says

   Performing a three-way merge
       merge
[...]
              String
                 3-way merge is performed using the specified custom merge driver. The built-in 3-way merge driver can be explicitly specified by asking
                 for "text" driver; the built-in "take the current branch" driver can be requested with "binary".
[...]
       Defining a custom merge driver

Is it not what you're looking for?

-- 
Matthieu

```

## Gregory Jefferis, 2009-06-26 13:27

Subject: Re: Choosing a mergetool according to file type
Message-ID: <C66A8B6B.20617%jefferis@gmail.com>
URL: https://gitlist.dev/e/C66A8B6B.20617%25jefferis%40gmail.com
In-Reply-To: <vpqd48rw68k.fsf@bauges.imag.fr>

```
Hi Matthieu,

Thanks for your reply.

On 2009-06-26 13:04, "Matthieu Moy" <Matthieu.Moy@imag.fr> wrote:

> Never used it, but man gitattributes says
> 
>    Performing a three-way merge
>        merge
> [...]
>               String
>                  3-way merge is performed using the specified custom merge
> driver. The built-in 3-way merge driver can be explicitly specified by asking
>                  for "text" driver; the built-in "take the current branch"
> driver can be requested with "binary".
> [...]
>        Defining a custom merge driver
> 
> Is it not what you're looking for?

This defines the merge driver but not the mergetool.  A mergetool is
presumably an interactive tool that helps you clean up failed automatic
merges.  For my binary files the internal merge driver "binary" will be used
which as your quote points our keeps the local file and signals a conflict
if it is different from the remote file.  I cannot define a custom merge
driver for my binary word files because I don't have such a program (which
would have to carry out the merge in a non-interactive fashion).  As
mergetool I use a script that calls Word and that of course has to be
interactive.

Best,

Greg.

```

## Matthieu Moy, 2009-06-26 13:51

Subject: Re: Choosing a mergetool according to file type
Message-ID: <vpq7hyzqf1i.fsf@bauges.imag.fr>
URL: https://gitlist.dev/e/vpq7hyzqf1i.fsf%40bauges.imag.fr
In-Reply-To: <C66A8B6B.20617%jefferis@gmail.com>

```
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.

-- 
Matthieu

```

## Junio C Hamano, 2009-06-26 16:57

Subject: Re: Choosing a mergetool according to file type
Message-ID: <7viqijszjw.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7viqijszjw.fsf%40alter.siamese.dyndns.org
In-Reply-To: <vpq7hyzqf1i.fsf@bauges.imag.fr>

```
Matthieu Moy <Matthieu.Moy@imag.fr> writes:

> 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.

```

## Gregory Jefferis, 2009-06-26 17:03

Subject: Re: Choosing a mergetool according to file type
Message-ID: <C66ABE00.20643%jefferis@gmail.com>
URL: https://gitlist.dev/e/C66ABE00.20643%25jefferis%40gmail.com
In-Reply-To: <vpq7hyzqf1i.fsf@bauges.imag.fr>

```
Hi Matthieu,

On 2009-06-26 14:51, "Matthieu Moy" <Matthieu.Moy@imag.fr> wrote:

> 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.

Hmm, I had of course looked at this but this thought that it wouldn't do
what I want. For one, I thought this would _always_ call gedit even if the
file is unchanged in remote. Testing, however this doesn't seem to be the
case. So I think you're right that this method can be used satisfactorily
even with an interactive merge and I have made a little script that seems to
do what I need.

On the other hand to me it does somewhat violate the separation between
automatic and interactive merging and one probably has to be quite careful
about what state the merge files are left in - presumably things that
whoever wrote the builtin "binary" merge thought about carefully.

All the best,

Greg.

```

## Gregory Jefferis, 2009-06-26 17:43

Subject: Re: Choosing a mergetool according to file type
Message-ID: <C66AC756.2064B%jefferis@gmail.com>
URL: https://gitlist.dev/e/C66AC756.2064B%25jefferis%40gmail.com
In-Reply-To: <7viqijszjw.fsf@alter.siamese.dyndns.org>

```
On 2009-06-26 17:57, "Junio C Hamano" <gitster@pobox.com> wrote:

> 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.

I think that Matthieu is more correct this time in that I can do what I need
with the merge driver because I don't need the failed half-merge result.
But I prefer the 2 level arrangement of 1) automatic then 2) fixing merge
conflicts manually since there will be other cases where this is required.

Thank you Junio for pointing out how to do add the necessary functionality -
a project for a rainy weekend I guess.

Best,

Greg.

```
