Skip to content

Skip reindex during rebase and add post-rewrite hook - #210

Merged
andrew merged 1 commit into
mainfrom
skip-reindex-during-rebase
May 27, 2026
Merged

andrew merged 1 commit into
mainfrom
skip-reindex-during-rebase

Conversation

@andrew

@andrew andrew commented May 26, 2026

Copy link
Copy Markdown
Contributor

Fixes #209.

The post-commit hook fires once per replayed commit during a rebase, so a 100-commit rebase ran git pkgs reindex 100 times. This change makes the post-commit and post-merge hooks exit early when $GIT_DIR/rebase-merge or $GIT_DIR/rebase-apply exists, and adds a post-rewrite hook that reindexes once when the rebase finishes.

post-rewrite only acts when $1 = rebase. Git also calls it with $1 = amend for every reword inside an interactive rebase and for standalone git commit --amend; the former would defeat the point and the latter is already covered by post-commit. Verified that the rebase state directory is still present when post-rewrite fires, so the directory check could not be reused there.

Hooks written by older versions are recognised by their #!/bin/sh\n# git-pkgs header and overwritten on the next git pkgs hooks --install or git pkgs init. Hooks where git-pkgs lines were appended to a user's own script are left as-is; those users will need to run hooks --uninstall then --install to pick up the guard.

The two near-identical install paths (doInstallHooks and installHooks) now share a writeHook helper.

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

Copilot AI 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.

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 writeHook helper for install paths.
  • Adds rebase guards to post-commit and post-merge.
  • Adds post-rewrite handling 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.

@andrew
andrew merged commit 8117f79 into main May 27, 2026
1 check passed
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.

Slow performance when rebasing

2 participants