Skip to content

Commit b6e2856

Browse files
authored
CHAD-4486 Commit hooks (#23444)
* CHAD-4486 Improve DTH commit process * set pre-commit script as executable * compile error handling * finalize commit hooks * cleanup of commit hook adds an "unconfigure" task if you want to undo
1 parent 78188c3 commit b6e2856

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

.githooks/pre-commit

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
3+
ERROR_COUNT=0
4+
while IFS= read -r DTH; do
5+
echo "Verifying $DTH"
6+
ERRORS=$(groovyc $DTH 2>&1 | grep ".groovy:")
7+
# echo $ERRORS
8+
IMPORTANT_ERRORS=$(echo $ERRORS | grep -v "unable")
9+
if [[ ${#IMPORTANT_ERRORS} -eq 0 ]]; then
10+
echo "No disqualifying compilation errors found"
11+
else
12+
echo "$DTH failed to compile, run groovyc on your source file for the full error: $ERRORS"
13+
ERROR_COUNT=$((ERROR_COUNT + 1))
14+
fi
15+
echo "======================================================================="
16+
done < <(git diff --cached --name-only | grep .*.groovy)
17+
18+
if [[ $ERROR_COUNT -gt 0 ]]; then
19+
echo "rejected" && exit 1
20+
else
21+
exit 0
22+
fi

build.gradle

+14
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,17 @@ slackSendMessage {
138138
text: messageText
139139
)
140140
}
141+
142+
task configure(type: Exec) {
143+
description "Configures automatic spaces->tabs conversion on merge and a commit hook to detect syntax errors"
144+
File attributeFile = new File("${projectDir}/.git/info/attributes")
145+
attributeFile.write("*.groovy filter=tabspace\n")
146+
commandLine "git", "config", "filter.tabspace.clean", "unexpand -t 2"
147+
commandLine "git", "config", "core.hooksPath", ".githooks"
148+
}
149+
150+
task unconfigure(type: Exec) {
151+
description "Undoes configuration put in place by configure"
152+
commandLine "git", "config", "--unset-all", "filter.tabspace.clean"
153+
commandLine "git", "config", "core.hooksPath", "${projectDir}/.git/hooks"
154+
}

0 commit comments

Comments
 (0)