Skip to content

git hooks: post-checkout ignores GRAPHIFY_SKIP_HOOK; post-commit builds a rogue graph in worktrees #1809

Closed

Description

@cdahl86-cyber

Summary

Two small gaps in the generated post-commit / post-checkout git hooks (from graphify hook install):

(a) post-checkout ignores GRAPHIFY_SKIP_HOOK. post-commit early-exits on GRAPHIFY_SKIP_HOOK=1 (hooks.py:269), but the post-checkout template has no such check. So GRAPHIFY_SKIP_HOOK=1 suppresses commit-triggered rebuilds but not branch-switch rebuilds — surprising when scripting around the hooks (e.g. batch branch switches, or tooling that sets the var).

(b) post-commit builds a rogue graph inside worktrees. With core.hooksPath shared across git worktrees, a commit in any worktree fires these hooks. post-checkout guards on [ -d graphify-out ] and exits when it's absent, but post-commit has no such guard — so in a worktree with no local graphify-out/, it runs graphify update with cwd=worktree and writes a fresh delta-only graph.json into that worktree, which the user never asked for.

Version

graphifyy 0.9.12

Suggested fix

In the hook templates (hooks.py):

  • Add to the post-checkout template: [ "${GRAPHIFY_SKIP_HOOK:-0}" = "1" ] && exit 0
  • Add to the post-commit template: [ -d "graphify-out" ] || exit 0 (matching post-checkout)

Editing the generated .git/hooks/* directly works, but is regenerated on reinstall/upgrade, so the fix belongs in the templates.

Activity

  1. safishamsi commented on Jul 12, 2026

    @safishamsi
    Member

    Fixed in 5f57c46 (ships in 0.9.14). Both gaps addressed in the hook templates: (a) post-checkout now honors GRAPHIFY_SKIP_HOOK like post-commit; (b) both hooks short-circuit inside a linked worktree. For (b) I went with a worktree check (git-dir != git-common-dir) rather than the [ -d graphify-out ] guard you suggested — it targets the actual condition (a linked worktree) instead of the proxy (missing output dir), so it also skips the wasteful rebuild in a worktree that happens to have its own graphify-out/. The compare resolves both paths to absolute so the primary checkout isn't false-positived. Verified end-to-end against a real git worktree. Thanks @cdahl86-cyber.

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