-
Notifications
You must be signed in to change notification settings - Fork 0
/
pre-commit
30 lines (26 loc) · 1.11 KB
/
pre-commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/bin/sh
# The directory we are monitoring (relative to the root of the repository)
DIR=sql
# String to find in the tags of interest
TAGPATTERN="release-.*"
# Files of interest
FILEPATTERN="seq.*\.sql"
lasttag=$(
git log --decorate=full --simplify-by-decoration --pretty=oneline HEAD | # The log
grep '(' | # Only include entries with names
sed -r -e 's/^[^\(]*\(([^\)]*)\).*$/\1/' -e 's/,/\n/g' -e 's/ //g' | # Select only the names, one line per name, delete spaces
grep "tag:$TAGPATTERN\$" | # Only tags of interest
sed 's/tag://' | # Remove the tag: prefix
head -n 1) # Only take the first one
immutable=$(git ls-tree -r --full-tree --name-only $lasttag | grep "^$DIR/$FILEPATTERN$")
changed=$(git diff --cached --name-only | grep "^$DIR/$FILEPATTERN$")
code=0
for change in $changed
do
if [ "$(echo $immutable | grep $change)" ]
then
echo "Cannot change file $change"
code=1
fi
done
exit $code