fix(commit): report hook refusals cleanly and honor --push on a clean tree
git.commit() was awaited without a try in both agentic commit routes and the legacy pipeline, so a refusing pre-commit/commit-msg hook escaped as an uncaught GitCommandError. In a bundled build Bun renders that as kilobytes of minified source. The split loop also threw out of its order loop, reporting no progress. The empty-staged-tree early return fired before args.push was read, so 'omp commit --push' on a clean tree exited 0 without pushing. Route commit/push failures through a shared execute helper: abortOnGitFailure prints the hook's own message (plus split-plan progress) and throws a CommitAbortedError the command maps to exit 1; pushOrAbort pushes existing commits when the tree is clean and reports refused pushes cleanly. Fixes #7834
This commit is contained in:
@@ -52,4 +52,22 @@ describe("omp commit command lifecycle (issue #1041)", () => {
|
||||
expect(runCommitSpy).toHaveBeenCalledTimes(1);
|
||||
expect(quitSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("maps CommitAbortedError to exit code 1 without rethrowing (issue #7834)", async () => {
|
||||
vi.spyOn(themeModule, "initTheme").mockResolvedValue(undefined);
|
||||
vi.spyOn(commitModule, "runCommitCommand").mockRejectedValue(new commitModule.CommitAbortedError());
|
||||
const quitSpy = vi.spyOn(postmortem, "quit").mockResolvedValue(undefined);
|
||||
|
||||
const command = new CommitCommand([], {
|
||||
bin: "omp",
|
||||
version: "0.0.0-test",
|
||||
commands: new Map(),
|
||||
});
|
||||
|
||||
// A hook refusal is already reported with a readable message; the command
|
||||
// must exit non-zero rather than let the runtime dump the error.
|
||||
await command.run();
|
||||
|
||||
expect(quitSpy).toHaveBeenCalledWith(1);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user