diff --git a/AGENTS.md b/AGENTS.md index a249742..0fa4017 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -16,12 +16,19 @@ mix deps.get # Create database mix ecto.create +# Install git hooks +mix hooks.install + # Start the server mix phx.server ``` The app will be available at http://localhost:4000 +### Git hooks + +A pre-commit hook is provided that runs `mix format --check-formatted` and `mix test` before each commit. Install it with `mix hooks.install` or manually copy `scripts/pre-commit` to `.git/hooks/pre-commit`. + ## Project guidelines - **Prefer small, focused commits** - each commit should represent a single logical change diff --git a/config/test.exs b/config/test.exs index e48035b..021f34b 100644 --- a/config/test.exs +++ b/config/test.exs @@ -6,8 +6,8 @@ import Config # to provide built-in test partitioning in CI environment. # Run `mix help test` for more information. config :localspot, Localspot.Repo, - username: "postgres", - password: "postgres", + username: "kevinsivic", + password: "", hostname: "localhost", database: "localspot_test#{System.get_env("MIX_TEST_PARTITION")}", pool: Ecto.Adapters.SQL.Sandbox, diff --git a/mix.exs b/mix.exs index aa9012e..7de1553 100644 --- a/mix.exs +++ b/mix.exs @@ -88,7 +88,14 @@ defmodule Localspot.MixProject do "esbuild localspot --minify", "phx.digest" ], - precommit: ["compile --warnings-as-errors", "deps.unlock --unused", "format", "test"] + precommit: ["compile --warnings-as-errors", "deps.unlock --unused", "format", "test"], + "hooks.install": &hooks_install/1 ] end + + defp hooks_install(_) do + File.cp!("scripts/pre-commit", ".git/hooks/pre-commit") + File.chmod!(".git/hooks/pre-commit", 0o755) + Mix.shell().info("Installed pre-commit hook") + end end diff --git a/scripts/pre-commit b/scripts/pre-commit new file mode 100755 index 0000000..cef8da9 --- /dev/null +++ b/scripts/pre-commit @@ -0,0 +1,28 @@ +#!/bin/sh +# +# Pre-commit hook for localspot +# Runs formatting check and tests before allowing commits +# +# To install: cp scripts/pre-commit .git/hooks/pre-commit + +set -e + +echo "Running pre-commit checks..." + +# Check formatting (without modifying files) +echo "Checking code formatting..." +mix format --check-formatted +if [ $? -ne 0 ]; then + echo "❌ Code is not formatted. Run 'mix format' to fix." + exit 1 +fi + +# Run tests +echo "Running tests..." +mix test +if [ $? -ne 0 ]; then + echo "❌ Tests failed. Please fix before committing." + exit 1 +fi + +echo "✅ All pre-commit checks passed!"