Pre-push hooks run from an agent worktree flip core.bare=true on the main checkout #198

Open
opened 2026-11-22 16:57:28 +00:00 by Claude · 0 comments
Owner

What happened

On 2026-11-22 a research subagent ran git push from a linked worktree (.claude/worktrees/agent-<id>, branch research/copilot-cli-agents). The pre-push hooks ran and the push failed (see the worktree-gate issue). Afterwards the main checkout's .git/config had core.bare = true:

  • git rev-parse --is-inside-work-tree returned false in /root/ai-development
  • git worktree list showed the main checkout as (bare)
  • the next push from the main checkout failed inside pre-commit with fatal: this operation must be run in a work tree

git config core.bare false restored it, and a later push from the main checkout left it false. The subagent also reported that its first push attempt left the worktree's HEAD detached at an older main commit.

Likely cause

This is the same class of bug that tests/run-tests.sh lines 36–42 already guard against. Git exports GIT_DIR (and possibly GIT_WORK_TREE, GIT_INDEX_FILE, GIT_COMMON_DIR) to hooks, so a fixture's git -C "$tmp" … resolves to this repo; the validate-provenance-skill.bats commit_as_base helper once flipped core.bare that way. run-tests.sh unsets them, but some other pre-push hook path does not. From a linked worktree, GIT_DIR points at .git/worktrees/<id>, and writes to config land in the shared .git/config.

To do

  • Reproduce: push from a linked worktree under .claude/worktrees/ and check git config core.bare on the main checkout afterwards.
  • Find the hook entry point that doesn't clear the inherited GIT_* variables (candidates: hooks that call bats or build fixture repos outside run-tests.sh, and apm-audit-ci's install replay), and unset them there, or centrally.
  • Add a regression test that runs the hook set with GIT_DIR exported and asserts core.bare is unchanged.

Found while working Copilot CLI agent behaviour from docs.

## What happened On 2026-11-22 a research subagent ran `git push` from a linked worktree (`.claude/worktrees/agent-<id>`, branch `research/copilot-cli-agents`). The pre-push hooks ran and the push failed (see the worktree-gate issue). Afterwards the **main checkout's** `.git/config` had `core.bare = true`: - `git rev-parse --is-inside-work-tree` returned `false` in `/root/ai-development` - `git worktree list` showed the main checkout as `(bare)` - the next push from the main checkout failed inside pre-commit with `fatal: this operation must be run in a work tree` `git config core.bare false` restored it, and a later push from the main checkout left it `false`. The subagent also reported that its first push attempt left the worktree's HEAD detached at an older `main` commit. ## Likely cause This is the same class of bug that `tests/run-tests.sh` lines 36–42 already guard against. Git exports `GIT_DIR` (and possibly `GIT_WORK_TREE`, `GIT_INDEX_FILE`, `GIT_COMMON_DIR`) to hooks, so a fixture's `git -C "$tmp" …` resolves to this repo; the `validate-provenance-skill.bats` `commit_as_base` helper once flipped `core.bare` that way. `run-tests.sh` unsets them, but some other pre-push hook path does not. From a linked worktree, `GIT_DIR` points at `.git/worktrees/<id>`, and writes to `config` land in the shared `.git/config`. ## To do - Reproduce: push from a linked worktree under `.claude/worktrees/` and check `git config core.bare` on the main checkout afterwards. - Find the hook entry point that doesn't clear the inherited `GIT_*` variables (candidates: hooks that call bats or build fixture repos outside `run-tests.sh`, and `apm-audit-ci`'s install replay), and unset them there, or centrally. - Add a regression test that runs the hook set with `GIT_DIR` exported and asserts `core.bare` is unchanged. Found while working [Copilot CLI agent behaviour from docs](https://git.rkdr.net/Mortis/Holocron/issues/187).
Claude added the Kind/BugStatus/Needs Triage labels 2026-11-22 16:57:28 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Mortis/Holocron#198