• 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?

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

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.

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.

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 Join to answer
Community showcase
Brian Ganninger
Published Jan 23, 2018 in Sourcetree

Tip from the team: workflow and keyboard shortcuts

Supported Platforms macOS Sourcetree has a lot to offer and, like many developer tools, finding and using it all can be a challenge, especially for a new user. Everyone might not love ...

274 views 0 3
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot