Skip to content

Commit

Permalink
Merge pull request #5 from GDSC-Hongik/feature/pre-commit
Browse files Browse the repository at this point in the history
spotless pre-commit 설정
  • Loading branch information
cmj7271 authored Jan 14, 2025
2 parents 71769dd + 18ce8a0 commit 7ef84f1
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
16 changes: 16 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,19 @@ spotless {
endWithNewline()
}
}

tasks.register("updateGitHooks", Copy) {
from "./scripts/pre-commit"
into ".git/hooks"
onlyIf {
System.getenv("NO_GIT_HOOKS") == "true"
}
}
tasks.register("executableGitHooks", Exec) {
commandLine "chmod", "ug+x", ".git/hooks/pre-commit"
dependsOn(updateGitHooks)
onlyIf {
System.getenv("NO_GIT_HOOKS") == "true"
}
}
compileJava.dependsOn(executableGitHooks)
2 changes: 2 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ services:
env_file:
- ./env/server.env
- ./env/db.env
environment:
- NO_GIT_HOOKS="true"
platform: linux/arm64
build:
context: .
Expand Down
16 changes: 16 additions & 0 deletions scripts/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/sh

# 변경된 파일들 이름만 추출하여 저장
stagedFiles=$(git diff --staged --name-only)

# SpotlessApply 실행
echo "Running spotlessApply. Formatting code..."

./gradlew spotlessApply

# 변경사항이 발생한 파일들 다시 git add
for file in $stagedFiles; do
if test -f "$file"; then
git add "$file"
fi
done

0 comments on commit 7ef84f1

Please sign in to comment.