Seeing Subversion Diffs for Commit Messages
When I go to check code into a Subversion repository, I like to review a diff of my changes. I can confirm I’m committing the right files, make sure I didn’t leave in any debugging statements, and take one last chance to ponder the code. Usually this means doing an svn diff
in another window or shelling out of vim to run it. This is a bit awkward, so it’s easy to forget the step. That’s backwards, it should be easier to do things right than slack.
So I decided to streamline the process (based off this), so that the commit template that svn provides goes from:
--This line, and those below, will be ignored--
M nearbygamers.com/public/stylesheets/screen.css
to:
--This line, and those below, will be ignored--
M nearbygamers.com/public/stylesheets/screen.css
Index: foo
===================================================================
Index: public/stylesheets/screen.css
===================================================================
--- public/stylesheets/screen.css (revision 360)
+++ public/stylesheets/screen.css (working copy)
@@ -1,3 +1,6 @@
+h1 {
+ margin-bottom: 0.25em;
+}
.tag_edit {
margin-top: 2em;
font-size: 80%;
First, I have a \~/bin
for storing my own commands. In my .profile
, I make sure this is the first thing in my path:
` export PATH=~/bin:$PATH `{lang=”bash”}
Then I added a \~/bin/svn
to catch commits, take a diff, and then call my . After saving and setting the execute bit (chmod +x \~/bin/svn
), you’ll probably have to start a new shell for it to be called.
#!/bin/sh
REALSVN=/usr/bin/svn
ARGS="$@"
if [ "$1" = "commit" -o "$1" = "ci" ]; then
shift # pop off $1 for diff
TEMPLATE=`mktemp`
$REALSVN diff "$@" > "$TEMPLATE"
$REALSVN $ARGS --editor-cmd="~/bin/svn-diff-editor '$TEMPLATE'"
else
$REALSVN $ARGS
fi
This called \~/bin/svn-diff-editor
, which loads the diff into the commit template and invokes your default editor. (Don’t forget to set the execute bit on this as well.)
echo >> "$2"
cat "$1" >> "$2"
rm "$1"
$VISUAL "$2"