Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better gitGetVersion #1183

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions components/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,12 @@ class AppViewModel {
this.latestVersion(version.latestVersion);
this.showNewVersionAvailable(!ungit.config.ungitVersionCheckOverride && version.outdated);
}).catch((e) => this.server.unhandledRejection(e));
this.server.getPromise('/gitversion')
.then((gitversion) => {
if (gitversion && !gitversion.satisfied) {
this.gitVersionError(gitversion.error);

const minGitVersion = '>=1.8.0'
this.server.getPromise('/gitversion', {requiredGitVersion: minGitVersion})
.then((result) => {
if (result && !result.satisfied) {
this.gitVersionError(`Ungit requires git ${minGitVersion}, found ${result.type} ${result.version}`);
}
}).catch((e) => this.server.unhandledRejection(e));
}
Expand Down
8 changes: 7 additions & 1 deletion source/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,13 @@ app.get('/api/latestversion', (req, res) => {
app.get('/api/ping', (req, res) => res.json({}));

app.get('/api/gitversion', (req, res) => {
sysinfo.getGitVersionInfo().then((result) => res.json(result));
sysinfo.getGitVersionInfo().then((result) => {
res.json({
satisfied: semver.satisfies(result, req.query.requiredGitVersion),
version: result,
type: 'git'
})
});
});

const userConfigPath = path.join(config.homedir, '.ungitrc');
Expand Down
18 changes: 1 addition & 17 deletions source/sysinfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,5 @@ exports.getUserHash = () => {
}

exports.getGitVersionInfo = () => {
const result = {
requiredVersion: '>=1.8.x',
version: 'unkown',
satisfied: false
};

if (!config.gitVersion) {
result.error = `Failed to parse git version number. Note that Ungit requires git version ${result.requiredVersion}`;
} else {
result.version = config.gitVersion;
result.satisfied = semver.satisfies(result.version, result.requiredVersion);
if (!result.satisfied) {
result.error = `Ungit requires git version ${result.requiredVersion}, you are currently running ${result.version}`;
}
}

return Bluebird.resolve(result);
return Bluebird.resolve(config.gitVersion);
}
8 changes: 8 additions & 0 deletions test/spec.sysinfo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const expect = require('expect.js');
const sysinfo = require('../src/sysinfo');

describe('sysinfo', () => {
it('returns the gitversion', () => {
sysinfo.getGitVersionInfo().then((version) => expect(version).to.match(/\d+\.\d+\.\d+/))
});
});