Skip to content
This repository was archived by the owner on Oct 23, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/commands/release/set-commits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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;
}
Expand Down
40 changes: 40 additions & 0 deletions test/commands/release/set-commits.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,46 @@ describe("release set-commits --commit", () => {
});
});

describe("release set-commits --clear", () => {
let setCommitsWithRefsSpy: ReturnType<typeof spyOn>;
let resolveOrgSpy: ReturnType<typeof spyOn>;

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<typeof spyOn>;
let resolveOrgSpy: ReturnType<typeof spyOn>;
Expand Down
Loading