Skip to content

Commit

Permalink
refactor(publish): DRY verification of working tree cleanliness
Browse files Browse the repository at this point in the history
  • Loading branch information
evocateur committed Jan 9, 2019
1 parent 2580e72 commit 5e975e0
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions commands/publish/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ class PublishCommand extends Command {

let chain = Promise.resolve();

// attempting to publish a release with local changes is not allowed
chain = chain.then(() => this.verifyWorkingTreeClean());
chain = chain.then(() => this.findVersionedUpdates());

return chain.then(result => {
Expand Down Expand Up @@ -190,6 +192,10 @@ class PublishCommand extends Command {
});
}

verifyWorkingTreeClean() {
return describeRef(this.execOpts).then(checkWorkingTree.throwIfUncommitted);
}

findVersionedUpdates() {
let chain = Promise.resolve();

Expand All @@ -206,19 +212,12 @@ class PublishCommand extends Command {
return chain;
}

verifyWorkingTreeClean() {
return describeRef(this.execOpts).then(checkWorkingTree.throwIfUncommitted);
}

detectFromGit() {
const { tagVersionPrefix = "v" } = this.options;
const matchingPattern = this.project.isIndependent() ? "*@*" : `${tagVersionPrefix}*.*.*`;

let chain = Promise.resolve();

// attempting to publish a tagged release with local changes is not allowed
chain = chain.then(() => this.verifyWorkingTreeClean());

chain = chain.then(() => getCurrentTags(this.execOpts, matchingPattern));
chain = chain.then(taggedPackageNames => {
if (!taggedPackageNames.length) {
Expand Down Expand Up @@ -248,9 +247,6 @@ class PublishCommand extends Command {
detectFromPackage() {
let chain = Promise.resolve();

// attempting to publish a release with local changes is not allowed
chain = chain.then(() => this.verifyWorkingTreeClean());

chain = chain.then(() => getUnpublishedPackages(this.project, this.conf.snapshot));
chain = chain.then(unpublishedPackages => {
if (!unpublishedPackages.length) {
Expand Down Expand Up @@ -286,9 +282,6 @@ class PublishCommand extends Command {

let chain = Promise.resolve();

// attempting to publish a canary release with local changes is not allowed
chain = chain.then(() => this.verifyWorkingTreeClean());

// find changed packages since last release, if any
chain = chain.then(() =>
collectUpdates(this.packageGraph.rawPackageList, this.packageGraph, this.execOpts, {
Expand Down

0 comments on commit 5e975e0

Please sign in to comment.