tig + mutt = commit review

I spend some of my time reviewing team members commits. Typically I’d use the RSS feed from Google Reader, but it doesn’t have the actual diff to comment on.

Most of the time I use tig to view
the commits. And instinctively I’d want to email the author with my comments, so here’s how to do that. I’m sure there are easier commands but this is what worked for me, your experience may vary.

First thing I did was create a git alias which is useful by itself. It outputs the commit to a temp file, then gets the title and the author’s email address from the same commit passing that to mutt.

    prepmail = !sh -c 'git show $1 > /tmp/commit && mutt -s \"`git show --pretty=format:\"%s\" $1 | head -n 1`\" -i /tmp/commit -- \"`git show --pretty=format:\"%ae\" $1 | head -n 1`\"' -

Now I want to be able to press a key in tig at the diff screen to reply to the author’s commit.

Simply bind a key, in my case I bound s in the diff view to call git prepmail with the commit’s SHA1.

In your $HOME/.tigrc add the following line. Checkout the tigrc man page for more information.

bind diff s !git prepmail %(commit)

Now in the diff view press ‘s’ and tig will launch mutt with the appropriate information.

The email shows up first:

Followed by the email’s subject, notice it matches the commit’s message.

And finally, the diff as an email body allowing you to comment on the changes
to the author.

So a simple git alias in $HOME/.gitconfig, a key binding for $HOME/.tigrc, and you can now review commits using tig. Enjoy!


Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s