Git (2.22.0) difftool no longer passes through to git diff if diff.tool is unset
Asked Answered
K

1

1

Per @VonC's answer in https://stackoverflow.com/a/56212234 in Git 2.22.0 (released 2019-06-08), a number of changes were made to the git difftool command regarding how its configuration is determined.

However, unless I am missing something here, it appears that a regression in functionality has been introduced in this version. In previous versions, including 2.21.0, it has been possible to use git difftool without any configuration or CLI options, in which case it passes through to git diff.

Now in Git 2.22.0 if I use git difftool without configuring diff.tool or merge.tool, I get the following message:

This message is displayed because 'diff.tool' is not configured.
See 'git difftool --tool-help' or 'git help config' for more details.
'git difftool' will now attempt to use one of the following tools:
kompare emerge vimdiff

Is there any way of bypassing this error and returning to the old behavior of passing through to git diff or must I call git diff directly?

edit: According to Jeff King's mailing list reply, the new behavior is intentional. However at the top of the git-difftool documentation, it says that:

git difftool is a frontend to git diff and accepts the same options and arguments. See git-diff[1].

Is this no longer the case?

Kaufmann answered 19/6, 2019 at 21:8 Comment(0)
F
2

TLDR; The new error message "This message is displayed because 'diff.tool' is not configured." might be an actual bug fix, and not a new error.


I just tried and... didn't get any error message (when used without parameters).

vonc@vonvb:~/git/cplgit/linux$ ./set_git 2.22.0
git set to v2.22.0
vonc@vonvb:~/git/cplgit/linux$ git version
git version 2.22.0

vonc@vonvb:~/git/cplgit/linux$ git config -l|grep -i tool

vonc@vonvb:~/git/cplgit/linux$ git difftool

Plus, this error message has been introduced in commit 5338a6a, Jan. 2013, Git v1.8.2-rc0.
I did mentioned commit 05fb872 from Git 2.22, which uses ${GIT_MERGETOOL_GUI}.
That environment variable is not set on my machine, and I don't get any error message.
Check your own git config and environment variables.

I do see the error message in Git 2.22 with:

vonc@vonvb:~/gits/src/git$ git difftool --no-index color.c color.h

This message is displayed because 'diff.tool' is not configured.
See 'git difftool --tool-help' or 'git help config' for more details.
'git difftool' will now attempt to use one of the following tools:
meld opendiff kdiff3 tkdiff xxdiff kompare gvimdiff diffuse diffmerge ecmerge p4merge araxis bc codecompare smerge emerge vimdiff

Viewing (1/1): 'color.c'
Launch 'bc' [Y/n]? 
The diff tool bc is not available as 'bcompare'
fatal: external diff died, stopping at color.c

With Git 2.21.0, it does default to a regular git diff:

vonc@vonvb:~/git/cplgit/linux$ ./set_git 2.21.0
git set to v2.21.0
vonc@vonvb:~/git/cplgit/linux$ git version
git version 2.21.0
vonc@vonvb:~/git/cplgit/linux$ cdgg
vonc@vonvb:~/gits/src/git$ git difftool --no-index color.c color.h
diff --git a/color.c b/color.h
index ebb222ec33..98894d6a17 100644

From the OP Git mailing list thread:

Denton Liu pinpoints the original commit 287ab28 (16 Feb 2019) by Jeff King (peff).
(Merged by Junio C Hamano -- gitster -- in commit 12e5bdd, 07 Mar 2019)

diff: reuse diff setup for --no-index case

When "--no-index" is in effect (or implied by the arguments), git-diff jumps early to a special code path to perform that diff.
This means we miss out on some settings like enabling --ext-diff and --textconv by default.

Jeff King replies:

I don't know much about how git-difftool works, but it looks like it sets GIT_EXTERNAL_DIFF=git-difftool--helper.

Prior to 287ab28bfa, we would not have respected any external diff command when running git-diff. But after it, we do.

In the case that the user has not provided --no-index, then this all works as I guess difftool is meant to: it runs the helper and says "hey, you have not configured this".

It seems like the behavior of the above command prior to 287ab28bfa was not intentional.
It would run git-diff, expecting it to trigger the helper, but it never did (and instead just did a normal no-index diff).

So it seems like the new behavior is actually the right thing, as it makes the --no-index case consistent with the regular one?
I'm not at all clear why you would run "difftool" here if you it is not configured and you just want the straight diff output.

Fabrizio answered 19/6, 2019 at 22:2 Comment(8)
Thank you -- I am not seeing any config/environment variables relating to Git diff/merge tools. What if you do a git difftool --no-index <file 1> <file 2>? (ensuring the two files have different contents)Kaufmann
@Kaufmann I have edited the answer... which confirms your reported regression. github.com/git/git/commit/… is a problem.Fabrizio
Great thanks for confirming that! Should I send in a bug report to the Git mailing list? Never done that before.Kaufmann
@Kaufmann Yes, on public-inbox.org/git. Leave as a comment the URL of your thread on that mailing list.Fabrizio
@Kaufmann Just checked with Git 2.23.0 batch 2: the error does persists.Fabrizio
thanks for checking that. I submitted the report here: public-inbox.org/git/…Kaufmann
@Kaufmann I have edited the answer to reflect the current conclusion of the thread.Fabrizio
I am not able to easily reply to the mailing list but I agree with their conclusion. Apparently I was relying on a bug instead of a feature without knowing it.Kaufmann

© 2022 - 2024 — McMap. All rights reserved.