Skip to content

Commit

Permalink
fix(publish): Pass explicit list of files to checkout instead of globs
Browse files Browse the repository at this point in the history
Fixes #1786
  • Loading branch information
evocateur committed Nov 28, 2018
1 parent 1c142db commit a4c57c2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
7 changes: 4 additions & 3 deletions commands/publish/__tests__/git-checkout.test.js
Expand Up @@ -6,11 +6,12 @@ const path = require("path");
const initFixture = require("@lerna-test/init-fixture")(__dirname);
const gitCheckout = require("../lib/git-checkout");

test("gitCheckout", async () => {
test("gitCheckout files", async () => {
const cwd = await initFixture("normal-no-inter-dependencies");
const files = ["package-1", "package-2"].map(name => path.join("packages", name, "package.json"));

await fs.writeJSON(path.join(cwd, "packages", "package-1", "package.json"), { foo: "bar" });
await gitCheckout("packages/*/package.json", { cwd });
await Promise.all(files.map(fp => fs.writeJSON(path.join(cwd, fp), { foo: "bar" })));
await gitCheckout(files, { cwd });

const modified = await execa.stdout("git", ["ls-files", "--modified"], { cwd });
expect(modified).toBe("");
Expand Down
12 changes: 6 additions & 6 deletions commands/publish/index.js
Expand Up @@ -413,12 +413,12 @@ class PublishCommand extends Command {
resetChanges() {
// the package.json files are changed (by gitHead if not --canary)
// and we should always leave the working tree clean
return pReduce(this.project.packageConfigs, (_, pkgGlob) =>
gitCheckout(`${pkgGlob}/package.json`, this.execOpts)
).then(() =>
// --skip-git should not leave unstaged changes behind
gitCheckout(this.project.manifest.location, this.execOpts)
);
const { cwd } = this.execOpts;
const dirtyManifests = [this.project.manifest]
.concat(this.packagesToPublish)
.map(pkg => path.relative(cwd, pkg.manifestLocation));

return gitCheckout(dirtyManifests, this.execOpts);
}

execScript(pkg, script) {
Expand Down
6 changes: 3 additions & 3 deletions commands/publish/lib/git-checkout.js
Expand Up @@ -5,8 +5,8 @@ const childProcess = require("@lerna/child-process");

module.exports = gitCheckout;

function gitCheckout(fileGlob, opts) {
log.silly("gitCheckout", fileGlob);
function gitCheckout(files, opts) {
log.silly("gitCheckout", files);

return childProcess.exec("git", ["checkout", "--", fileGlob], opts);
return childProcess.exec("git", ["checkout", "--"].concat(files), opts);
}

0 comments on commit a4c57c2

Please sign in to comment.