Creating a pre commit script that will only allow commits that contain a specific string somewhere in the file Test.cfg
Currently I have it working in that it will look through every file committed and blocks commits that contain a specified string
REPOS="$1"
TXN="$2"
SVNLOOK=/usr/bin/svnlook
$SVNLOOK diff -t "$TXN" "$REPOS" | \
grep -i "Sting to search here" > /dev/null && { echo "String exists so block commit" 1>&2; exit 1; }
What I am after is for the above code to pretty do the complete opposite so that if the string exists allow the commit and if not then prevent the commit. It would also be nice if I could specify which file should be searched as currently it searches every file and some of the commits can contain 1000's of files
I beg your pardon, but svnlook diff
in your case is ugly stupid way. Re-read svnlook subcommands topic in SVNBook, pay attention to svnlook tree
/svnlook changed
+ svnlook cat
Full business-logic of your test can|have to be something like (I'm too lazy to write full bashism here, it will be your duty)
IF $FILENAME
exist in transaction ( I'll prefer svnlook tree --full-paths ...
just because svnlook changed ...
will require additional | gawk {print $2}
for clean filename) AND $FILENAME
contains $STRING
(svnlook cat "$FILENAME" | grep "STRING" ...
) DO SOMETHING
Don't forget also process possible edge cases:
Due to above notes, I'll recommend to explore|check possibility of replacing file+string by testing custom revision's property in hook (shorter, easier, more manageable)