Skip to content

fix: skip migrations and version check when called as git hook#545

Merged
di-sukharev merged 2 commits intodi-sukharev:masterfrom
majiayu000:fix/issue-493-rebase-slow-hook
Mar 27, 2026
Merged

fix: skip migrations and version check when called as git hook#545
di-sukharev merged 2 commits intodi-sukharev:masterfrom
majiayu000:fix/issue-493-rebase-slow-hook

Conversation

@majiayu000
Copy link
Copy Markdown
Contributor

Fixes #493

Problem

During git rebase -i, opencommit's prepare-commit-msg hook runs for every pick commit. Even though the hook itself exits early when commitSource is set (e.g. during rebase), runMigrations() and checkIsLatestVersion() execute first — adding network calls and file I/O per commit, making rebase painfully slow.

Fix

Move the isHookCalled() check before runMigrations() and checkIsLatestVersion() in the CLI callback. When invoked as a git hook, we skip straight to prepareCommitMessageHook() without running migrations or version checks. These expensive operations only run for interactive CLI usage.

Test Plan

  • npm run test:unit — all 25 tests pass
  • npm run build — compiles cleanly
  • Manual: set up opencommit hook, create commits, run git rebase -i HEAD~3 — each pick completes near-instantly

Move isHookCalled() check before runMigrations() and
checkIsLatestVersion() so that during git rebase, each pick commit
exits immediately without expensive I/O and network calls.

Also adds missing await on prepareCommitMessageHook() to properly
handle async errors.

Closes di-sukharev#493

Signed-off-by: majiayu000 <1835304752@qq.com>
@majiayu000 majiayu000 marked this pull request as ready for review March 21, 2026 03:23
@di-sukharev
Copy link
Copy Markdown
Owner

@majiayu000 first of all thank you very much for your contribution <3

the code looks good, but an e2e test fails, could you pls look into it 🙏

@di-sukharev
Copy link
Copy Markdown
Owner

@majiayu000 thank you 🙏
an e2e test fails, could you please look into it and i will merge it

Signed-off-by: majiayu000 <majiayu000@users.noreply.github.com>
@di-sukharev di-sukharev merged commit f51393e into di-sukharev:master Mar 27, 2026
6 checks passed
@di-sukharev
Copy link
Copy Markdown
Owner

@majiayu000 thank you

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.

[Bug]: rebasing is painfully slow with opencommit hook set

2 participants