6.3 just hook

Build it yourself. Read the tutorial 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

This part does not start where the part before it ends, because the walk skips some changes. This command puts the files that this part starts from in place of yours. Run it, and then go on:

git fetch --quiet --tags --force origin; git restore --source step-05 --staged -- :/ && git restore --source 009d77653ead --staged --worktree -- :/

If you start at this part, make your clone as Get the project says, and then run this command. It puts in your clone the files that this part starts from. A file that the project deleted before this part stays, so delete it if git check lists it:

git rm -rq --cached --ignore-unmatch -- :/ && git restore --source 009d77653ead --staged --worktree -- :/
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.

Apply the patch to justfile, from the top of the project:

curl -fsSL https://github.com/rahuldave/cheesecracker/commit/57ec2e24ecd4946823edbfad27bc2296f80e3847.diff | git apply --include=justfile

Read the recipe hook, after the recipe setup.

just hook

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

Check your files against this move. The command prints nothing when they match, and otherwise shows what differs:

git check 57ec2e24ecd4

If you are stuck, this command puts the files of this move in place of yours. A file that you made yourself stays:

git fetch --quiet --tags --force origin; git restore --source 009d77653ead --staged -- :/ && git restore --source step-06 --staged --worktree -- :/

What changed

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

The patch to 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