Skip to main content

init

Function init 

Source
pub fn init() -> Result<(), String>
Expand description

amont init — wire up THIS repository, and touch nothing else.

The verb a package manager can call. "prepare": "amont init" in a package.json means a teammate who clones and runs npm install gets the hooks, which is the ergonomic husky has and this project did not.

§Why install could not be that verb

Every one of its three extra steps is wrong for something that runs on every teammate’s install, and the third is a hang:

  • install_binary copies into ~/.local/bin — a machine-level write from npm install;
  • populate_template_dir writes ~/.config/git/git-templates, so a package manager would be arranging for every FUTURE clone to get hooks;
  • offer_trust calls trust::confirm, which opens /dev/tty. In a terminal that succeeds and BLOCKS, so npm install would stop dead on a prompt about a manifest the user has not read.

So this does one thing: bake four shims into the repository’s own hooks directory.

§What it bakes, and why not the PATH hit

current_exe(), always — never [install_binary]’s “is it already on PATH?” branch. Under npm the answer to that question is node_modules/.bin/amont, which is the JS wrapper: baking it would put a node process in front of every single commit, on a tool whose start-up cost is a stated feature. current_exe() is the native binary inside the platform package, which is what should run.

§Silence, and its limits

Outside a git repository this reports nothing and exits 0. npm install legitimately runs where there is no .git — from a tarball, inside a Docker build, in CI — and failing there would make the package uninstallable in all three. It stays LOUD about everything else: a redirect, an unwritable directory, a foreign hook, and a repository git REFUSES to answer about (dubious ownership in a container bind mount, an unreadable .git/config) all still fail, because those are repositories where somebody believes they have hooks and does not. The silence is git’s verdict, never git’s absence.

§Inside a push snapshot, it stands down

A push snapshot is a linked worktree, so it SHARES this repository’s hooks directory — and its dependency install runs prepare, which runs this. Baking there pointed every hook at a binary inside a temp directory that is deleted minutes later. The snapshot marks itself in its own git admin dir (crate::pushed_tree::in_push_snapshot); when the mark is there, nothing is written. When it cannot be TOLD whether the mark is there, it fails rather than guess: a wrong guess is exactly the bake this prevents.