Skip to content

Commit be9c323

Browse files
authored
<perf>(style): add pre-commit hook before git commit. (#846)
1 parent fc2b3fb commit be9c323

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

build.gradle

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,13 @@ javadoc {
176176
options.addStringOption('charSet', 'UTF-8')
177177
}
178178

179+
task copyHooks(type: Copy) {
180+
from("hooks") {
181+
include "**"
182+
}
183+
into ".git/hooks"
184+
}
185+
179186
task sourcesJar(type: Jar) {
180187
from sourceSets.main.allJava
181188
archiveClassifier = 'sources'
@@ -304,3 +311,4 @@ jar {
304311
}
305312
}
306313
check.dependsOn jacocoTestReport
314+
verifyGoogleJavaFormat.dependsOn(copyHooks)

hooks/pre-commit

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/sh
2+
#
3+
# An example hook script to verify what is about to be committed.
4+
# Called by "git commit" with no arguments. The hook should
5+
# exit with non-zero status after issuing an appropriate message if
6+
# it wants to stop the commit.
7+
#
8+
# To enable this hook, rename this file to "pre-commit".
9+
10+
bash gradlew verifyGoogleJavaFormat
11+
result=$?
12+
printf "the verifyGoogleJavaFormat result code is $result"
13+
if [[ "$result" = 0 ]] ; then
14+
echo "\033[32m
15+
....
16+
....
17+
verifyGoogleJavaFormat Pass!!
18+
....
19+
....
20+
\033[0m"
21+
exit 0
22+
else
23+
bash gradlew goJF
24+
echo "\033[31m
25+
....
26+
....
27+
verifyGoogleJavaFormat Failed!!
28+
Code format has been automatically adjusted, please review the code and then git add. && git commit;
29+
....
30+
....
31+
\033[0m"
32+
exit 1
33+
fi

0 commit comments

Comments
 (0)