Skip to content

Commit

Permalink
Skip git repo check in commands that do not rely on git (#803)
Browse files Browse the repository at this point in the history
  • Loading branch information
noherczeg authored and evocateur committed May 4, 2017
1 parent 7b72210 commit 64a01ac
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Command.js
Expand Up @@ -129,6 +129,10 @@ export default class Command {
return this._execOpts;
}

get requiresGit() {
return true;
}

// Override this to inherit config from another command.
// For example `updated` inherits config from `publish`.
get otherCommandConfigs() {
Expand Down Expand Up @@ -175,7 +179,7 @@ export default class Command {
}

runValidations() {
if (!GitUtilities.isInitialized(this.execOpts)) {
if (this.requiresGit && !GitUtilities.isInitialized(this.execOpts)) {
log.error("ENOGIT", "This is not a git repository, did you already run `git init` or `lerna init`?");
this._complete(null, 1);
return;
Expand Down
4 changes: 4 additions & 0 deletions src/commands/BootstrapCommand.js
Expand Up @@ -41,6 +41,10 @@ export const builder = {
};

export default class BootstrapCommand extends Command {
get requiresGit() {
return false;
}

initialize(callback) {
const { registry, npmClient } = this.options;

Expand Down
4 changes: 4 additions & 0 deletions src/commands/CleanCommand.js
Expand Up @@ -21,6 +21,10 @@ export const builder = {
};

export default class CleanCommand extends Command {
get requiresGit() {
return false;
}

initialize(callback) {
this.directoriesToDelete = this.filteredPackages.map((pkg) => pkg.nodeModulesLocation);

Expand Down
4 changes: 4 additions & 0 deletions src/commands/ExecCommand.js
Expand Up @@ -21,6 +21,10 @@ export const builder = {
};

export default class ExecCommand extends Command {
get requiresGit() {
return false;
}

initialize(callback) {
this.command = this.input[0];
this.args = this.input.slice(1);
Expand Down
4 changes: 4 additions & 0 deletions src/commands/LsCommand.js
Expand Up @@ -15,6 +15,10 @@ export const describe = "List all public packages";
export const builder = {};

export default class LsCommand extends Command {
get requiresGit() {
return false;
}

initialize(callback) {
// Nothing to do...
callback(null, true);
Expand Down
4 changes: 4 additions & 0 deletions src/commands/RunCommand.js
Expand Up @@ -27,6 +27,10 @@ export const builder = {
};

export default class RunCommand extends Command {
get requiresGit() {
return false;
}

initialize(callback) {
this.script = this.input[0];
this.args = this.input.slice(1);
Expand Down
11 changes: 11 additions & 0 deletions test/integration/__snapshots__/lerna-bootstrap.test.js.snap
Expand Up @@ -74,3 +74,14 @@ cli package-2 OK
package-3 cli1 OK
package-3 cli2 package-2 OK"
`;

exports[`simple-no-git-check: stdout 1`] = `
"lerna info version __TEST_VERSION__
lerna info Bootstrapping 4 packages
lerna info lifecycle preinstall
lerna info Installing external dependencies
lerna info Symlinking packages and binaries
lerna info lifecycle postinstall
lerna info lifecycle prepublish
lerna success Bootstrapped 4 packages"
`;
13 changes: 13 additions & 0 deletions test/integration/lerna-bootstrap.test.js
@@ -1,10 +1,12 @@
import execa from "execa";
import getPort from "get-port";
import globby from "globby";
import tempy from "tempy";
import normalizePath from "normalize-path";

import { LERNA_BIN } from "../helpers/constants";
import initFixture from "../helpers/initFixture";
import copyFixture from "../helpers/copyFixture";

describe("lerna bootstrap", () => {
describe("from CLI", () => {
Expand Down Expand Up @@ -33,6 +35,17 @@ describe("lerna bootstrap", () => {
expect(stderr).toMatchSnapshot("ignore: stderr");
});

test.concurrent("git repo check is ignored by default", async () => {
const cwd = await tempy.directoryAsync();
await copyFixture(cwd, "BootstrapCommand/integration");
const args = [
"bootstrap",
];

const stderr = await execa.stderr(LERNA_BIN, args, { cwd });
expect(stderr).toMatchSnapshot("simple-no-git-check: stdout");
});

test.concurrent("--npm-client yarn", async () => {
const cwd = await initFixture("BootstrapCommand/integration");
const args = [
Expand Down

0 comments on commit 64a01ac

Please sign in to comment.