Repository navigation
Skip reindex during rebase and add post-rewrite hook - #210
Merged
Merged
Conversation
The post-commit hook fired once per commit during a rebase, so a 100-commit rebase ran reindex 100 times. The hook now bails when $GIT_DIR/rebase-merge or rebase-apply exists, and a new post-rewrite hook reindexes once when the rebase finishes ($1 = rebase, so per-commit amend calls inside the rebase are ignored). Hooks installed by older versions are detected by their #!/bin/sh header and overwritten on the next `hooks --install` or `init`. Fixes #209
There was a problem hiding this comment.
Pull request overview
This PR reduces unnecessary reindexing during rebases by skipping reindex work from commit/merge hooks while a rebase is active and adding a post-rewrite hook to reindex once after rebase rewrites complete.
Changes:
- Introduces shared hook definitions and a
writeHookhelper for install paths. - Adds rebase guards to
post-commitandpost-merge. - Adds
post-rewritehandling for rebase-only reindexing plus tests for upgrade, append, and uninstall behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
cmd/hooks.go |
Refactors hook installation and adds guarded post-commit/post-merge plus post-rewrite. |
cmd/hooks_test.go |
Adds tests for guarded uninstall behavior, old hook upgrades, post-rewrite install, and foreign hook append behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #209.
The
post-commithook fires once per replayed commit during a rebase, so a 100-commit rebase rangit pkgs reindex100 times. This change makes thepost-commitandpost-mergehooks exit early when$GIT_DIR/rebase-mergeor$GIT_DIR/rebase-applyexists, and adds apost-rewritehook that reindexes once when the rebase finishes.post-rewriteonly acts when$1 = rebase. Git also calls it with$1 = amendfor every reword inside an interactive rebase and for standalonegit commit --amend; the former would defeat the point and the latter is already covered bypost-commit. Verified that the rebase state directory is still present whenpost-rewritefires, so the directory check could not be reused there.Hooks written by older versions are recognised by their
#!/bin/sh\n# git-pkgsheader and overwritten on the nextgit pkgs hooks --installorgit pkgs init. Hooks where git-pkgs lines were appended to a user's own script are left as-is; those users will need to runhooks --uninstallthen--installto pick up the guard.The two near-identical install paths (
doInstallHooksandinstallHooks) now share awriteHookhelper.