forked from dash-/git-wrapper2-promise
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommands.js
133 lines (113 loc) · 2.51 KB
/
commands.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*
* Checks to see if this is a git repository
**/
var isRepo = exports.isRepo = function(){
return this.exec('status').then(function() {
return true;
}).catch(function(childProcess) {
var err;
if(! childProcess.stderr) {
err = childProcess;
throw err;
}
if(childProcess.code === 128) {
return false;
}
throw new Error(childProcess.stderr.toString());
});
};
/*
* Clone the repository.
**/
var clone = exports.clone = function(repo, dir){
var args = [repo, dir];
return this.spawn('clone', args);
};
/*
* Pull latest from the repository.
**/
var pull = exports.pull = function(remote, branch){
if(typeof remote == 'function') {
callback = remote;
remote = 'origin';
branch = 'master';
} else if(typeof branch == 'function') {
callback = branch;
branch = 'master';
}
var args = [remote, branch];
return this.spawn('pull', args);
};
/*
* Add files for a commit.
**/
var add = exports.add = function(which){
var cmd = 'add', args = [which];
return this.spawn(cmd, args);
};
/*
* Remove files for a commit.
**/
var rm = exports.rm = function(which) {
which = Array.isArray(which) ? which : [which];
return this.spawn('rm', which);
};
/*
* Commit the repo.
**/
var commit = exports.commit = function(msg, args){
args = (args || []).concat(['-m', msg]);
return this.spawn('commit', args);
};
/*
* Push to master
**/
var push = exports.push = function(remote, branch){
if(typeof remote == 'undefined') {
remote = 'origin';
branch = 'master';
} else if(typeof branch == 'undefined') {
branch = 'master';
}
var args = [remote, branch];
return this.spawn('push', args);
};
/*
* Save - Does commit and push at once.
**/
exports.save = function(msg, commitargs){
var that = this ;
return that.add('-A').then(function() {
return that.commit(msg, commitargs);
}).then(function() {
return that.push();
});
};
/*
* Call `git log`, optionally with arguments.
**/
exports.log = function(args) {
args = args || [];
return this.spawn('log', args);
};
/*
* Calls `git branch`.
*/
exports.branch = function(name, args) {
args = (args || []).concat([name]);
return this.spawn('branch', args);
};
/*
* Calls `git checkout`.
*/
exports.checkout = function(branch, args) {
args = (args || []).concat([branch]);
return this.spawn('checkout', args);
};
/*
* Calls `git show`.
*/
exports.show = function(sha1, file, args) {
args = (args || []).concat([sha1 + ':' + file]);
return this.spawn('show', args);
};