renaming instead of replacing files on a pull

I have some custom diff software that I'd like to use to compare versions. To do this I need to have both the old (local) version of a file, and the pulled version, in the same folder. Is it possible to, on a pull, for any modified files (on the server) rename the local ones, and then pull the newest ones to the same names as before?

1 answer

Is there any reason you'd want to do this except in the case of a merge conflict? If there's a merge conflict, then both versions are available anyway via hg/git, you can 'resolve using theirs' or 'resolve using mine', or indeed use a merge tool.

If it's just because you want to diff the history, you can do this just by hooking up your diff tool as an external diff option. In Preferences > Diff you can select one of a number of pre-configured tools, or you can set up a custom tool if you want. Then, you can use that to diff from the log either for a single commit's changes, or for a range of commits (multi-select).

OK, so I think what I actually want is to do an diff using an external program. I'm trying to use the latexdiff tool, which takes in two latex documents and returns a third which is the diff. Normal command line usage is:

latexdiff file1.tex file2.tex > diff.tex

I've tried a set up where I put latexdiff in the the "diff command" box and "$LOCAL $REMOTE > diff.tex" in the arguments box, but it doesn't seem to do anything. I'm running OS X 10.8.2 on a Macbook Air, and version 1.5.5 of SourceTree. The repository in question is a Mercurial repository, stored on Bitbucket.

So in experimenting I've discovered that the external diff tool seems to open an external program that shows a diff, rather than creating an output file in the relevant directory, as I would like.

Perhaps you want to create a patch instead? You can right-click a commit and select Create Patch to export the changes as a patch file.

Unfortunately the diff program needs the old and the new files as input, not a patch file.

OK, well the external diff tool should work then, because it will be called with 2 parameters, the file instances will just be extracted from the repo on demand and put in a temp folder before the ext diff is called. Although the intention is usually to display a visual tool, there's nothing to say that it has to be that. The only tricky part might be the pipe you're trying to use there, which won't work because it won't be called in a full shell. If there's an --output option or similar, that should work.

There's not an output option. I tried writing a new shell script that did the piping inside the shell, but that doesn't seem to work either.

This unfortunately may not be doable via the external diff features of git/hg then (ST essentially just sets these up in the ~/.gitconfig etc al). You may just have to use custom scripts to export file contents at given commits and execute your tool on them that way - you can hook up most external scripts to SourceTree via the Custom Action feature in Preferences, including the context of the commit and selected file.

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published May 30, 2018 in Sourcetree

Tip from the team: configuring Git or Mercurial in Sourcetree

Supported Platforms macOS Windows To make using Sourcetree as simple yet powerful as possible we embed (bundle) dependencies such as Git, Git LFS, and Mercurial. We strive to keep these...

414 views 0 1
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