1 | var exec = require('child_process').execSync,
|
2 | path = require('path'),
|
3 | gitRootDir = '../',
|
4 |
|
5 | commandWithPath = function(path, args, callback) {
|
6 | args.unshift('git');
|
7 | var cmd = args.join(' ');
|
8 | try {
|
9 | var stdOut = exec(cmd, {cwd:path});
|
10 | return callback(null, stdOut.toString());
|
11 | }
|
12 | catch (error) {
|
13 | try{
|
14 | return callback(error.stderr.toString(), null);
|
15 | }
|
16 | catch (error2) {
|
17 | throw error;
|
18 | }
|
19 | }
|
20 | },
|
21 |
|
22 | command = function(args, callback) {
|
23 | commandWithPath(path.resolve(__dirname, gitRootDir), args, callback);
|
24 | };
|
25 |
|
26 | exports.pull = function(callback) {
|
27 | command(['pull'], callback);
|
28 | };
|
29 |
|
30 | exports.pullWithPath = function(path, callback) {
|
31 | commandWithPath(path, ['pull'], callback);
|
32 | };
|
33 |
|
34 | exports.getSHAOfHead = function(callback) {
|
35 | command(['rev-parse', '--verify', 'HEAD'], callback);
|
36 | };
|
37 |
|
38 | exports.getSHAOfRemoteMaster = function(callback) {
|
39 | command(['rev-parse', '--verify', 'origin/master'], callback);
|
40 | };
|
41 |
|
42 | exports.getCurrentBranchName = function(callback) {
|
43 | command(['symbolic-ref', '--short', 'HEAD'], callback);
|
44 | };
|
45 |
|
46 | exports.clone = function(url, dir, callback) {
|
47 | command(['clone', url, dir], callback);
|
48 | };
|
49 |
|
50 | exports.submoduleUpdate = function(callback) {
|
51 | command(['submodule', 'update', '--init', '--recursive'], callback);
|
52 | };
|