Skip to main content

guard_write

Function guard_write 

Source
pub fn guard_write(path: &Path, force: bool) -> Result<HookFile, Refuse>
Expand description

May we write a hook at path, and what is there now?

force is the user saying “I looked at it”. It relaxes exactly two refusals — a foreign file, and a symlink — and it relaxes them into REPLACING THE LINK, never into writing through it (see the module doc).

force does NOT relax the tracked guard, and this is the one rule in the module with no exception. --force is a statement about .git/hooks, which is machine-local scratch space; it is not consent to rewrite a file in the working tree that git is watching. The user who typed it was thinking about a hook they wrote last month, not about devhooks/pre-commit being on the other end of a link they forgot they made. Nor does it relax TrackedUnknown: an override that fires when we could not even ask the question is an override of the guard rather than of the finding.

The tracked check runs FIRST so its refusal survives everything else — a tracked symlink refuses as Tracked, not as a forceable Symlink.