1 |
|
2 | var debug, exec;
|
3 |
|
4 | exec = require('child_process').exec;
|
5 |
|
6 | debug = require('debug')("git");
|
7 |
|
8 | module.exports = function(dir) {
|
9 | var options;
|
10 | debug("initialized for: " + dir);
|
11 | options = {
|
12 | cwd: dir
|
13 | };
|
14 | return {
|
15 | dir: dir,
|
16 | isClean: function(callback) {
|
17 | debug("isClean");
|
18 | return exec('git status --untracked-files=all --porcelain', options, function(error, stdout, stderror) {
|
19 | return callback(stdout.length === 0, stdout != null ? stdout.trim() : void 0);
|
20 | });
|
21 | },
|
22 | getSha: function(callback) {
|
23 | debug('getSha');
|
24 | return exec('git rev-parse HEAD', options, function(error, stdout, stderror) {
|
25 | return callback(error, stdout != null ? stdout.trim() : void 0);
|
26 | });
|
27 | },
|
28 | commit: function(message, callback) {
|
29 | debug("commit - " + message);
|
30 | return exec("git add CHANGELOG.md package.json && git commit -m '" + message + "'", options, function(error, stdout, stderror) {
|
31 | return callback(!error);
|
32 | });
|
33 | },
|
34 | diffSinceLastTag: function(callback) {
|
35 | debug("diffSinceLastTag");
|
36 | return exec("git log --oneline $(git describe --tags --abbrev=0)..HEAD", options, function(error, stdout, stderr) {
|
37 | return callback(error, stdout);
|
38 | });
|
39 | },
|
40 | tag: function(tag, callback) {
|
41 | debug("tag - " + tag);
|
42 | return exec("git tag -a " + tag + " -m " + tag, options, function(error, stdout, stderror) {
|
43 | return callback(error);
|
44 | });
|
45 | },
|
46 | branch: function(callback) {
|
47 | debug("branch");
|
48 | return exec("git rev-parse --abbrev-ref HEAD", options, function(error, stdout, stderr) {
|
49 | return callback(error, stdout);
|
50 | });
|
51 | },
|
52 | push: function(branch, callback) {
|
53 | debug("push - " + branch);
|
54 | return exec("git push origin " + branch, options, function(error, stdout, stderror) {
|
55 | return callback(error);
|
56 | });
|
57 | },
|
58 | pushTag: function(tag, callback) {
|
59 | debug("pushTag - " + tag);
|
60 | return exec("git push origin tag " + tag, options, function(error, stdout, stderror) {
|
61 | return callback(error);
|
62 | });
|
63 | }
|
64 | };
|
65 | };
|