Search This Blog

Tuesday, December 7, 2010

Setting up an email notification for subversion repository

Add the following piece of code in the /.../<<svnroot>>/<<repository_name>>/hooks/post-commit


#!/bin/sh
REPOS="$1"
REV="$2"
/usr/local/bin/svnnotify -r "$REV" -C -d -H Alternative \
 --alt HTML::ColorDiff -p "$REPOS" -t "xxxx@xxxx.com" \
 --from 'SVN @ xxxx.com <svn@xxxx.com>'

if svnnotify command is not present on your svn server then use following code in the post-commit file

#!/bin/sh
REPOS="$1"
REV="$2"
/usr/bin/svnlook diff -r "$REV" "$REPOS" | mutt -s "SVN Notify" xxxx@xxxx.com

2 comments:

  1. A more detailed report can be achieved via following code

    #!/bin/sh
    REPOS_NAME="$1"
    REPOS="/path/to/svnroot/$1"
    REV="$2"
    AUTHOR=$(svnlook author -r $REV $REPOS)
    DATE=$(svnlook date -r $REV $REPOS)

    {
    echo "REPOSITORY: $REPOS_NAME"
    echo "REVISION: $REV"
    echo "COMMITTED BY: $AUTHOR"
    echo "DATE: $DATE"

    echo ""
    echo "DESCRIPTION:"
    svnlook log -r $REV $REPOS

    echo ""
    echo "FILES:"
    svnlook changed -r $REV $REPOS

    } | mail -s "[SVN Notify] Check In Rev $REV by $AUTHOR" xxxx@xxxx.com

    ReplyDelete
  2. This script might not give your proper output, the output could be similar to


    REPOSITORY: /extra/svn/armada
    REVISION: 10641
    COMMITTED BY:
    DATE:

    DESCRIPTION:

    FILES:

    The problem can be resolved by adding following code in the post-commit file

    PATH=/usr/bin:/bin

    The complete code of post-commit is as follows

    #!/bin/sh
    PATH=/usr/bin:/bin
    REPOS="$1"
    REV="$2"
    AUTHOR=$(svnlook author -r $REV $REPOS)
    DATE=$(svnlook date -r $REV $REPOS)

    {
    echo "REPOSITORY: $REPOS"
    echo "REVISION: $REV"
    echo "COMMITTED BY: $AUTHOR"
    echo "DATE: $DATE"

    echo ""
    echo "DESCRIPTION:"
    svnlook log -r $REV $REPOS

    echo ""
    echo "FILES:"
    svnlook changed -r $REV $REPOS

    } | mail -s "[SVN Notify] Check In Rev $REV by $AUTHOR" xxxx@xxxx.com

    ReplyDelete