Skip to content

Hooks ignore core.hooksPath and do not run in linked worktrees #12

Closed

Description

@dnnsjsk

Hooks run by Repository are always looked up in <gitDir>/hooks/<name> (

private function hookPath(string $hookName): string
{
return $this->gitDir . '/hooks/' . $hookName;
}
), with gitDir being the per-worktree directory (https://github.com/inline0/pitmaster/blob/5beb97da195f57f4e9ea06bfc68ac71144bfefba/src/Repository.php#L5391,
return (new HookRunner($this->gitDir))->runAndCheck($hookName, $args, $stdin);
). Two consequences:

  1. In a linked worktree gitDir is .git/worktrees/<name>, so the shared .git/hooks scripts never run there. git runs the common hooks in every worktree.
  2. core.hooksPath is not read anywhere in src/, so repositories that keep their hooks elsewhere (a common setup with tools that manage hooks) run none of them through Pitmaster.

Repro

$repo = Pitmaster::open('/repo');                 // has an executable .git/hooks/pre-commit that exits 1
$wt = $repo->addWorktree('/tmp/wt', 'feature');
$linked = Pitmaster::open('/tmp/wt');
// change and add a file in /tmp/wt
$linked->commit('msg');                          // succeeds; the pre-commit hook did not run

Expected

Hooks resolve to core.hooksPath when set, otherwise to the common directory's hooks/, as in git.

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