6.3 just hook

Read the tutorial. Build it yourself is the other way to read this part.

This walk goes through rahuldave/cheesecracker on GitHub. This part starts from the code at 009d77653ead, partway through step-06. The code before this part

To look at this code on your machine, run these commands. The first one makes a clone, if this folder has none:

[ -d cheesecracker ] || git clone https://github.com/rahuldave/cheesecracker
cd cheesecracker
git fetch --quiet --tags --force origin
git switch --detach 009d77653ead
just setup

The whole tutorial then adds pre-commit, a tool that runs checks before every commit. git runs them through a hook, a file in git's own folder. just setup installs only Python and the packages, so the hook gets a recipe of its own.

6.3 just hook installs the checks as a git hook

pre-commit runs before every commit only after it installs a hook in .git/hooks/. just setup never changes git, so the hook has a recipe of its own, hook. You run it once in each clone.

± See the change to justfile

The recipe hook, after the recipe setup, runs uv run pre-commit install.

just hook

pre-commit prints pre-commit installed at .git/hooks/pre-commit. From now on, git commit runs the checks first.

What changed

  • justfile: the recipe hook. 4 lines added. The file
    • look at uv run pre-commit install

The diff of justfile
@@ -11,6 +11,10 @@ default:
 setup:
     uv sync --locked
 
+# Install the git hook: the checks of .pre-commit-config.yaml before every commit. Once per clone
+hook:
+    uv run pre-commit install
+
 # Run the tests. Extra arguments go to pytest: just test tests/unit
 test *args:
     uv run pytest "$@"

This change on GitHub

This part ends at the code at step-06. The code after this part