1

According to doc and various answers here git difftool will invoke the specified executable (usually a shell script) with environment variables LOCAL and REMOTE set to the file paths. But when I try, LOCAL and REMOTE are not set. I've tried the following test:

git config --global diff.tool mytest  
git config --global difftool.mytest.cmd mytest.sh  
git config --global difftool.prompt false  

with mytest.sh:

#!/bin/sh  
echo "LOCAL:$LOCAL REMOTE:$REMOTE"  

invoking:

git difftool --tool mytest <commitid> -- <path-to-file>  

output:

LOCAL: REMOTE:  

Any suggestions?

Lukáš Lalinský
  • 40,587
  • 6
  • 104
  • 126
c-urchin
  • 4,344
  • 6
  • 28
  • 30

2 Answers2

4

What the man page means is that difftool.<tool>.cmd can have $LOCAL and $REMOTE in its command-line. Those will be replaced with the relevant file paths. It isn't intended that those variables are exported into your environment.

To demonstrate with an example, here's a re-worked version of your original setup.

git config --global diff.tool mytest  
git config --global difftool.mytest.cmd 'mytest.sh $LOCAL $REMOTE'
git config --global difftool.prompt false
jamessan
  • 41,569
  • 8
  • 85
  • 85
0

This is the diff wrapper I've always used (with tkdiff):

#!/bin/sh

# diff is called with 7 parameters:
# path old-file old-hex old-mode new-file new-hex new-mode

tkdiff "$2" "$5"

Which uses parameters rather than $LOCAL and $REMOTE.

Aaron
  • 9,123
  • 5
  • 40
  • 38
  • 1
    I've tried that, $1, $2, etc are not set either. Anyway from the docs that invocation is used for "git diff" configured with external tool, not for "git difftool" – c-urchin Dec 18 '09 at 19:57