From b0c1b4294c5dd5deb04c701d8804d6f1cc03d90d Mon Sep 17 00:00:00 2001 From: Hossain Khan Date: Mon, 16 Jun 2025 13:32:29 -0400 Subject: [PATCH 1/3] [ADDED] Git pre commit hook added --- .githooks/README.md | 26 ++++++++++++++++++++++++++ .githooks/pre-commit | 23 +++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 .githooks/README.md create mode 100755 .githooks/pre-commit diff --git a/.githooks/README.md b/.githooks/README.md new file mode 100644 index 0000000..ca40a4e --- /dev/null +++ b/.githooks/README.md @@ -0,0 +1,26 @@ +# Git Hooks + +This project uses Git hooks to maintain code quality. + +## Setup for new developers + +After cloning the repository, run: + +```bash +git config core.hooksPath .githooks +``` + +This will configure Git to use the hooks in the `.githooks` directory. + +## Available hooks + +### Pre-commit + +Automatically runs `./gradlew formatKotlin` before each commit and prevents commits if: +- The code fails to pass formatting checks +- The formatter modifies files that aren't included in the commit + +If your commit is rejected due to formatting issues: +1. Review the error messages +2. Add the formatted files to your commit with `git add` +3. Try committing again diff --git a/.githooks/pre-commit b/.githooks/pre-commit new file mode 100755 index 0000000..6ddd2b1 --- /dev/null +++ b/.githooks/pre-commit @@ -0,0 +1,23 @@ +#!/bin/bash + +echo "Running Kotlin formatter check..." + +# Execute the Kotlin formatting task +./gradlew formatKotlin --daemon + +# Check the exit code of the format command +status=$? +if [ $status -ne 0 ]; then + echo "❌ formatKotlin failed! Please fix formatting issues before committing." + exit 1 +fi + +# Check if there are unstaged changes after formatting +if [[ -n $(git status -s | grep "^.M") ]]; then + echo "❌ Files were modified by formatKotlin. Please add these changes to your commit." + git status -s | grep "^.M" + exit 1 +fi + +echo "✅ Kotlin code formatting check passed!" +exit 0 From f5d5a02beee66d592f14073454da0c769956813e Mon Sep 17 00:00:00 2001 From: Hossain Khan Date: Mon, 16 Jun 2025 13:35:38 -0400 Subject: [PATCH 2/3] Update .githooks/pre-commit Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .githooks/pre-commit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.githooks/pre-commit b/.githooks/pre-commit index 6ddd2b1..88e5483 100755 --- a/.githooks/pre-commit +++ b/.githooks/pre-commit @@ -3,7 +3,7 @@ echo "Running Kotlin formatter check..." # Execute the Kotlin formatting task -./gradlew formatKotlin --daemon +./gradlew formatKotlin --quiet # Check the exit code of the format command status=$? From 1585caf287a9ce22dcb6f2265a4380c93df0eb28 Mon Sep 17 00:00:00 2001 From: Hossain Khan Date: Mon, 16 Jun 2025 13:36:36 -0400 Subject: [PATCH 3/3] Update .githooks/pre-commit Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .githooks/pre-commit | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.githooks/pre-commit b/.githooks/pre-commit index 88e5483..85fb633 100755 --- a/.githooks/pre-commit +++ b/.githooks/pre-commit @@ -13,9 +13,9 @@ if [ $status -ne 0 ]; then fi # Check if there are unstaged changes after formatting -if [[ -n $(git status -s | grep "^.M") ]]; then +if [[ -n $(git diff --name-only --diff-filter=M) ]]; then echo "❌ Files were modified by formatKotlin. Please add these changes to your commit." - git status -s | grep "^.M" + git diff --name-only --diff-filter=M exit 1 fi