1 | var childProcess = require('child_process');
|
2 |
|
3 | var async = require('async');
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | function 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 |
|
34 | module.exports = {
|
35 | checkRepoUpToDate: checkRepoUpToDate
|
36 | }; |
\ | No newline at end of file |