diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 1e3df2f2..78ab3ebc 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -33,6 +33,9 @@ Follow these steps to set up your development environment and gain access to all * Install web frontend dependencies: `make install` * *(Mobile app dependencies will be installed within their respective directories later.)* +- **Install Git Hooks:** + - Run `make install-git-hooks` to set up local safeguards that prevent direct pushes to protected branches (`main` and `dev`). **This is a mandatory step.** + 7. **Firebase Project Access Validation (CTO will provide access):** * Confirm you have access to the `dev` Firebase/GCP project. * Verify you can run `firebase login` and `gcloud auth login` successfully. diff --git a/Makefile b/Makefile index ea88f475..2c7f1231 100644 --- a/Makefile +++ b/Makefile @@ -74,3 +74,9 @@ create-issues-from-file: @echo "--> Creating GitHub issues from file..." @./scripts/create_issues.py +# --- Development Tools --- +install-git-hooks: + @echo "--> Installing Git hooks..." + @ln -sf ../../scripts/git-hooks/pre-push .git/hooks/pre-push + @echo "✅ pre-push hook installed successfully. Direct pushes to 'main' and 'dev' are now blocked." + diff --git a/scripts/git-hooks/pre-push b/scripts/git-hooks/pre-push new file mode 100755 index 00000000..421e47f0 --- /dev/null +++ b/scripts/git-hooks/pre-push @@ -0,0 +1,21 @@ +#!/bin/sh + +# --- Protected Branches --- +PROTECTED_BRANCHES="^(main|dev)$" + +# Read stdin to get push details +while read local_ref local_sha remote_ref remote_sha; do + # Extract the branch name from the remote ref (e.g., refs/heads/branch-name) + branch_name=$(echo "$remote_ref" | sed 's!refs/heads/!!') + + # Check if the pushed branch matches our protected branches + if echo "$branch_name" | grep -qE "$PROTECTED_BRANCHES"; then + echo "----------------------------------------------------------------" + echo "❌ ERROR: Direct pushes to the '$branch_name' branch are forbidden." + echo "Please use a pull request to merge your changes." + echo "----------------------------------------------------------------" + exit 1 # Abort the push + fi +done + +exit 0 # Allow the push