Skip to content

Commit

Permalink
fix(v2): ensure ghost update --force correctly jumps to v2
Browse files Browse the repository at this point in the history
refs #759
  • Loading branch information
kirrg001 authored and acburdine committed Aug 16, 2018
1 parent eae5e97 commit 27d0473
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
24 changes: 13 additions & 11 deletions lib/utils/resolve-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,15 @@ module.exports = function resolveVersion(version, activeVersion, v1 = false, for
}

return yarn(['info', 'ghost', 'versions', '--json']).then((result) => {
let comparator = !force && activeVersion ? `>${activeVersion}` : MIN_RELEASE;
let comparator;

if (!force && activeVersion) {
comparator = `>${activeVersion}`;
} else if (force && activeVersion) {
comparator = `>=${activeVersion}`;
} else {
comparator = MIN_RELEASE;
}

if (v1) {
comparator += ' <2.0.0';
Expand All @@ -55,23 +63,17 @@ module.exports = function resolveVersion(version, activeVersion, v1 = false, for

let versionToReturn = version || versions.pop();

if (v1 && activeVersion && semver.satisfies(activeVersion, '^2.0.0')) {
return Promise.reject(new errors.CliError({
message: 'You can\'t downgrade from v2 to v1 using these options.',
help: 'Please run "ghost update --rollback".'
}));
}

// CASE: you haven't passed `--v1` and you are not about to install a fresh blog
if (!v1 && activeVersion) {
const majorVersionJump = semver.major(activeVersion) !== semver.major(versionToReturn);

// CASE: use latest v1 release
if (majorVersionJump && force) {
// CASE 1: you want to force update and you are not on the latest v1 version
// CASE 2: you don't use force and you are not on the latest v1 version
if (majorVersionJump && force && versions.length > 1) {
while (!semver.satisfies(versionToReturn, '^1.0.0')) {
versionToReturn = versions.pop();
}
} else if (majorVersionJump && versions.length) {
} else if (majorVersionJump && !force && versions.length) {
return Promise.reject(new errors.CliError({
message: 'You are about to migrate to Ghost 2.0. Your blog is not on the latest Ghost 1.0 version.',
help: 'Please run "ghost update --v1".'
Expand Down
6 changes: 3 additions & 3 deletions test/unit/utils/resolve-version-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,12 @@ describe('Unit: resolveVersion', function () {
});
});

it('force updating', function () {
it('force updating and you are on the latest v1', function () {
stubYarn('{"data": ["1.23.0", "1.25.1", "1.25.2", "2.0.0"]}');

return resolveVersion(null, '1.25.2', false, true)
.then(function (version) {
expect(version).to.eql('1.25.2');
expect(version).to.eql('2.0.0');
});
});

Expand Down Expand Up @@ -202,7 +202,7 @@ describe('Unit: resolveVersion', function () {
})
.catch(function (error) {
expect(error).to.be.an.instanceOf(Error);
expect(error.message).to.equal('You can\'t downgrade from v2 to v1 using these options.');
expect(error.message).to.equal('No valid versions found.');
});
});

Expand Down

0 comments on commit 27d0473

Please sign in to comment.