Skip to content

Commit 59fba4f

Browse files
committed
Fixed ghost update --force to jump to next major if you are on latest v1
refs #759
1 parent 83ba097 commit 59fba4f

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

lib/utils/resolve-version.js

+13-11
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,15 @@ module.exports = function resolveVersion(version, activeVersion, v1 = false, for
2929
}
3030

3131
return yarn(['info', 'ghost', 'versions', '--json']).then((result) => {
32-
let comparator = !force && activeVersion ? `>${activeVersion}` : MIN_RELEASE;
32+
let comparator;
33+
34+
if (!force && activeVersion) {
35+
comparator = `>${activeVersion}`;
36+
} else if (force && activeVersion) {
37+
comparator = `>=${activeVersion}`;
38+
} else {
39+
comparator = MIN_RELEASE;
40+
}
3341

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

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

58-
if (v1 && activeVersion && semver.satisfies(activeVersion, '^2.0.0')) {
59-
return Promise.reject(new errors.CliError({
60-
message: 'You can\'t downgrade from v2 to v1 using these options.',
61-
help: 'Please run "ghost update --rollback".'
62-
}));
63-
}
64-
6566
// CASE: you haven't passed `--v1` and you are not about to install a fresh blog
6667
if (!v1 && activeVersion) {
6768
const majorVersionJump = semver.major(activeVersion) !== semver.major(versionToReturn);
6869

69-
// CASE: use latest v1 release
70-
if (majorVersionJump && force) {
70+
// CASE 1: you want to force update and you are not on the latest v1 version
71+
// CASE 2: you don't use force and you are not on the latest v1 version
72+
if (majorVersionJump && force && versions.length > 1) {
7173
while (!semver.satisfies(versionToReturn, '^1.0.0')) {
7274
versionToReturn = versions.pop();
7375
}
74-
} else if (majorVersionJump && versions.length) {
76+
} else if (majorVersionJump && !force && versions.length) {
7577
return Promise.reject(new errors.CliError({
7678
message: 'You are about to migrate to Ghost 2.0. Your blog is not on the latest Ghost 1.0 version.',
7779
help: 'Please run "ghost update --v1".'

test/unit/utils/resolve-version-spec.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,12 @@ describe('Unit: resolveVersion', function () {
166166
});
167167
});
168168

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

172172
return resolveVersion(null, '1.25.2', false, true)
173173
.then(function (version) {
174-
expect(version).to.eql('1.25.2');
174+
expect(version).to.eql('2.0.0');
175175
});
176176
});
177177

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

0 commit comments

Comments
 (0)