@@ -676,32 +676,51 @@ After committing and pushing this file, GitHub will automatically run your tests
676676
677677You can add a **pre-commit Git hook** that runs your unit tests before any commit is finalized.
678678
679- #### 🛠 Setup Instructions (PowerShell for Windows )
679+ #### 🛠 Setup Pre-commit Hook (Manual — Recommended )
680680
681- ` ` ` powershell
682- # 1. Navigate to your repo root
683- cd path\to\your\repo # Replace with your actual repo path
684681
685- //if you are on virtual machine :
686- cd C:\Users\User.Name(replace with your username)\Source\Repos\gordon-cs\gordon-360-api>
682+ 1️⃣ Navigate to your repo root
683+ ` ` ` bash
684+
685+ cd path/to/your/repo
686+
687+ Example (on Windows Virtual Machine) :
688+
689+ C:\Users\Your__UserName\Source\Repos\gordon-cs\gordon-360-api
690+ ```
691+
692+ 2️⃣ Open .git/hooks/pre-commit
693+
694+ If the file does not exist, create a new file named pre-commit in .git/hooks/.
695+
687696
688- # 2. Create the pre-commit hook file
689- New-Item -ItemType File -Path .git/hooks/pre-commit
690697
691- # 3. Add script to run tests before each commit
692- @"
698+ 3️⃣ Copy and paste the following script into pre-commit file:
699+ ``` bash
700+
693701#! /bin/sh
694- echo "Running unit tests before commit..."
702+ echo " Running build before commit..."
703+
704+ dotnet build --no-restore --verbosity quiet
705+ BUILD_EXIT_CODE=$?
706+
707+ if [ $BUILD_EXIT_CODE -ne 0 ]; then
708+ echo " Build failed. Commit aborted."
709+ exit 1
710+ fi
695711
696- dotnet test --no-build --verbosity quiet
712+ echo " Running tests before commit... "
697713
698- if [ $? -ne 0 ]; then
699- echo "Unit tests failed. Commit aborted."
714+ dotnet test gordon360.Tests/gordon360.Tests.csproj --no-build --verbosity quiet
715+ TEST_EXIT_CODE=$?
716+
717+ if [ $TEST_EXIT_CODE -ne 0 ]; then
718+ echo " Tests failed. Commit aborted."
700719 exit 1
701720else
702- echo "All tests passed. Proceeding with commit."
721+ echo " Build and tests passed. Proceeding with commit."
703722fi
704- " @ | Set-Content .git/hooks/pre-commit
723+
705724```
706725
707726> ⚠️ This only runs locally on your machine. Others won't get it unless shared via tools like Husky.
0 commit comments