Subversion – show commit details when editing commit message
by bigpresh on May.21, 2009, under Perl, Programming, Uncategorized
Something I’ve wanted to do for a while is get the list of changed files and a diff into the commit message in my editor when I make a commit with Subversion.
With Git, you can pass the -v (verbose) option when committing, and the commit message you edit will include diffs as well as the list of modified files.
Subversion provides no such option, so I put together a little wrapper shell script to do this for me.
The script provides a function named svncommit (which I alias to just ‘ci’ for supreme shortness :) ).
When used, after the “–This line, and those below, will be ignored–” marker line, the list of files and then diffs will be inserted, as shown in the screenshot below (click for full size):
The script itself is relatively simple (it was knocked up quickly; I’ll probably improve on it sometime):
# Do an svn commit, with diffs included in the commit message svncommit() { # Start preparing the commit message which we'll then edit COMMITMSG=/tmp/$USER-commitmsg echo > $COMMITMSG echo "--This line, and those below, will be ignored--" >> $COMMITMSG svn status "$@" >> $COMMITMSG echo >> $COMMITMSG # Now do a diff; work out stats on lines added/removed by looking at # the diff, add that info, then the diff itself svn diff "$@" > /tmp/$USER-svndiff LINESADDED=$( grep '^+[^+]' /tmp/$USER-svndiff | wc -l) LINESREMOVED=$(grep '^-[^-]' /tmp/$USER-svndiff | wc -l) echo "Added $LINESADDED lines, removed $LINESREMOVED lines" >> $COMMITMSG echo >> $COMMITMSG cat /tmp/$USER-svndiff >> $COMMITMSG echo >> $COMMITMSG ORIGMD5=$(md5sum $COMMITMSG) $VISUAL $COMMITMSG if [[ "$(md5sum $COMMITMSG)" == "$ORIGMD5" ]]; then echo "Commit message unchanged, commit aborted"; else svn commit "$@" -F $COMMITMSG fi rm $COMMITMSG rm /tmp/$USER-svndiff }
May 27th, 2009 on 9:40 am
nice post and thanks for the script i will use it and will try to improve it.
June 4th, 2009 on 1:01 pm
Helpful and great post. Thank’s for sharing
June 13th, 2009 on 8:18 pm
Very useful Post. Thanks for the script. I will use it.
June 22nd, 2009 on 8:15 pm
I think I messed something up when I changed the script, I will have another go, thankf for this
July 20th, 2009 on 11:58 am
thanks for this usefull informations..
now i find what i want to know..
thanks so much..