SourceTree and Gerrit
SourceTree is a free GUI for git and mercurial produced by the people at Atlassian and I love it. It’s brilliant at loads of things, but I particularly find it useful for repo visualisation.
One of the cool features of SourceTree is that you can add arbitrary commit text replacements. For example, if you use Jira as a project tracking tool, SourceTree can find references to issues and turn them into links:
Jira Links
Setting this up is really simple:
- In SourceTree, when viewing your repo click the Settings button on the right hand side of the tool bar.
- Then click Advanced.
- You can then Add a Commit Text Replacement. Set the two required fields:
It really is that easy.
Links to Gerrit Change Ids
It’s also possible to add custom regex-based text replacements. For example, if you use gerrit (a brilliant open source git-based code review tool) then commit messages can have change-ids added. These allow for multiple changesets be linked together for the same commit - an essential part of the code review process.
Gerrit is a web-based tool, with each changset having its own URL. Using the SourceTree regex text replacement, we can change the change-ids present in the commit messages into links:
To set this up, we add a new Commit Text Replacement (as with the aforementioned Jira link), but select the type to be other.
We use the following regex pattern, which picks out the 40 character hex-hash, prefixed with a capital I:
And then the replacement is a correctly constructed HTML link:
This uses the gerrit query URL to search for the requested gerrit ID.
I find this tip really useful to see who reviewed commits which have been through gerrit, and to add reviewers to commits I have just pushed. Hope it helps somebody else as well.