Skip to content

Instantly share code, notes, and snippets.

@vbfox
Created November 10, 2010 16:56
Show Gist options
  • Save vbfox/671122 to your computer and use it in GitHub Desktop.
Save vbfox/671122 to your computer and use it in GitHub Desktop.
Pre-Commit hook for svn checking that no .cs file is committed as a binary file.
#!/bin/bash
function script {
local repo="$1"
echo "repo=$repo"
local txn="$2"
echo "txn=$txn"
local selector="-t $txn"
echo "Changed:"
echo "--------------------"
svnlook changed $selector "$repo"
echo "--------------------"
while read line
do
local ext=`echo "$line"|sed -r -e 's/^.+\.(.+)$/\1/'`
if [ "cs" == "$ext" ]
then
local mimetype=`svnlook propget $selector "$repo" svn:mime-type "$line" 2>/dev/null`
if [ "application/octet-stream" == "$mimetype" ]
then
echo "Binary .cs file : $line" >&2
exit 1
fi
fi
done < <(svnlook changed $selector "$repo" | egrep '^(.U|A )' | sed -e 's/^..\s*//')
exit 0
}
script "$1" "$2"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment