Skip to content

fix: follow origin/HEAD in pre-commit hook#36

Merged
ethanj merged 1 commit intomainfrom
hook-dynamic-base
Apr 22, 2026
Merged

fix: follow origin/HEAD in pre-commit hook#36
ethanj merged 1 commit intomainfrom
hook-dynamic-base

Conversation

@ethanj
Copy link
Copy Markdown
Contributor

@ethanj ethanj commented Apr 22, 2026

Summary

Follow-up to the earlier hook tightening. Codex flagged that .husky/pre-commit hardcoded --base=origin/main (or origin/staging in webapp-sdk) while CI uses a dynamic base (github.base_ref || github.event.repository.default_branch). If the repo ever changes its default branch, or a PR targets a non-default branch, the hook and CI would audit different diffs — the same false-green risk the --base pin was meant to eliminate.

Fix

Replace the hardcoded ref with git symbolic-ref --short refs/remotes/origin/HEAD, which returns the actual default branch (origin/main, origin/staging, etc.) set by git clone. The hook now adapts to whatever the repo defaults to.

Non-default-target PRs (a feature branch explicitly targeting staging while origin defaults to main, etc.) will still diff differently locally than CI will — that is inherent to pre-commit since the eventual PR target is not known until push time. Documented inline in the hook comment.

Test plan

  • Pre-commit hook resolves BASE correctly and passes fallow audit on this branch
  • CI green end-to-end

Codex flagged that .husky/pre-commit hardcoded --base=origin/main
while CI uses a dynamic base (github.base_ref || default_branch),
so if the repo ever changes its default branch or a PR targets a
non-default branch, the hook and CI would audit different diffs —
the same false-green risk the --base pin was meant to eliminate.

Replace the hardcoded ref with `git symbolic-ref --short
refs/remotes/origin/HEAD`, which returns the actual default branch
(origin/main, origin/staging, etc.) set by `git clone`. The hook
now adapts to whatever the repo defaults to.

Non-default-target PRs (a feature branch explicitly targeting
staging while origin defaults to main, etc.) will still diff
differently locally than CI will — that is inherent to pre-commit
since the eventual PR target is not known until push time.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@ethanj ethanj merged commit c5f6a33 into main Apr 22, 2026
1 check passed
@ethanj ethanj deleted the hook-dynamic-base branch April 22, 2026 23:05
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