Skip to content

fix(hooks): pass --allow-unknown-hook-name on git 2.44+#727

Merged
aviator-app[bot] merged 2 commits intomasterfrom
fix-hooks-allow-unknown-hook-name
Apr 22, 2026
Merged

fix(hooks): pass --allow-unknown-hook-name on git 2.44+#727
aviator-app[bot] merged 2 commits intomasterfrom
fix-hooks-allow-unknown-hook-name

Conversation

@jainankit
Copy link
Copy Markdown
Contributor

@jainankit jainankit commented 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.442.53 — flag included, accepted but not required.
  • >= 2.54 — flag included and required; prevents the "unknown hook event" failure.

Test plan

  • go build ./...
  • go tool golangci-lint run ./internal/git/... ./cmd/av/...
  • go test --vet=all ./internal/git/... ./cmd/av/...
  • CI green

Git 2.54 tightened `git hook run` to reject non-native hook names
unless `--allow-unknown-hook-name` is passed, so `av pr` and `av sync`
fail on 2.54+ when invoking the `pre-av-pr` and `pre-av-sync` hooks
(even when no such hook is configured). The flag was introduced in
git 2.44, so add it conditionally based on a parsed `git --version`
to avoid regressing older gits that don't recognize the flag.
@jainankit jainankit requested a review from a team as a code owner April 22, 2026 19:20
@jainankit jainankit marked this pull request as draft April 22, 2026 19:21
@jainankit jainankit marked this pull request as ready for review April 22, 2026 19:21
@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
    • 🔒 internal/git/version.go
    • 🔒 internal/git/version_test.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 davi-maciel April 22, 2026 19:22
@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 was merged using Aviator.


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.

@davi-maciel davi-maciel requested review from tulioz and removed request for davi-maciel April 22, 2026 19:25
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 implements dynamic git hook argument generation based on the installed git version, specifically adding support for the --allow-unknown-hook-name flag required by newer git versions. It introduces a version parsing utility and updates hook execution calls in the pr and sync commands. A review comment suggests caching the git version to improve performance by avoiding redundant shell executions.

Comment thread internal/git/version.go
Comment on lines +13 to +19
func (r *Repo) Version(ctx context.Context) (major, minor int, err error) {
out, err := r.Git(ctx, "--version")
if err != nil {
return 0, 0, err
}
return parseGitVersion(out)
}
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 Version method executes an external git --version command every time it is called. While this is relatively fast, it is inefficient to perform this I/O and process creation repeatedly during a single CLI invocation. Consider caching the detected version in the Repo struct or using a package-level sync.OnceValues to ensure the version is only parsed once.

@aviator-app aviator-app Bot merged commit 8524ee9 into master Apr 22, 2026
5 checks passed
@aviator-app aviator-app Bot deleted the fix-hooks-allow-unknown-hook-name branch April 22, 2026 19:33
aviator-app Bot pushed a commit that referenced this pull request Apr 22, 2026
## Summary

Follow-up to #727. That PR gated `--allow-unknown-hook-name` at git 2.44 based on incorrect version information. The flag was actually introduced in git 2.54 alongside the stricter hook-name validation, so passing it on 2.44–2.53 would be rejected as an unknown flag.

## Change

- `internal/git/version.go`: bump the threshold in `supportsAllowUnknownHookName` from `>= 2.44` to `>= 2.54`, and update the surrounding comments.

Behavior now:
- `< 2.54` — flag omitted (no unknown-flag errors on older git).
- `>= 2.54` — flag included; required to allow non-native hook names like `pre-av-pr`/`pre-av-sync`.

If version detection fails, we still include the flag so modern git keeps working.

## 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] Locally upgraded to git 2.54.0 and can confirm `av sync` now invokes the `pre-av-sync` hook instead of failing with `unknown hook event`.
- [ ] CI green
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