Four years ago, I built a little EXE to use for external diffs that let me apply BeyondCompare to the paired files that represent various things in Visual FoxPro. Along the way, I ran into the fact that the $REMOTE parameter passed into external diffs is relative to the repository's home folder. (I asked about that then: https://community.atlassian.com/t5/Sourcetree-questions/Custom-diff-tool-finding-the-REMOTE-file/qaq-p/1551704)
Back then, I found a workaround in VFP that let the thing work for me. Now, I have a new computer and that workaround isn't working anymore.
Is there a way to get my hands on the repository's home folder? If I had that, I'm pretty sure I can do the rest.
Alternatively, is there any way to specify that $REMOTE include a full path?
Thanks, Tamar
Hi @TamarGranor
I'm not very good at Source Tree, so I asked Rovo this question to see if it is able to provide some advice, and this is the response provided:-
Short version: Sourcetree still doesn’t expose the repository root to your external diff command, and there’s no way to make $REMOTE a fully‑qualified path from within Sourcetree’s config. You’ll need to reconstruct the full path in your EXE again.
From your original post at
Custom diff tool: finding the $REMOTE$ file
$LOCAL → a fully‑pathed temporary file (the committed side).
$REMOTE → a relative path from the repo root, e.g. CLASSLIBS\MyClassLib.VCX.
Sourcetree’s external diff arguments only support the documented placeholders ($LOCAL, $REMOTE, etc.), and there’s no additional “repository root” or “working directory” token you can use. There’s also no option to say “pass $REMOTE as an absolute path instead”.
So:
Is there a way to get my hands on the repository's home folder?
Is there any way to specify that$REMOTEinclude a full path?
From Sourcetree itself: no to both.
You’re back to the same class of workaround you used in VFP before, but you can probably make it more robust so it doesn’t depend on machine‑specific quirks.
Assuming $REMOTE is always “path inside repo”, these are your realistic options:
Sourcetree typically launches the external diff tool with the repository as the working directory. If that’s true in your setup, your EXE can:
Get the process current directory.
Combine it with the $REMOTE parameter.
Pseudo‑flow in your EXE:
repoRoot := GetCurrentDirectory()
remoteRel := param2 && e.g., "CLASSLIBS\MyClassLib.VCX"
remoteFull := PathCombine(repoRoot, remoteRel)Then pass remoteFull to Beyond Compare along with $LOCAL.
If this used to work and now doesn’t, there are a couple of likely culprits on the new machine:
The EXE is being launched from a different working directory (e.g., your tool’s own folder).
Some “run as admin” or shortcut wrappers changed the working directory.
You’re now calling it through a script/launcher that changes CWD.
You can test this easily by having your EXE just log the current directory and arguments to a text file.
$REMOTEIf the working directory isn’t reliable, you can:
Use $REMOTE to locate the repo folder from the file system:
Use the relative path to find a matching file somewhere under your usual dev roots, or
Accept a base “search root” in a config file/registry, and walk up the path until you find .git or .hg.
Or, if you know you’re always inside a Git repo, you can shell out:
git rev-parse --show-toplevelexecuted in any directory inside the repo gives you the absolute repo root.
So your EXE can:
Change directory to where you think the file lives (or to a likely base).
Run git rev-parse --show-toplevel.
Combine that result with $REMOTE.
That’s more work, but it decouples you from Sourcetree’s launch environment.
If you don’t mind a little per‑repo setup, have your EXE read a simple config:
E.g. .<yourtool>.ini at the repo root containing:
[repo]
root=C:\Dev\MyProjectYour EXE:
Walks upwards from its own location or from a guessed base until it finds that ini file.
Reads the root path.
Combines root + $REMOTE.
This keeps it reusable but lets you override edge cases.
$REMOTEThere’s nothing in the current Sourcetree docs or support articles that indicates:
A token like $REPO / $WORKDIR / $ROOT.
A checkbox/setting to “pass absolute path for REMOTE”.
The external diff arguments are fixed to the existing placeholders; you can see this pattern echoed in other Sourcetree usage docs like:
General Sourcetree KB index:
Sourcetree support | Sourcetree - latest | Atlassian Support
Repository settings KB (example):
Changing remote repository path on SourceTree using Git or Mercurial | Sourcetree | Atlassian Support
None of those introduce extra diff‑tool macros.
So the only realistic route is to let your EXE reconstruct the full path using one of the strategies above.
Upon doing some further checking, this time with Google's AI and a different response is provided:-
$REMOTE and $LOCAL parameters passed to custom diff tools are indeed paths to temporary files created by Git, not the original files in your working directory. git rev-parse --show-toplevel
$REMOTE and $LOCAL point to temp files, the $MERGED parameter (often available in diff contexts as well) typically contains the relative path of the file from the repository root. "$MERGED" as a third argument to your EXE, you can combine the root path (from step 1) with this relative path to get the full original filename.
"$LOCAL" "$REMOTE" "$MERGED"$MERGED) to see the file's name and relative path.git rev-parse --show-toplevel to find where the repo lives on your new computer.
PATH. If your EXE cannot find git.exe to run the rev-parse command, it will fail. You can check this by typing git --version in a standard command prompt.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.