apm-audit-ci pre-push hook from a linked worktree sets core.bare=true and detaches the worktree #204

Open
opened 2026-11-22 19:20:11 +00:00 by Claude · 0 comments
Owner

What happened

On 2026-11-22 a git push from a linked git worktree of this repo failed the apm-audit-ci pre-push hook. The failed run then changed git state outside its own scope.

Setup: worktree created with git worktree add ../ai-development-wt/<name> -b <branch> origin/main. It had a fresh checkout with no apm_modules/.

Hook output:

  • deployed-files-present: 344 deployed file(s) missing.
  • drift: drift replay failed: Subdirectory 'plugins/bin' not found in repository.
  • pre-commit also reported "files were modified by this hook".

Side effects:

  1. core.bare = true was written to the shared /root/ai-development/.git/config. The main checkout broke: git status failed with "fatal: this operation must be run in a work tree", and git worktree list showed the main checkout as (bare).
  2. The linked worktree was left on a detached HEAD at an old commit. Its reflog shows two hook-driven checkouts: from the branch to c3d0ab3, then to 60f9b22 (holocron PR 164's merge). The working tree was left with dozens of modified files and untracked ADRs.
  3. The branch tip and commit were unaffected.

Recovery (manual):

  • git config core.bare false in the main checkout.
  • git checkout -f <branch> in the worktree.

Pushing the same branch from the main checkout, which has apm_modules/ populated, passed every hook and changed nothing.

Why it matters

  • AGENTS.md doesn't cover it. It says a fresh clone needs apm install once, but says nothing about linked worktrees, which agents and subagents create routinely for parallel work.
  • The damage spreads. A failed audit in one worktree silently breaks every other checkout that shares the .git directory.

Suspected cause

The drift / config-consistency install replay appears to run git operations (checkout, and something that sets core.bare) against the repository resolved from the hook's environment. In a linked worktree, GIT_DIR / GIT_COMMON_DIR point at the shared .git. A replay that clones or initialises "a repository" there instead of in a temp dir would explain both effects. This is unverified: the replay code wasn't read.

Expected

The audit replay must work in an isolated temp clone and never mutate the invoking repository's config or HEAD. Failing that, the hook should detect a linked worktree without apm_modules/ and fail with a clear message before replaying.

Workarounds until fixed

  • Run apm install in a new worktree before its first push, or push from the main checkout.
  • After any failed apm-audit-ci run in a worktree, check git config --get core.bare in the main checkout.

Worth a LESSONS.md entry once the cause is confirmed.

## What happened On 2026-11-22 a `git push` from a **linked git worktree** of this repo failed the `apm-audit-ci` pre-push hook. The failed run then changed git state outside its own scope. **Setup:** worktree created with `git worktree add ../ai-development-wt/<name> -b <branch> origin/main`. It had a fresh checkout with no `apm_modules/`. **Hook output:** - `deployed-files-present`: 344 deployed file(s) missing. - `drift`: drift replay failed: `Subdirectory 'plugins/bin' not found in repository`. - pre-commit also reported "files were modified by this hook". **Side effects:** 1. **`core.bare = true` was written to the shared `/root/ai-development/.git/config`.** The main checkout broke: `git status` failed with "fatal: this operation must be run in a work tree", and `git worktree list` showed the main checkout as `(bare)`. 2. **The linked worktree was left on a detached HEAD at an old commit.** Its reflog shows two hook-driven checkouts: from the branch to `c3d0ab3`, then to `60f9b22` (holocron PR 164's merge). The working tree was left with dozens of modified files and untracked ADRs. 3. **The branch tip and commit were unaffected.** **Recovery (manual):** - `git config core.bare false` in the main checkout. - `git checkout -f <branch>` in the worktree. Pushing the same branch from the main checkout, which has `apm_modules/` populated, passed every hook and changed nothing. ## Why it matters - **AGENTS.md doesn't cover it.** It says a fresh clone needs `apm install` once, but says nothing about linked worktrees, which agents and subagents create routinely for parallel work. - **The damage spreads.** A failed audit in one worktree silently breaks every other checkout that shares the `.git` directory. ## Suspected cause The drift / config-consistency install replay appears to run git operations (checkout, and something that sets `core.bare`) against the repository resolved from the hook's environment. In a linked worktree, `GIT_DIR` / `GIT_COMMON_DIR` point at the shared `.git`. A replay that clones or initialises "a repository" there instead of in a temp dir would explain both effects. This is unverified: the replay code wasn't read. ## Expected The audit replay must work in an isolated temp clone and never mutate the invoking repository's config or HEAD. Failing that, the hook should detect a linked worktree without `apm_modules/` and fail with a clear message before replaying. ## Workarounds until fixed - Run `apm install` in a new worktree before its first push, or push from the main checkout. - After any failed `apm-audit-ci` run in a worktree, check `git config --get core.bare` in the main checkout. Worth a `LESSONS.md` entry once the cause is confirmed.
Claude added this to the Tooling milestone 2026-11-22 19:20:11 +00:00
Claude added the Kind/Bug
Priority
Medium
3
labels 2026-11-22 19:20:11 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Mortis/Holocron#204