From dbabdf39d079246efed3a61e402e0d846ccae1a0 Mon Sep 17 00:00:00 2001 From: Viktor Barzin Date: Sat, 14 Feb 2026 11:36:26 +0000 Subject: [PATCH] Add shared pre-push hook to run tests before pushing Hook lives in .githooks/pre-push (tracked) and runs pytest inside the Docker app container. start.sh auto-configures core.hooksPath so new clones pick it up on first run. --- .githooks/pre-push | 27 +++++++++++++++++++++++++++ start.sh | 5 +++++ 2 files changed, 32 insertions(+) create mode 100755 .githooks/pre-push diff --git a/.githooks/pre-push b/.githooks/pre-push new file mode 100755 index 0000000..5c26668 --- /dev/null +++ b/.githooks/pre-push @@ -0,0 +1,27 @@ +#!/bin/sh +# +# pre-push hook: runs the test suite before allowing a push. +# If tests fail, the push is aborted. +# + +echo "Running tests before push..." + +# Check if the app container is running +if ! docker compose ps --status running 2>/dev/null | grep -q rec-app; then + echo "ERROR: rec-app container is not running." + echo "Start it with: docker compose up -d" + echo "Skipping tests — push blocked." + exit 1 +fi + +docker compose exec -T app pytest tests/ -v --tb=short +status=$? + +if [ $status -ne 0 ]; then + echo "" + echo "Tests failed — push aborted." + echo "Fix the failures and try again, or push with --no-verify to skip." + exit 1 +fi + +exit 0 diff --git a/start.sh b/start.sh index 3e7d8a0..d1f0ff0 100755 --- a/start.sh +++ b/start.sh @@ -60,6 +60,11 @@ start_docker() { build_flag="--build" fi + # Ensure git hooks are configured (idempotent) + if git rev-parse --git-dir &>/dev/null; then + git config core.hooksPath .githooks + fi + echo "Starting all services with Docker Compose..." echo ""