Skip to content

Commit

Permalink
fix(version): Skip working tree validation when `--no-git-tag-version…
Browse files Browse the repository at this point in the history
…` passed

This matches the behavior of `npm version --no-git-tag-version`. Use at your own risk.

Fixes #1613
  • Loading branch information
evocateur committed Aug 28, 2018
1 parent 9df88a4 commit bd948cc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
19 changes: 18 additions & 1 deletion commands/version/__tests__/version-command.test.js
Expand Up @@ -36,7 +36,10 @@ const collectUpdatesActual = require.requireActual("@lerna/collect-updates");

// assertion helpers
const listDirty = cwd =>
execa("git", ["diff", "--name-only"], { cwd }).then(result => result.stdout.split("\n").filter(Boolean));
// git ls-files --exclude-standard --modified --others
execa("git", ["ls-files", "--exclude-standard", "--modified", "--others"], { cwd }).then(result =>
result.stdout.split("\n").filter(Boolean)
);

// stabilize commit SHA
expect.addSnapshotSerializer(require("@lerna-test/serialize-git-sha"));
Expand Down Expand Up @@ -243,6 +246,20 @@ describe("VersionCommand", () => {
expect(logMessages).toContain("Skipping git tag/commit");
expect(logMessages).toContain("--skip-git has been replaced by --no-git-tag-version --no-push");
});

it("skips dirty working tree validation", async () => {
const testDir = await initFixture("normal");
await fs.outputFile(path.join(testDir, "packages/package-1/hello.js"), "world");
await lernaVersion(testDir)("--no-git-tag-version");

expect(checkWorkingTree).not.toBeCalled();

const logMessages = loggingOutput("warn");
expect(logMessages).toContain("Skipping working tree validation, proceed at your own risk");

const unstaged = await listDirty(testDir);
expect(unstaged).toContain("packages/package-1/hello.js");
});
});

describe("--no-push", () => {
Expand Down
4 changes: 3 additions & 1 deletion commands/version/index.js
Expand Up @@ -154,8 +154,10 @@ class VersionCommand extends Command {
];

// amending a commit probably means the working tree is dirty
if (amend !== true) {
if (this.commitAndTag && amend !== true) {
tasks.unshift(() => checkWorkingTree(this.execOpts));
} else {
this.logger.warn("version", "Skipping working tree validation, proceed at your own risk");
}

return pWaterfall(tasks);
Expand Down

0 comments on commit bd948cc

Please sign in to comment.