Skip to content

post-commit hook: every exit 0 in the generated block terminates the whole hook — silently kills anything appended after it (incl. repo-local hook chaining) on root commits, rebases and worktrees #2986

Closed

Description

@sam-fakhreddine

Summary

The generated post-commit hook is a flat sh script whose skip conditions use bare exit 0. In a flat script that terminates the entire hook process, not just graphify's section. Any block appended after graphify's markers — including hook-chaining logic that other tools install — is silently skipped whenever graphify decides to skip itself.

This is not an edge case: one of those exits fires on every root commit of every repository.

Affected

Confirmed by reading graphify/hooks.py in the published wheels for 0.9.45 (16 exit 0) and 0.9.48 (17). Installed and observed with 0.9.39 and 0.9.45. The count went up rather than down between those releases, so this looks unnoticed rather than known.

Mechanism

hooks.py emits, among others:

[ -d "$GIT_DIR/rebase-merge" ] && exit 0
[ -d "$GIT_DIR/rebase-apply" ] && exit 0
[ -f "$GIT_DIR/MERGE_HEAD" ] && exit 0
[ -f "$GIT_DIR/CHERRY_PICK_HEAD" ] && exit 0
[ "${GRAPHIFY_SKIP_HOOK:-0}" = "1" ] && exit 0

CHANGED=$(git diff --name-only HEAD~1 HEAD 2>/dev/null || git diff --name-only HEAD 2>/dev/null)
if [ -z "$CHANGED" ]; then
    exit 0
fi

_NON_GRAPH=$(echo "$CHANGED" | grep -v '^graphify-out/' || true)
if [ -z "$_NON_GRAPH" ]; then
    exit 0
fi

Each is correct as an intent ("graphify should not run here") but wrong as a mechanism in a shared hook file, because it ends the process.

The root-commit case is the most surprising one. On a repository's first commit HEAD~1 does not resolve, so the fallback git diff --name-only HEAD compares the working tree against HEAD — clean immediately after a commit — yielding an empty CHANGED and an exit 0.

Reproduction

# global hook: graphify's block, followed by anything else
printf '#!/bin/sh\n' > ~/.config/git/hooks/post-commit
graphify hook install                      # appends the graphify block
printf 'printf "[after-graphify RAN]\\n"\n' >> ~/.config/git/hooks/post-commit

mkdir repro && cd repro && git init -q
printf 'x\n' > f.txt && git add -A
git commit -m "root"        # -> "[after-graphify RAN]" does NOT print

printf 'y\n' >> f.txt && git add -A
git commit -m "second"      # -> it prints

The same asymmetry appears during rebase, cherry-pick, in linked worktrees, with GRAPHIFY_SKIP_HOOK=1, and on commits touching only graphify-out/.

Impact

hooks.py contains no chaining logic of its own, so it implicitly assumes it owns the hook file or runs last. In practice it is commonly appended alongside other tools' blocks. Where another tool's block chains to repository-local hooks, those repo-local post-commit hooks silently stop running in all the situations above — no error, no output, just nothing.

Suggested fix

Wrap the emitted block in a subshell so the skip conditions become local:

(
  ... existing generated block ...
) || true

exit 0 then leaves the subshell, graphify skips itself exactly as intended, and the hook continues. Verified locally against 0.9.45: root commits, graphify-out/-only commits, and normal code commits all now continue past the block, while graphify's own rebuild behaviour is unchanged (GRAPH_REPORT.md still produced on code commits).

An alternative that avoids the subshell is replacing each exit 0 with a guard variable checked before the rebuild step, but the subshell wrap is a one-line change and cannot miss an exit path.

Happy to open a PR if the subshell approach looks right.

Activity

  1. safishamsi commented on Sep 7, 2026

    @safishamsi
    Member
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