diff --git a/Readme.adoc b/Readme.adoc index 4a81cd0..5cd33be 100644 --- a/Readme.adoc +++ b/Readme.adoc @@ -265,6 +265,15 @@ $ lproj list --mine == Development +First, activate the repo's git hooks (enforces conventional-commit subjects +before you even push): + +[source,sh] +---- +$ cd app +$ mise exec -- mix githooks.install +---- + The project uses ExUnit and `mix format`. Run tests with: [source,sh] diff --git a/app/lib/mix/tasks/githooks.install.ex b/app/lib/mix/tasks/githooks.install.ex new file mode 100644 index 0000000..463617f --- /dev/null +++ b/app/lib/mix/tasks/githooks.install.ex @@ -0,0 +1,21 @@ +defmodule Mix.Tasks.Githooks.Install do + @moduledoc "Activates this repo's githooks/ (conventional-commit enforcement on commit-msg)." + @shortdoc "Activates the repo's git hooks" + + use Mix.Task + + @impl Mix.Task + def run(_args) do + with {root, 0} <- System.cmd("git", ["rev-parse", "--show-toplevel"], stderr_to_stdout: true), + root = String.trim(root), + {_output, 0} <- + System.cmd("git", ["config", "core.hooksPath", "githooks"], + cd: root, + stderr_to_stdout: true + ) do + Mix.shell().info("githooks activated (core.hooksPath = githooks)") + else + {output, _status} -> Mix.raise("Failed to activate githooks: #{String.trim(output)}") + end + end +end