tags:

views:

41

answers:

2

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?

A: 

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
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
+1  A: 

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
Thanks very much!
c-urchin