@unclepaul/allcountjs
Version:
The open source framework for rapid business application development with Node.js
25 lines (21 loc) • 907 B
JavaScript
//var nodegit = require('nodegit');
var childProcess = require('child_process');
var Q = require('q');
module.exports = function () {
var service = {};
service.checkForUpdates = function (repositoryDir) {
return getRepositoryHeadSha(repositoryDir).then(function (currentHead) {
return Q.nfcall(childProcess.exec, 'git pull origin master', {cwd: repositoryDir, timeout: 30000}).then(function () {
return getRepositoryHeadSha(repositoryDir);
}).then(function (updatedHead) {
return currentHead !== updatedHead;
});
})
};
function getRepositoryHeadSha(repositoryDir) {
return Q.nfcall(childProcess.exec, 'git rev-parse HEAD', {cwd: repositoryDir, timeout: 30000}).then(function (commitInfo) {
return commitInfo[0].trim();
});
}
return service;
};