I am trying to create a pre-commit hook that will search the file being committed vs a pre determined string and if it contains it then it errors out before the commit.
I have the following after trying to search online:
#!/bin/sh
REPOS="$1"
TXN="$2"
SVNLOOK=/usr/bin/svnlook
$SVNLOOK diff "$REPOS" -t "$TXN" | [[ grep "^+builder_group">/dev/null exit 0 ]] ||
echo "File contains builder_group commit failed" >&2
exit 1
here is the error I get:
svn: E165001: Commit failed (details follow):
svn: E165001: Commit blocked by pre-commit hook (exit code 2) with output:
/etc/svn/testrepo/hooks/pre-commit: line 7: conditional binary operator expected
/etc/svn/testrepo/hooks/pre-commit: line 7: syntax error near `"^+cod_bank">'
/etc/svn/testrepo/hooks/pre-commit: line 7: `$SVNLOOK diff "$REPOS" -t "$TXN" | [[ grep "^+builder_group">/dev/null exit 0 ]] ||'
Can you see why it would be showing the error like it is? Thank you.
Here is what I ended up having to change it to to get it to work.
$SVNLOOK diff -t "$TXN" "$REPOS" | grep -i "builder_group" > /dev/null && { echo "File contains builder_group commit failed." 1>&2; exit 1; }
exit 0;
Based what you have in the field after grep -i "abc123" it will search the file and if it matches or contains the same lettering path it will cause a commit error.
Ex: if the file contains aabc123 it will still error out.