Skip to content

Commit

Permalink
Fix version command not committing when commit config option is set (#…
Browse files Browse the repository at this point in the history
…437)

* Fix version command not committing when commit config option is set

* Update packages/cli/src/commands/version/version.test.ts

Co-authored-by: Mitchell Hamilton <mitchell@hamil.town>
  • Loading branch information
Blasz and emmatown committed Aug 13, 2020
1 parent 077bcd4 commit efd01d9
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/silent-planes-smoke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@changesets/cli": patch
---

Fix version command not committing when commit config option is set
14 changes: 8 additions & 6 deletions packages/cli/src/commands/version/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ export default async function version(
},
config: Config
) {
const releaseConfig = {
...config,
// Disable committing when in snapshot mode
commit: options.snapshot ? false : config.commit
};
const [changesets, preState] = await Promise.all([
readChangesets(cwd),
readPreState(cwd),
Expand Down Expand Up @@ -61,22 +66,19 @@ export default async function version(
let releasePlan = assembleReleasePlan(
changesets,
packages,
config,
releaseConfig,
preState,
options.snapshot
);

await applyReleasePlan(
releasePlan,
packages,
{
...config,
commit: false
},
releaseConfig,
options.snapshot
);

if (options.snapshot !== undefined && config.commit) {
if (releaseConfig.commit) {
log("All files have been updated and committed. You're ready to publish!");
} else {
log("All files have been updated. Review them and commit at your leisure");
Expand Down
56 changes: 56 additions & 0 deletions packages/cli/src/commands/version/version.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,41 @@ describe("running version in a simple project", () => {
);
});

it("should not commit the result if commit config is not set", async () => {
await writeChangesets([simpleChangeset2], cwd);
const spy = jest.spyOn(git, "commit");

expect(spy).not.toHaveBeenCalled();

await versionCommand(cwd, defaultOptions, modifiedDefaultConfig);

expect(spy).not.toHaveBeenCalled();
});

it("should commit the result if commit config is set", async () => {
await writeChangesets([simpleChangeset2], cwd);
const spy = jest.spyOn(git, "commit");

expect(spy).not.toHaveBeenCalled();

await versionCommand(cwd, defaultOptions, {
...modifiedDefaultConfig,
commit: true
});

expect(spy).toHaveBeenCalled();
expect(spy.mock.calls[0][0]).toMatchInlineSnapshot(`
"RELEASING: Releasing 2 package(s)
Releases:
pkg-a@1.1.0
pkg-b@1.0.1
[skip ci]
"
`);
});

describe("when there are multiple changeset commits", () => {
it("should bump releasedPackages", async () => {
await writeChangesets([simpleChangeset, simpleChangeset2], cwd);
Expand Down Expand Up @@ -351,6 +386,27 @@ describe("snapshot release", () => {
);
});

it("should not commit the result even if commit config is set", async () => {
let cwd = f.copy("simple-project");
await writeChangesets([simpleChangeset2], cwd);
const spy = jest.spyOn(git, "commit");

expect(spy).not.toHaveBeenCalled();

await versionCommand(
cwd,
{
snapshot: "exprimental"
},
{
...modifiedDefaultConfig,
commit: true
}
);

expect(spy).not.toHaveBeenCalled();
});

describe("useCalculatedVersionForSnapshots: true", () => {
it("should update packages using calculated version", async () => {
let cwd = f.copy("simple-project");
Expand Down

0 comments on commit efd01d9

Please sign in to comment.