0

The short question is: how to make

git diff

invoke

git difftool -t opendiff -y

? The second line is to invoke opendiff to diff some files, even when there is no configuration whatsoever done beforehand (I am using git version 1.9.2 and the current Xcode 12.1 on macOS Catalina and Big Sur).

The line

git config --global diff.external 'git difftool -t opendiff -y'

does not work.


Longer details:

We can readily invoke opendiff using git difftool -t opendiff -y, so git knows how to use opendiff as a visual diff tool without any additional configuration. And there is a way on github about how to use diff.external to invoke a separate shell script to invoke opendiff.

So since git readily knows how to invoke opendiff using difftool, we really should not need to use an external shell script. For the fact that diff.external can invoke any external command, then it would appear logical to even invoke itself, which is to invoke git difftool -t opendiff -y, but the line

git config --global diff.external 'git difftool -t opendiff -y'

won't work and can cause an error when we do a git diff afterwards. (it may appear it is due to git passing additional arguments to the "external" command?) The error it gives is:

fatal: 234c9c6e7d7f2798068d2f6ee434af9a9dd88123: no such path in the working tree. 
Use 'git <command> -- <path>...' to specify paths that do not exist locally. 
external diff died, stopping at foo.rb.

How to make it work so that git diff can invoke the git difftool with opendiff? It seems git diff and git difftool is a little bit adhoc, because we even configure the default difftool to use using git config --global diff.tool opendiff so we are touching diff to configure difftool. So in a way git diff and git difftool look like separate things but in a way they look like they are one unit.

One way to make it work but using an alias is

git config --global alias.diffy 'difftool -t opendiff -y'

but then we will need to use git diffy to run it instead of git diff. We can also create a Bash or Zsh alias gitdiff to run git difftool -t opendiff -y but it seems we should be able to use git diff without setting up an additional shell script.

nonopolarity
  • 146,324
  • 131
  • 460
  • 740
  • What exactly does "does not work" mean? – mkrieger1 Nov 23 '20 at 00:07
  • Note that `git difftool` *is* a shell script (with a small front end that does the initial setup). It's not really true that Git knows how to invoke `opendiff`. Instead, `git difftool` simply runs *any arbitrary command* with arguments supplied by the script. – torek Nov 23 '20 at 00:11
  • @mkrieger1 please see the error in the updated details – nonopolarity Nov 23 '20 at 00:12
  • @torek isn't `difftool` part of the `git` release? so you are saying `difftool` is almost the same as using the shell script using `diff.external`... any way to just make `git diff` use *that* script then, without we building a shell script separately? – nonopolarity Nov 23 '20 at 00:14
  • Parts of Git are just shell scripts that cobble together individual tools. Mergetool and difftool are done this way; they build on how Git uses its index. The `git diff` command is fairly different from these: it's a front end that picks one of three different back ends to run (`git diff-tree`, `git diff-index`, or `git diff-files`), and those are the core diff-engine parts of Git. Meanwhile setting an external diff is a way to direct the front end (`git diff`) to run a script: so it's at the same level, as it were, as `git difftool`. – torek Nov 23 '20 at 00:51
  • That's where your existing efforts are bottoming out or running aground or whatever metaphor you prefer. If you write your own script, you must pick one of the lower-level Git tools (diff-index or diff-tree or diff-files) to drive it. – torek Nov 23 '20 at 00:52
  • @torek then it might seem that `git` could use some sort of `diff.difftool` to specify a visual diff too and use it just like `git difftool` – nonopolarity Nov 23 '20 at 00:58
  • 1
    Well, maybe. You can always make proposals on the Git mailing list, of the form: "here's our usage scenario, here's a proposed change to make it work conveniently, and here's why we think this should be in future Git versions." – torek Nov 23 '20 at 01:11

0 Answers0