Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
  • Community
  • Products
  • Sourcetree
  • Questions
  • How do I pass the absolute path to an external diff tool for both $LOCAL and $REMOTE when one of those is associated with the currently checked-out commit?

How do I pass the absolute path to an external diff tool for both $LOCAL and $REMOTE when one of those is associated with the currently checked-out commit?

intelligen May 14, 2015

I'm trying to use an external diff tool to compare a given file from two commits. If I select two commits in SourceTree and neither one is currently checked out, the file is checked out from each branch, copied to a temporary location, and the absolute (full) path of each is passed to the external diff tool. Everything works fine.

However, if one of the commits is currently checked out, the absolute path is not passed to the external diff tool. It seems only the filename (or perhaps relative path, based from the root working dir of the git repo) is passed. This causes the external diff to fail because the current working directory is the directory containing the external diff tool, rather than the appropriate directory within the git workspace ($PWD in SourceTree).

If I replace $LOCAL and $REMOTE with $PWD\$LOCAL and $PWD\$REMOTE, respectively, the absolute path for the file in the currently checked-out commit is passed correctly, but of course this breaks the other one (the temporary file path from the branch which is not checked out).

I've also reproduced the same issue with git difftool on the command-line, but of course when running the path on the command-line, the current working directory is correct. Is there a workaround to make SourceTree prepend $PWD\ only when necessary? If not, is there some other solution that will solve my problem?

2 answers

1 accepted

0 votes
Answer accepted
intelligen June 2, 2015

This issue seems to be a defect in SourceTree's design. Normally when you use git, your current working directory is in the git repo. SourceTree, on the other hand, does not set the the git repo as the current working directory, so any relative paths will be incorrect.

I ended up having to create a batch file and pass $PWD as an additional argument. (In my testing, I found that $PWD apparently reports the root of the git repo.) The batch file cd's into $PWD, then passes the remaining arguments to the external diff tool.

0 votes
Seth
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 15, 2015

First of all, seems like the solution is going to be OS dependent.

Secondly, if your difftool is in your OS's PATH variable, the diff tool should be runnable from you repo directory instead of the difftool executable's directory.

intelligen May 21, 2015

To clarify, the problem seems to be that SourceTree just calls git difftool from the external diff tool's directory, rather than cd'ing into the correct directory first.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events