Skip to content

fix(hooks): pass --allow-unknown-hook-name to git hook run#724

Closed
tgandrews wants to merge 1 commit intoaviator-co:masterfrom
tgandrews:fix/git-2.54-unknown-hook-name
Closed

fix(hooks): pass --allow-unknown-hook-name to git hook run#724
tgandrews wants to merge 1 commit intoaviator-co:masterfrom
tgandrews:fix/git-2.54-unknown-hook-name

Conversation

@tgandrews
Copy link
Copy Markdown
Contributor

Summary

Git 2.54 tightened git hook run to reject non-native hook names unless --allow-unknown-hook-name is passed. Since av invokes git hook run pre-av-pr and git hook run pre-av-sync — both custom names — every av pr and av sync currently fails on git 2.54 with:

error: unknown hook event 'pre-av-pr';
use --allow-unknown-hook-name to allow non-native hook names

…which av treats as a hook failure, aborting the command before any push or PR creation happens (even when the user has no such hook configured, because --ignore-missing no longer suppresses the unknown-name error).

This PR adds --allow-unknown-hook-name at the two call sites:

  • cmd/av/pr.gorunPRHook invoking pre-av-pr
  • cmd/av/sync.gopreAvSyncHookModel.Init invoking pre-av-sync

The flag is also accepted by git hook run on pre-2.54 versions, so no version gating is needed.

Reproduction (before the fix)

$ git --version
git version 2.54.0
$ av pr --debug
...
time=... level=debug msg="git [hook run --ignore-missing pre-av-pr]"
error: unknown hook event 'pre-av-pr';
use --allow-unknown-hook-name to allow non-native hook names
error: pre-av-pr hook failed: git [hook run --ignore-missing pre-av-pr] (): exit status 1

Test plan

  • go build ./...
  • go tool golangci-lint run
  • go test ./cmd/av/...
  • Ran the patched binary against a repo on git 2.54.0 — av pr now passes the hook stage and proceeds to push / PR creation as expected (debug log shows git [hook run --ignore-missing --allow-unknown-hook-name pre-av-pr] succeeding).
  • CI green

🤖 Generated with Claude Code

Git 2.54 tightened `git hook run` to reject non-native hook names
unless `--allow-unknown-hook-name` is passed. Since av invokes
`git hook run pre-av-pr` and `git hook run pre-av-sync` — both
custom names — every `av pr` and `av sync` now fails on git 2.54
with:

    error: unknown hook event 'pre-av-pr';
    use --allow-unknown-hook-name to allow non-native hook names

Add `--allow-unknown-hook-name` at both call sites. The flag is
accepted by `git hook run` on older versions as well, so no version
gating is needed.

Verified by building locally and running `av pr` against a repo on
git 2.54.0 — the hook invocation now succeeds and the command
proceeds normally.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
@tgandrews tgandrews requested a review from a team as a code owner April 22, 2026 13:35
@aviator-app
Copy link
Copy Markdown
Contributor

aviator-app Bot commented Apr 22, 2026

Current Aviator status

Aviator will automatically update this comment as the status of the PR changes.
Comment /aviator refresh to force Aviator to re-examine your PR (or learn about other /aviator commands).

This PR is currently in state closed (PR closed manually).


See the real-time status of this PR on the Aviator webapp.
Use the Aviator Chrome Extension to see the status of your PR within GitHub.

@aviator-app
Copy link
Copy Markdown
Contributor

aviator-app Bot commented Apr 22, 2026

🔃 FlexReview Status

Common Owner: aviator-co/engineering (expert-load-balance assignment)
Owner and Assignment:

  • 🔒 aviator-co/engineering (expert-load-balance assignment)
    Owned Files
    • 🔒 cmd/av/pr.go
    • 🔒 cmd/av/sync.go

Review SLO: 7 business hours if PR size is <= 200 LOC for the first response.

@aviator-app aviator-app Bot requested a review from jainankit April 22, 2026 13:35
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds the --allow-unknown-hook-name flag to Git hook commands in cmd/av/pr.go and cmd/av/sync.go. Feedback highlights that this flag was introduced in Git 2.44.0 and will cause errors on older versions, suggesting that version gating may be necessary if older Git versions are supported.

Comment thread cmd/av/pr.go
"hook",
"run",
"--ignore-missing",
"--allow-unknown-hook-name",
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The --allow-unknown-hook-name flag was introduced in Git 2.44.0. Using it will cause an unknown option error on older Git versions (2.36–2.43). While the PR description mentions that no version gating is needed, this is only true for Git 2.44 and later. If the project intends to support older Git versions, consider checking the Git version before passing this flag.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is correct, we get an error on older versions:

error: unknown option `allow-unknown-hook-name'

Comment thread cmd/av/sync.go
"hook",
"run",
"--ignore-missing",
"--allow-unknown-hook-name",
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The --allow-unknown-hook-name flag was introduced in Git 2.44.0. Using it will cause an unknown option error on older Git versions (2.36–2.43). While the PR description mentions that no version gating is needed, this is only true for Git 2.44 and later. If the project intends to support older Git versions, consider checking the Git version before passing this flag.

aviator-app Bot pushed a commit that referenced this pull request Apr 22, 2026
## Summary

Git 2.54 tightened `git hook run` to reject non-native hook names unless `--allow-unknown-hook-name` is passed. Since av invokes `git hook run pre-av-pr` and `git hook run pre-av-sync` — both custom names — every `av pr` and `av sync` fails on git 2.54+ with:

```
error: unknown hook event 'pre-av-pr';
use --allow-unknown-hook-name to allow non-native hook names
```

This is closely related to #724, but that PR passes the flag unconditionally. `--allow-unknown-hook-name` was only introduced in git 2.44, so on older gits the flag itself would be rejected. This PR gates the flag on a parsed `git --version`.

## Changes

- `internal/git/version.go`: adds `Repo.Version(ctx)` which parses `git --version` into `(major, minor)`, and `Repo.HookRunArgs(ctx, hookName)` which builds the `git hook run` arg list and conditionally appends `--allow-unknown-hook-name` when git >= 2.44. If version detection fails, the flag is still included so modern git keeps working.
- `internal/git/version_test.go`: unit tests covering stable, patch, Apple-suffixed, newline-trailed, and malformed version strings.
- `cmd/av/pr.go`: `runPRHook` uses `repo.HookRunArgs(ctx, "pre-av-pr")`.
- `cmd/av/sync.go`: `preAvSyncHookModel.Init` uses `m.repo.HookRunArgs(ctx, "pre-av-sync")`.

Behavior by git version:
- `< 2.44` — flag omitted (avoids "unknown option" errors on old git).
- `2.44`–`2.53` — flag included, accepted but not required.
- `>= 2.54` — flag included and required; prevents the "unknown hook event" failure.

## Test plan

- [x] `go build ./...`
- [x] `go tool golangci-lint run ./internal/git/... ./cmd/av/...`
- [x] `go test --vet=all ./internal/git/... ./cmd/av/...`
- [x] CI green
@jainankit
Copy link
Copy Markdown
Contributor

Fixed with #727

@jainankit jainankit closed this Apr 22, 2026
@tgandrews
Copy link
Copy Markdown
Contributor Author

Fixed with #727

Thanks for fixing it. I only just saw the review comments.

@tgandrews tgandrews deleted the fix/git-2.54-unknown-hook-name branch April 22, 2026 21:37
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.

2 participants