installed-hooks
worktree
repo with pre-commit and commit-msg hooks installed and marked executable
Description
Two passing hook scripts are installed in `.git/hooks/`.
- `pre-commit`: runs before every commit; a non-zero exit aborts the
commit. Useful for linters, formatters, or secret-scanners.
- `commit-msg`: receives the path to the commit-message file; used to
enforce message format (e.g. Conventional Commits, ticket prefixes).
Both scripts exit 0 so the repo stays in a clean, committable state. The
scenario documents *presence* and *permissions* of hooks, not enforcement.
Platform notes:
- Hooks are installed after the setup commits so a blocking hook cannot
interrupt the scenario construction itself.
- On Windows (native cmd.exe), git hooks require a POSIX shell such as
Git Bash or WSL. Test hook presence on all platforms; skip invocation
tests on native Windows.
Useful for testing:
- Hook detection ("does this repo have a pre-commit hook?")
- UI indicators showing hooks are active
- Tools that offer to bypass hooks (--no-verify flows)
- Permission checks (hooks must be executable to be invoked by git) Contracts
- main is checked out
- main has 2 commits
- .git/hooks/pre-commit exists and is executable
- .git/hooks/commit-msg exists and is executable
- worktree is clean
Tags
Branches
main Use it
import { spinUpScenario } from '@gfargo/git-scenarios'
const repo = await spinUpScenario('installed-hooks') npx git-scenarios create installed-hooks import { describeWithScenario } from '@gfargo/git-scenarios/jest'
describeWithScenario('installed-hooks', (getRepo) => {
it('should have the expected state', async () => {
const repo = getRepo()
// your assertions here
})
}) Commit graph
* 39669d4 (HEAD -> main) feat: add source
* 7520170 chore: initial