UNPKG

1.34 kBJavaScriptView Raw
1var childProcess = require('child_process');
2
3var async = require('async');
4
5/**
6 * Checks if the git repo in the specified directory is up to date with origin/master
7 * @param directory {string} full path to the directory of the git repo
8 * @param callback {function} callback(err, upToDate)
9 */
10function checkRepoUpToDate(directory, callback) {
11
12 async.auto({
13 fetch: [function(next) {
14 childProcess.exec('git fetch', {cwd: directory}, function (err, stdout, stderr) {
15 next(err);
16 });
17 }],
18 localCommitDate: ['fetch', function(next) {
19 childProcess.exec('git log --pretty=format:\'%ad\' -n 1 master', {cwd: directory}, function (err, stdout, stderr) {
20 next(err, stdout);
21 });
22 }],
23 masterCommitDate: ['fetch', function(next) {
24 childProcess.exec('git log --pretty=format:\'%ad\' -n 1 origin/master', {cwd: directory}, function (err, stdout, stderr) {
25 next(err, stdout);
26 });
27 }]
28 }, function(err, results) {
29 var upToDate = !err && results.localCommitDate && results.masterCommitDate && Date.parse(results.localCommitDate) >= Date.parse(results.masterCommitDate);
30 callback(err, upToDate);
31 });
32}
33
34module.exports = {
35 checkRepoUpToDate: checkRepoUpToDate
36};
\No newline at end of file