From 4da3f1547cce72389ada75f151584ebd2d82762b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Beteg=C3=B3n?= Date: Fri, 3 Jul 2026 17:59:52 +0200 Subject: [PATCH] fix(release): make set-commits --clear actually clear commits --clear sent `{ commits: [] }`, but the Sentry release PUT endpoint only runs `clear_commits()` when it receives an explicitly-empty `refs` array; an empty `commits` list is falsy server-side and silently no-ops. Route --clear through setCommitsWithRefs(org, version, []) so it sends `{ refs: [] }` and the commits are removed. Reported in #1156. Co-authored-by: Cursor --- src/commands/release/set-commits.ts | 11 ++++--- test/commands/release/set-commits.test.ts | 40 +++++++++++++++++++++++ 2 files changed, 46 insertions(+), 5 deletions(-) diff --git a/src/commands/release/set-commits.ts b/src/commands/release/set-commits.ts index c65d358b8a..fe70b052d5 100644 --- a/src/commands/release/set-commits.ts +++ b/src/commands/release/set-commits.ts @@ -10,7 +10,6 @@ import { setCommitsAuto, setCommitsLocal, setCommitsWithRefs, - updateRelease, } from "../../lib/api-client.js"; import { buildCommand, numberParser } from "../../lib/command.js"; import { getDatabase } from "../../lib/db/index.js"; @@ -278,11 +277,13 @@ export const setCommitsCommand = buildCommand({ cwd ); - // Clear mode: remove all commits regardless of other flags + // Clear mode: remove all commits regardless of other flags. + // The server only clears commits when it receives an explicitly-empty + // `refs` array — an empty `commits` list is treated as "no change" and + // silently no-ops. setCommitsWithRefs sends `{ refs: [] }`, which triggers + // release.clear_commits() server-side. if (flags.clear) { - const release = await updateRelease(org, version, { - commits: [], - }); + const release = await setCommitsWithRefs(org, version, []); yield new CommandOutput(release); return; } diff --git a/test/commands/release/set-commits.test.ts b/test/commands/release/set-commits.test.ts index 11fc9a1b88..b047f8b6b2 100644 --- a/test/commands/release/set-commits.test.ts +++ b/test/commands/release/set-commits.test.ts @@ -208,6 +208,46 @@ describe("release set-commits --commit", () => { }); }); +describe("release set-commits --clear", () => { + let setCommitsWithRefsSpy: ReturnType; + let resolveOrgSpy: ReturnType; + + beforeEach(() => { + setCommitsWithRefsSpy = vi.spyOn(apiClient, "setCommitsWithRefs"); + resolveOrgSpy = vi.spyOn(resolveTarget, "resolveOrg"); + }); + + afterEach(() => { + setCommitsWithRefsSpy.mockRestore(); + resolveOrgSpy.mockRestore(); + }); + + // The server only clears commits when it receives an explicitly-empty + // `refs` array; an empty `commits` list silently no-ops. This guards + // against regressing back to the `updateRelease({ commits: [] })` path. + test("sends an empty refs array to clear commits", async () => { + resolveOrgSpy.mockResolvedValue({ org: "my-org" }); + setCommitsWithRefsSpy.mockResolvedValue(sampleRelease); + + const { context } = createMockContext(); + const func = await setCommitsCommand.loader(); + await func.call( + context, + { + auto: false, + local: false, + clear: true, + commit: undefined, + "initial-depth": 20, + json: true, + }, + "1.0.0" + ); + + expect(setCommitsWithRefsSpy).toHaveBeenCalledWith("my-org", "1.0.0", []); + }); +}); + describe("release set-commits --auto", () => { let setCommitsAutoSpy: ReturnType; let resolveOrgSpy: ReturnType;