Skip to content
Open
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
5 changes: 5 additions & 0 deletions .changeset/vast-onions-behave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@changesets/cli": minor
---

Add no commit option to "add"/default command. Use `--no-commit` or `-n` when instantiated and the changeset will not be committed.
32 changes: 32 additions & 0 deletions packages/cli/src/commands/add/__tests__/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,38 @@ describe("Add command", () => {
expect(git.commit).toHaveBeenCalledTimes(1);
});

it("should not commit when the `no-commit` flag is passed in", async () => {
const cwd = await testdir({
"package.json": JSON.stringify({
private: true,
workspaces: ["packages/*"],
}),
"packages/pkg-a/package.json": JSON.stringify({
name: "pkg-a",
version: "1.0.0",
dependencies: {
"pkg-b": "1.0.0",
},
}),
"packages/pkg-b/package.json": JSON.stringify({
name: "pkg-b",
version: "1.0.0",
}),
});

mockUserResponses({ releases: { "pkg-a": "patch" } });
await addChangeset(
cwd,
{ empty: false, noCommit: true },
{
...defaultConfig,
commit: [path.resolve(__dirname, "..", "..", "..", "commit"), null],
}
);
expect(git.add).toHaveBeenCalledTimes(0);
expect(git.commit).toHaveBeenCalledTimes(0);
});

it("should create empty changeset when empty flag is passed in", async () => {
const cwd = await testdir({
"package.json": JSON.stringify({
Expand Down
8 changes: 6 additions & 2 deletions packages/cli/src/commands/add/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ import printConfirmationMessage from "./messages";

export default async function add(
cwd: string,
{ empty, open }: { empty?: boolean; open?: boolean },
{
empty,
open,
noCommit,
}: { empty?: boolean; open?: boolean; noCommit?: boolean },
config: Config
): Promise<void> {
const packages = await getPackages(cwd);
Expand Down Expand Up @@ -90,7 +94,7 @@ export default async function add(
config.commit,
cwd
);
if (getAddMessage) {
if (getAddMessage && !noCommit) {
await git.add(path.resolve(changesetBase, `${changesetID}.md`), cwd);
await git.commit(await getAddMessage(newChangeset, commitOpts), cwd);
log(pc.green(`${empty ? "Empty " : ""}Changeset added and committed`));
Expand Down
13 changes: 11 additions & 2 deletions packages/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@ import { run } from "./run";
const args = process.argv.slice(2);

const parsed = mri(args, {
boolean: ["sinceMaster", "verbose", "empty", "open", "gitTag", "snapshot"],
boolean: [
"sinceMaster",
"verbose",
"empty",
"open",
"gitTag",
"snapshot",
"noCommit",
],
string: [
"output",
"otp",
Expand All @@ -21,6 +29,7 @@ const parsed = mri(args, {
// Short flags
v: "verbose",
o: "output",
n: "noCommit",
// Support kebab-case flags
"since-master": "sinceMaster",
"git-tag": "gitTag",
Expand Down Expand Up @@ -52,7 +61,7 @@ if (parsed.help && args.length === 1) {
$ changeset [command]
Commands
init
add [--empty] [--open]
add [--empty] [--open] [--no-commit]
version [--ignore] [--snapshot <?name>] [--snapshot-prerelease-template <template>]
publish [--tag <name>] [--otp <code>] [--no-git-tag]
status [--since <branch>] [--verbose] [--output JSON_FILE.json]
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@
}

if (input.length < 1) {
const { empty, open }: CliOptions = flags;
const { empty, noCommit, open }: CliOptions = flags;

Check warning on line 67 in packages/cli/src/run.ts

View check run for this annotation

Codecov / codecov/patch

packages/cli/src/run.ts#L67

Added line #L67 was not covered by tests
// @ts-ignore if this is undefined, we have already exited
await add(cwd, { empty, open }, config);
await add(cwd, { empty, noCommit, open }, config);

Check warning on line 69 in packages/cli/src/run.ts

View check run for this annotation

Codecov / codecov/patch

packages/cli/src/run.ts#L69

Added line #L69 was not covered by tests
} else if (input[0] !== "pre" && input.length > 1) {
error(
"Too many arguments passed to changesets - we only accept the command name as an argument"
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export type CliOptions = {
tag?: string;
gitTag?: boolean;
open?: boolean;
noCommit?: boolean;
};

export type CommandOptions = CliOptions & {
Expand Down