Skip to content

Commit

Permalink
💚 使用本地 git hook 进行提交前的格式校验
Browse files Browse the repository at this point in the history
  • Loading branch information
Hccake committed Jan 20, 2024
1 parent 42a8c13 commit 825155f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .etc/git-hooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh
source ~/.bash_profile

# 在提交前进行校验
mvn spring-javaformat:validate

# 检查 mvn validate 的退出状态
if [ $? -ne 0 ]; then
echo "Maven validate failed, aborting commit."
exit 1
fi
22 changes: 22 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@
<maven.compiler.target>${java.version}</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<git-build-hook-maven-plugin.version>3.4.1</git-build-hook-maven-plugin.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -319,6 +321,26 @@
</execution>
</executions>
</plugin>
<!-- git hook 配置 -->
<plugin>
<groupId>com.rudikershaw.gitbuildhook</groupId>
<artifactId>git-build-hook-maven-plugin</artifactId>
<version>${git-build-hook-maven-plugin.version}</version>
<configuration>
<gitConfig>
<!-- The location of the directory you are using to store the Git hooks in your project. -->
<core.hooksPath>.etc/git-hooks/</core.hooksPath>
</gitConfig>
</configuration>
<executions>
<execution>
<goals>
<!-- Sets git config specified under configuration > gitConfig. -->
<goal>configure</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<developers>
Expand Down

0 comments on commit 825155f

Please sign in to comment.