# "git difftool" is not working as expected during MERGING

2 messages from 2015-06-10 to 2015-06-11. Participants: Bossert, Andre, David Aguilar.
Thread: https://gitlist.dev/t/39584

## Bossert, Andre, 2015-06-10 13:12

Subject: "git difftool" is not working as expected during MERGING
Message-ID: <CALzBCsGSJJZhWRoSVW6-tb+grxnFTOWSQ8kQFmwk05sC-30Q6w@mail.gmail.com>
URL: https://gitlist.dev/e/CALzBCsGSJJZhWRoSVW6-tb%2BgrxnFTOWSQ8kQFmwk05sC-30Q6w%40mail.gmail.com

```
Hello,

i've tested "git difftool" with -t --ext-cmd and other options to see
my diff with external tools, but it always show internal text-diff in
console. The same tests with "git mergetool" working as expected. I've
compared (nanually reviewed) git-mergetool.sh with git-difftool.pl and
see that difftool is mixed / shared implementation with normal "git
diff" command. So during MERGING state there is no possibility to call
external difftool with this command. Any ideas why this was
implemented this way?

-- 
Regards
Andre (anb0s)
eMail: anb0s@anbos.de

```

## David Aguilar, 2015-06-11 09:22

Subject: Re: "git difftool" is not working as expected during MERGING
Message-ID: <20150611092205.GA93332@gmail.com>
URL: https://gitlist.dev/e/20150611092205.GA93332%40gmail.com
In-Reply-To: <CALzBCsGSJJZhWRoSVW6-tb+grxnFTOWSQ8kQFmwk05sC-30Q6w@mail.gmail.com>

```
On Wed, Jun 10, 2015 at 03:12:21PM +0200, Bossert, Andre wrote:
> Hello,
> 
> i've tested "git difftool" with -t --ext-cmd and other options to see
> my diff with external tools, but it always show internal text-diff in
> console. The same tests with "git mergetool" working as expected. I've
> compared (nanually reviewed) git-mergetool.sh with git-difftool.pl and
> see that difftool is mixed / shared implementation with normal "git
> diff" command. So during MERGING state there is no possibility to call
> external difftool with this command. Any ideas why this was
> implemented this way?
> 
> -- 
> Regards
> Andre (anb0s)
> eMail: anb0s@anbos.de

The "why" behind this behavior is likely, "historical reasons".

The behavior you described is an unfortunate side-effect of how
it's implemented under the hood.  As you discovered, difftool is
built upon git-diff's GIT_EXTERNAL_DIFF feature.

That feature is not invoked when the index contains multiple
stages (i.e. when merging) and the combined diff is printed
instead.

A logical extension to the GIT_EXTERNAL_DIFF machinery might be
something like supporting a GIT_EXTERNAL_MERGE_DIFF variable to
handle the 3-way case.  We could then plug this edge case by
creating a new handler that reuses the mergetool code[1].

Alternatively, we could make "git diff" stricter and teaach it
to die() when doing a mergy diff and GIT_EXTERNAL_DIFF is set.
That might break existing setups, though, so having a new
feature does seem preferable over making it stricter.

As you mentioned, using "git mergetool" works.  That's because
mergetool is the intended tool for that use case.  The fact that
difftool prints a combined diff when when your worktree is in
the middle of a conflicted merge is simply an unpolished edge
case.

If you've already resolved all of your conflicts, and everything
is staged, then "git difftool --staged" will work too.

Let me know if you have any questions.  If you're interested in
implementing the idea described in [1] then I'd be happy to help
review and test the code, but for now you can probably just use
"git mergetool".

cheers,
-- 
David

```
