diff --git a/build.gradle b/build.gradle index 665704e..f16a19e 100644 --- a/build.gradle +++ b/build.gradle @@ -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) \ No newline at end of file diff --git a/compose.yaml b/compose.yaml index 2e1d21e..fd195a5 100644 --- a/compose.yaml +++ b/compose.yaml @@ -3,6 +3,8 @@ services: env_file: - ./env/server.env - ./env/db.env + environment: + - NO_GIT_HOOKS="true" platform: linux/arm64 build: context: . diff --git a/scripts/pre-commit b/scripts/pre-commit new file mode 100644 index 0000000..d78dcb7 --- /dev/null +++ b/scripts/pre-commit @@ -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 \ No newline at end of file