Skip to content

Instantly share code, notes, and snippets.

@dpwright
Created May 30, 2012 05:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dpwright/2833953 to your computer and use it in GitHub Desktop.
Save dpwright/2833953 to your computer and use it in GitHub Desktop.
SVN post-commit hook to send emails to file owners
#!/usr/bin/env bash
LOOK=/usr/bin/svnlook
REPOS="$1"
REV="$2"
PROJECT="$3"
AUTHOR=$($LOOK author $REPOS -r $REV)
DOMAIN=domain.com
OWNERS=""
for FILE in $($LOOK changed $REPOS -r $REV | awk '{ print $2 }')
do
OWNER_LOG=$(svn log "file://$REPOS/$FILE" 2> /dev/null | grep "^r[0-9]* | " | awk '{ print $3 }' | sort | uniq -c | sort | tail -n 1 | awk '{ print $2 }')
if [[ "$OWNER_LOG" != "$AUTHOR" && "$OWNERS" != *" $OWNER_LOG "* ]]
then
OWNERS="$OWNERS $OWNER_LOG "
fi
OWNER_BLAME=$(svn blame -x "-w --ignore-eol-style" "file://$REPOS/$FILE" 2> /dev/null | awk '{ print $2 }' | sort | uniq -c | sort | tail -n 1 | awk '{ print $2 }')
if [[ "$OWNER_BLAME" != "" && "$OWNER_BLAME" != "$AUTHOR" && "$OWNERS" != *" $OWNER_BLAME "* ]]
then
OWNERS="$OWNERS $OWNER_BLAME "
fi
done
if [[ "$OWNERS" != "" ]]
then
RECIPIENTS=$(for PERSON in $OWNERS; do echo -n "--to $PERSON@$DOMAIN ";
done)
/usr/local/bin/svnnotify \\
--repos-path "$REPOS" \\
--revision "$REV" \\
--subject-prefix "[$PROJECT-svn]" \\
--attach-diff \\
--diff-switches '-x "-w --ignore-eol-style"' \\
--user-domain $DOMAIN \\
$RECIPIENTS
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment