Skip to content

fix: stop pre-push tests writing to the repository's git config - #424

Open
stuartwdouglas wants to merge 1 commit into
mainfrom
fix/pre-push-tests-git-dir
Open

stuartwdouglas wants to merge 1 commit into
mainfrom
fix/pre-push-tests-git-dir

Conversation

@stuartwdouglas

Copy link
Copy Markdown
Contributor

Git sets GIT_DIR when it runs hooks. On a push from a linked worktree, it points at the main repository's .git/worktrees/<name>. The pre-push hook runs just test, and tests that run git init or git -C <tmpdir> config ... honour GIT_DIR over -C, so they write into the real repository's shared config instead of their temp repos. That leaves:

  • core.bare = true, which breaks the main checkout (git status: "this operation must be run in a work tree")
  • user.name = Test / user.email = test@example.com, so later commits are authored as Test and fail DCO

The test pre-push command now unsets GIT_DIR, GIT_WORK_TREE and GIT_INDEX_FILE before running the tests.

Verified with a scratch repo and worktree whose pre-push command runs git init and git config user.email in a temp dir, like the tests do. Before this change, a push from the worktree left user.email=test@example.com and core.bare=true in the main repo's config. With it, the config is untouched.

Git sets GIT_DIR for hooks. When pushing from a linked worktree it points at
the main repository, so the tests' git init/config commands against temp
directories instead wrote core.bare=true and a Test user identity into the
shared config, breaking the main checkout and authoring later commits as
Test <test@example.com>.

Amp-Thread-ID: https://ampcode.com/threads/T-01a1a052-93bd-73a1-83b2-d55b78c2b1c0
Co-authored-by: Amp <amp@ampcode.com>
@stuartwdouglas
stuartwdouglas requested a review from a team as a code owner November 4, 2026 04:17
@stuartwdouglas
stuartwdouglas requested review from joshfriend and removed request for a team November 4, 2026 04:17
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-04T04:19:18.175891Z 4bfc6a6 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4bfc6a6c92

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread lefthook.yml
Comment on lines +14 to +15
# Git sets GIT_DIR for hooks, which makes the tests' git commands write to this repository instead of their
# temporary repositories.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Remove the comment on this single command

This newly added comment documents a single run entry rather than a block of 20 or more lines, conflicting with the root repository policy that comments are only for large, nonobvious blocks. Remove the comment and let the command and commit history carry this rationale.

AGENTS.md reference: AGENTS.md:L19-L20

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant