Skip to content

The hook line hooks install prints has no PATH guard #128

Backlog

Description

@ammartahamohamedy

proofline hooks install gives one of two outputs, and only one of them handles a missing proofline:

  • No hooks path: it writes Hook::script() (src/hooks.rs:79). The script checks command -v proofline first. If proofline is missing, it prints a note and applies onIncomplete; the default warn exits 0.
  • core.hooksPath set (Husky, lefthook, a shared .githooks), or another tool's hook already there: it writes nothing and prints Hook::line() to paste (hooks.rs:155-160, :188-192). That line is a bare proofline hook run pre-commit "$@".

A hooks path is usually committed, so the pasted line runs in every clone, including clones where proofline isn't on PATH. There sh fails with status 127, and Proofline never starts, so onIncomplete can't apply:

  • under sh -e (how Husky runs hooks) or as the last line, Git refuses the commit even under warn;
  • ahead of other commands, the failure is ignored, so onIncomplete=block doesn't block.

Who hits it

  • A developer who has Proofline installed, when an IDE or GUI Git client starts without the shell's PATH (~/.cargo/bin, say). Reinstalling doesn't help.
  • Everyone else who commits in the repo. Husky's prepare script sets core.hooksPath on npm install, so the hook also reaches outside contributors, CI jobs and bots that commit, and devcontainers.

Severity is medium-low. Where a team requires Proofline, command not found does tell people what to install. But script() already treats a missing binary as "not reviewed, apply onIncomplete", and the printed line should do the same.

Reproduce (offline, no sign-in)

git init -q demo && cd demo && git commit -q --allow-empty -m base
git config core.hooksPath .husky
proofline hooks install --pre-commit    # writes nothing, prints the line
mkdir .husky && printf '#!/bin/sh\nproofline hook run pre-commit "$@"\n' > .husky/pre-commit
chmod +x .husky/pre-commit
echo x > f && git add f
PATH=/usr/bin:/bin git commit -m test   # a PATH without proofline
# .husky/pre-commit: line 2: proofline: command not found
# git exits 1 and no commit is created, although onIncomplete is unset (warn)

Proposed fix

Print a guarded snippet built around line(), with the same command -v check and onIncomplete policy as script(). The snippet ends up among other commands in the same file, so it must not exec or exit 0.

Keep line() itself unchanged: open PRs #77 (hooks status) and #99 (doctor) recognize a Proofline hook by contains(&hook.line()), and that check still matches a pasted snippet that contains the line.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions