Skip to content

Commit

Permalink
Show warning in UI for bad git versions. Fixes FredrikNoren#406
Browse files Browse the repository at this point in the history
  • Loading branch information
FredrikNoren committed Jul 29, 2014
1 parent a749fcf commit 2fe07b3
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 51 deletions.
31 changes: 1 addition & 30 deletions bin/ungit
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ var config = require('../source/config');
var open = require('open');
var path = require('path');
var child_process = require('child_process');
var semver = require('semver');
var async = require('async');

var BugTracker = require('../source/bugtracker');
Expand Down Expand Up @@ -70,31 +69,6 @@ function startupListener(data) {

child.on('stdout', startupListener);

function verifyGitVersion(callback) {
child_process.exec('git --version', function(err, stdout, stderr) {

if (err) {
callback('Can\'t run "git --version". Is git installed and available in your path?');
} else {
var versionSearch = /.*?(\d+[.]\d+[.]\d+).*/.exec(stdout);
var requiredVersion = '>=1.8.x';
if (!versionSearch || config.gitVersionCheckOverride) {
console.log('Failed to parse git version number: ', stdout);
console.log('Note that Ungit requires git version ' + requiredVersion);
console.log('Start ungit with --gitVersionCheckOverride (or set that option to true in your .ungitrc) to override this check.');
return callback();
}
var version = versionSearch[1];
if (!semver.satisfies(version, requiredVersion)) {
callback('Ungit requires git version ' + requiredVersion + ', you are currently running ' + version +'. Start ungit with --gitVersionCheckOverride (or set that option to true in your .ungitrc) to override this check. ');
} else {
callback();
}
}

});
}

function checkIfUngitIsRunning(callback) {
// Fastest way to find out if a port is used or not/i.e. if ungit is running
var net = require('net');
Expand All @@ -119,9 +93,6 @@ checkIfUngitIsRunning(function(err1, ungitRunning) {
});
}
else {
verifyGitVersion(function(err) {
if (err) console.log(err);
else child.start();
});
child.start();
}
});
5 changes: 5 additions & 0 deletions components/app/app.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
<div class="app-wrapper">

<div class="container" data-bind="shown: shown" data-ta-container="app">
<div class="alert alert-danger" data-bind="visible: gitVersionErrorVisible">
<span data-bind="text: gitVersionError"></span>
<button type="button" class="close" data-bind="click: dismissGitVersionError">&times;</button>
</div>

<div class="alert alert-info" data-bind="visible: newVersionAvailable">
A new version of ungit (<span data-bind="text: latestVersion"></span>) is available! Run <code data-bind="text: newVersionInstallCommand"></code> to install. (You are currently running version <span data-bind="text: currentVersion"></span>.)
<button type="button" class="close" data-dismiss="alert">&times;</button>
Expand Down
15 changes: 15 additions & 0 deletions components/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ var AppViewModel = function(appContainer, server) {
return !self.bugtrackingEnabled() && !self.bugtrackingNagscreenDismissed();
});

this.gitVersionErrorDismissed = ko.observable(localStorage.getItem('gitVersionErrorDismissed'));
this.gitVersionError = ko.observable();
this.gitVersionErrorVisible = ko.computed(function() {
return !ungit.config.gitVersionCheckOverride && self.gitVersionError() && !self.gitVersionErrorDismissed();
});

var NPSSurveyLastDismissed = parseInt(localStorage.getItem('NPSSurveyLastDismissed') || '0');
var monthsSinceNPSLastDismissed = (Date.now() - NPSSurveyLastDismissed) / (1000 * 60 * 60 * 24 * 30);
this.showNPSSurvey = ko.observable(monthsSinceNPSLastDismissed >= 6 && Math.random() < 0.01);
Expand Down Expand Up @@ -70,6 +76,11 @@ AppViewModel.prototype.shown = function() {
self.latestVersion(version.latestVersion);
self.newVersionAvailable(version.outdated);
});
this.server.get('/gitversion', undefined, function(err, gitversion) {
if (!gitversion.satisfied) {
self.gitVersionError(gitversion.error);
}
});
}
AppViewModel.prototype.updateAnimationFrame = function(deltaT) {
if (this.content() && this.content().updateAnimationFrame) this.content().updateAnimationFrame(deltaT);
Expand Down Expand Up @@ -141,6 +152,10 @@ AppViewModel.prototype.dismissBugtrackingNagscreen = function() {
localStorage.setItem('bugtrackingNagscreenDismissed', true);
this.bugtrackingNagscreenDismissed(true);
}
AppViewModel.prototype.dismissGitVersionError = function() {
localStorage.setItem('gitVersionErrorDismissed', true);
this.gitVersionErrorDismissed(true);
}
AppViewModel.prototype.dismissNPSSurvey = function() {
this.showNPSSurvey(false);
localStorage.setItem('NPSSurveyLastDismissed', Date.now());
Expand Down
22 changes: 2 additions & 20 deletions source/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ var defaultConfig = {
// "pluginConfigs": { "gerrit": { "disabled": true } }
pluginConfigs: {},

// Git version check override
// Don't show errors when the user is using a bad or undecidable git version
gitVersionCheckOverride: false,

// Automatically does stash -> operation -> stash pop when you checkout, reset or cherry pick. This makes it
Expand All @@ -104,19 +104,6 @@ function getUserHome() {
return process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE;
}

function getInvalidOption() {
for (var key in argv) {
if (key === '$0' || key === '_') {
// do nothing
} else {
if (!defaultConfig[key]) {
return key;
}
}
}
return null;
}

// Works for now but should be moved to bin/ungit
var argv = optimist
.usage('ungit [-v] [-b] [--cliconfigonly] [--gitVersionCheckOverride]')
Expand All @@ -128,8 +115,6 @@ var argv = optimist
.describe('v', 'Display ungit versions')
.argv;

var invalidOption = getInvalidOption();

if (argv.help) {
optimist.showHelp();
process.exit(0);
Expand All @@ -142,9 +127,6 @@ if (argv.help) {
defaultConfig,
argv
]);
} else if (invalidOption) {
console.log('unknown option(s) for ungit: ' + invalidOption);
process.exit(0);
}else {
} else {
module.exports = rc('ungit', defaultConfig, argv);
}
6 changes: 6 additions & 0 deletions source/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,12 @@ app.get('/api/ping', function(req, res) {
res.json({});
});

app.get('/api/gitversion', function(req, res) {
sysinfo.getGitVersionInfo(function(result) {
res.json(result);
});
});

function getUserHome() {
return process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE || "/tmp";
}
Expand Down
34 changes: 33 additions & 1 deletion source/sysinfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var path = require('path');
var cache = require('./utils/cache');
var getmac = require('getmac');
var md5 = require('blueimp-md5').md5;
var semver = require('semver');

var sysinfo = exports;

Expand Down Expand Up @@ -53,4 +54,35 @@ sysinfo.getUserHash = function(callback) {
getmac.getMac(function(err, addr) {
callback(err, md5(addr));
});
}
}

sysinfo.getGitVersionInfo = function(callback) {
child_process.exec('git --version', function(err, stdout, stderr) {
var result = {
requiredVersion: '>=1.8.x',
version: 'unkown',
satisfied: false
};

if (err) {
result.error = 'Can\'t run "git --version". Is git installed and available in your path?';
} else {
var versionSearch = /.*?(\d+[.]\d+[.]\d+).*/.exec(stdout);
if (!versionSearch) {
result.error =
'Failed to parse git version number: ' + stdout + '. ' +
'Note that Ungit requires git version ' + result.requiredVersion;
} else {
result.version = versionSearch[1];
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;
}
}
}

callback(result);

});
}

0 comments on commit 2fe07b3

Please sign in to comment.