diff --git a/get_started.sh b/get_started.sh new file mode 100755 index 0000000..a13b26c --- /dev/null +++ b/get_started.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +set -eu + +git config --local core.hooksPath scripts/hooks/ +chmod +x scripts/hooks/* diff --git a/scripts/hooks/pre-commit b/scripts/hooks/pre-commit new file mode 100755 index 0000000..913387b --- /dev/null +++ b/scripts/hooks/pre-commit @@ -0,0 +1,26 @@ +#!/bin/sh + +repository_root=$(git rev-parse --show-toplevel) +cd "$repository_root" || exit 1 + +echo "[git pre-commit hook] Running ktlintFormat before commit." + +staged_files=$(git diff --name-only --cached --diff-filter=d) +if [ -z "$staged_files" ]; then + echo "No staged files, skipping formatting." + exit 0 +fi + +./gradlew :ktlintFormat --configuration-cache +status=$? + +echo "Finished ktlintFormat with status: $status" + +if [ "$status" -ne 0 ]; then + echo "Error running ktlintFormat, aborting commit." + exit "$status" +fi + +printf '%s\n' "$staged_files" | while IFS= read -r file; do + git add -- "$file" +done