diff --git a/docs/CLI.md b/docs/CLI.md index 61dc3eb9..c1ac6d9d 100644 --- a/docs/CLI.md +++ b/docs/CLI.md @@ -396,6 +396,7 @@ Options: --amend Amend the previous commit --no-edit Use the previous commit message without editing -a, --all Auto-stage modified and deleted tracked files + -q, --quiet Suppress commit summary ``` ## git config diff --git a/src/commands/commit.ts b/src/commands/commit.ts index 173d3dff..3d799ae2 100644 --- a/src/commands/commit.ts +++ b/src/commands/commit.ts @@ -62,6 +62,7 @@ export function registerCommitCommand(parent: Command, ext?: GitExtensions) { amend: f().describe("Amend the previous commit"), noEdit: f().describe("Use the previous commit message without editing"), all: f().alias("a").describe("Auto-stage modified and deleted tracked files"), + quiet: f().alias("q").describe("Suppress commit summary"), }, handler: async (args, ctx) => { const messages = args.message as string[]; @@ -440,6 +441,7 @@ export function registerCommitCommand(parent: Command, ext?: GitExtensions) { parents, author, }); + if (args.quiet) return { stdout: "", stderr: "", exitCode: 0 }; // Format output — for amend, diff against the amended commit's parent const branchRef = head?.type === "symbolic" ? head.target : null; diff --git a/test/commands/commit.test.ts b/test/commands/commit.test.ts index 7b8f17cc..f7620394 100644 --- a/test/commands/commit.test.ts +++ b/test/commands/commit.test.ts @@ -733,4 +733,23 @@ describe("git commit", () => { expect(results[2].stdout).toContain("relative path message"); }); }); + + describe("--quiet", () => { + test("-q and -qm commit without printing the summary", async () => { + const bash = createTestBash({ files: BASIC_REPO, env: TEST_ENV }); + await bash.exec("git init"); + await bash.exec("git add README.md"); + const first = await bash.exec('git commit -q -m "first"'); + expect(first.exitCode).toBe(0); + expect(first.stdout).toBe(""); + expect(first.stderr).toBe(""); + + await bash.exec("git add src/main.ts"); + const second = await bash.exec('git commit -qm "second"'); + expect(second.exitCode).toBe(0); + expect(second.stdout).toBe(""); + expect(second.stderr).toBe(""); + expect((await bash.exec("git log --format=%s -2")).stdout).toContain("second\nfirst"); + }); + }); });