@@ -4,7 +4,7 @@ const path = require('path');
4
4
const util = require ( 'util' ) ;
5
5
6
6
/**
7
- * @constructor
7
+ * @function Object() { [native code] }
8
8
* @param {number } code Error code.
9
9
* @param {string } message Error message.
10
10
*/
@@ -21,21 +21,21 @@ util.inherits(ProcessError, Error);
21
21
/**
22
22
* Util function for handling spawned processes as promises.
23
23
* @param {string } exe Executable.
24
- * @param {Array. <string> } args Arguments.
24
+ * @param {Array<string> } args Arguments.
25
25
* @param {string } cwd Working directory.
26
26
* @return {Promise } A promise.
27
27
*/
28
28
function spawn ( exe , args , cwd ) {
29
29
return new Promise ( ( resolve , reject ) => {
30
30
const child = cp . spawn ( exe , args , { cwd : cwd || process . cwd ( ) } ) ;
31
31
const buffer = [ ] ;
32
- child . stderr . on ( 'data' , chunk => {
32
+ child . stderr . on ( 'data' , ( chunk ) => {
33
33
buffer . push ( chunk . toString ( ) ) ;
34
34
} ) ;
35
- child . stdout . on ( 'data' , chunk => {
35
+ child . stdout . on ( 'data' , ( chunk ) => {
36
36
buffer . push ( chunk . toString ( ) ) ;
37
37
} ) ;
38
- child . on ( 'close' , code => {
38
+ child . on ( 'close' , ( code ) => {
39
39
const output = buffer . join ( '' ) ;
40
40
if ( code ) {
41
41
const msg = output || 'Process failed: ' + code ;
@@ -50,8 +50,8 @@ function spawn(exe, args, cwd) {
50
50
/**
51
51
* Create an object for executing git commands.
52
52
* @param {string } cwd Repository directory.
53
- * @param {string } exe Git executable (full path if not already on path).
54
- * @constructor
53
+ * @param {string } cmd Git executable (full path if not already on path).
54
+ * @function Object() { [native code] }
55
55
*/
56
56
function Git ( cwd , cmd ) {
57
57
this . cwd = cwd ;
@@ -61,12 +61,12 @@ function Git(cwd, cmd) {
61
61
62
62
/**
63
63
* Execute an arbitrary git command.
64
- * @param {string } var_args Arguments (e.g. 'remote', 'update').
64
+ * @param {Array< string> } args Arguments (e.g. [ 'remote', 'update'] ).
65
65
* @return {Promise } A promise. The promise will be resolved with this instance
66
66
* or rejected with an error.
67
67
*/
68
- Git . prototype . exec = function ( ) {
69
- return spawn ( this . cmd , [ ...arguments ] , this . cwd ) . then ( output => {
68
+ Git . prototype . exec = function ( ... args ) {
69
+ return spawn ( this . cmd , [ ...args ] , this . cwd ) . then ( ( output ) => {
70
70
this . output = output ;
71
71
return this ;
72
72
} ) ;
@@ -76,15 +76,15 @@ Git.prototype.exec = function() {
76
76
* Initialize repository.
77
77
* @return {Promise } A promise.
78
78
*/
79
- Git . prototype . init = function ( ) {
79
+ Git . prototype . init = function ( ) {
80
80
return this . exec ( 'init' ) ;
81
81
} ;
82
82
83
83
/**
84
84
* Clean up unversioned files.
85
85
* @return {Promise } A promise.
86
86
*/
87
- Git . prototype . clean = function ( ) {
87
+ Git . prototype . clean = function ( ) {
88
88
return this . exec ( 'clean' , '-f' , '-d' ) ;
89
89
} ;
90
90
@@ -94,7 +94,7 @@ Git.prototype.clean = function() {
94
94
* @param {string } branch Branch name.
95
95
* @return {Promise } A promise.
96
96
*/
97
- Git . prototype . reset = function ( remote , branch ) {
97
+ Git . prototype . reset = function ( remote , branch ) {
98
98
return this . exec ( 'reset' , '--hard' , remote + '/' + branch ) ;
99
99
} ;
100
100
@@ -103,7 +103,7 @@ Git.prototype.reset = function(remote, branch) {
103
103
* @param {string } remote Remote alias.
104
104
* @return {Promise } A promise.
105
105
*/
106
- Git . prototype . fetch = function ( remote ) {
106
+ Git . prototype . fetch = function ( remote ) {
107
107
return this . exec ( 'fetch' , remote ) ;
108
108
} ;
109
109
@@ -113,7 +113,7 @@ Git.prototype.fetch = function(remote) {
113
113
* @param {string } branch Branch name.
114
114
* @return {Promise } A promise.
115
115
*/
116
- Git . prototype . checkout = function ( remote , branch ) {
116
+ Git . prototype . checkout = function ( remote , branch ) {
117
117
const treeish = remote + '/' + branch ;
118
118
return this . exec ( 'ls-remote' , '--exit-code' , '.' , treeish ) . then (
119
119
( ) => {
@@ -122,7 +122,7 @@ Git.prototype.checkout = function(remote, branch) {
122
122
. then ( ( ) => this . clean ( ) )
123
123
. then ( ( ) => this . reset ( remote , branch ) ) ;
124
124
} ,
125
- error => {
125
+ ( error ) => {
126
126
if ( error instanceof ProcessError && error . code === 2 ) {
127
127
// branch doesn't exist, create an orphan
128
128
return this . exec ( 'checkout' , '--orphan' , branch ) ;
@@ -136,10 +136,10 @@ Git.prototype.checkout = function(remote, branch) {
136
136
137
137
/**
138
138
* Remove all unversioned files.
139
- * @param {string| string[] } files Files argument.
139
+ * @param {string | Array< string> } files Files argument.
140
140
* @return {Promise } A promise.
141
141
*/
142
- Git . prototype . rm = function ( files ) {
142
+ Git . prototype . rm = function ( files ) {
143
143
if ( ! Array . isArray ( files ) ) {
144
144
files = [ files ] ;
145
145
}
@@ -148,10 +148,10 @@ Git.prototype.rm = function(files) {
148
148
149
149
/**
150
150
* Add files.
151
- * @param {string| string[] } files Files argument.
151
+ * @param {string | Array< string> } files Files argument.
152
152
* @return {Promise } A promise.
153
153
*/
154
- Git . prototype . add = function ( files ) {
154
+ Git . prototype . add = function ( files ) {
155
155
if ( ! Array . isArray ( files ) ) {
156
156
files = [ files ] ;
157
157
}
@@ -163,7 +163,7 @@ Git.prototype.add = function(files) {
163
163
* @param {string } message Commit message.
164
164
* @return {Promise } A promise.
165
165
*/
166
- Git . prototype . commit = function ( message ) {
166
+ Git . prototype . commit = function ( message ) {
167
167
return this . exec ( 'diff-index' , '--quiet' , 'HEAD' ) . catch ( ( ) =>
168
168
this . exec ( 'commit' , '-m' , message )
169
169
) ;
@@ -174,7 +174,7 @@ Git.prototype.commit = function(message) {
174
174
* @param {string } name Name of tag.
175
175
* @return {Promise } A promise.
176
176
*/
177
- Git . prototype . tag = function ( name ) {
177
+ Git . prototype . tag = function ( name ) {
178
178
return this . exec ( 'tag' , name ) ;
179
179
} ;
180
180
@@ -185,7 +185,7 @@ Git.prototype.tag = function(name) {
185
185
* @param {boolean } force Force push.
186
186
* @return {Promise } A promise.
187
187
*/
188
- Git . prototype . push = function ( remote , branch , force ) {
188
+ Git . prototype . push = function ( remote , branch , force ) {
189
189
const args = [ 'push' , '--tags' , remote , branch ] ;
190
190
if ( force ) {
191
191
args . push ( '--force' ) ;
@@ -198,9 +198,9 @@ Git.prototype.push = function(remote, branch, force) {
198
198
* @param {string } remote Remote alias.
199
199
* @return {Promise<string> } A promise for the remote URL.
200
200
*/
201
- Git . prototype . getRemoteUrl = function ( remote ) {
201
+ Git . prototype . getRemoteUrl = function ( remote ) {
202
202
return this . exec ( 'config' , '--get' , 'remote.' + remote + '.url' )
203
- . then ( git => {
203
+ . then ( ( git ) => {
204
204
const repo = git . output && git . output . split ( / [ \n \r ] / ) . shift ( ) ;
205
205
if ( repo ) {
206
206
return repo ;
@@ -210,7 +210,7 @@ Git.prototype.getRemoteUrl = function(remote) {
210
210
) ;
211
211
}
212
212
} )
213
- . catch ( err => {
213
+ . catch ( ( err ) => {
214
214
throw new Error (
215
215
'Failed to get remote.' +
216
216
remote +
@@ -225,9 +225,11 @@ Git.prototype.getRemoteUrl = function(remote) {
225
225
226
226
/**
227
227
* Delete ref to remove branch history
228
- * @param {string } branch
228
+ * @param {string } branch The branch name.
229
+ * @return {Promise } A promise. The promise will be resolved with this instance
230
+ * or rejected with an error.
229
231
*/
230
- Git . prototype . deleteRef = function ( branch ) {
232
+ Git . prototype . deleteRef = function ( branch ) {
231
233
return this . exec ( 'update-ref' , '-d' , 'refs/heads/' + branch ) ;
232
234
} ;
233
235
@@ -240,7 +242,7 @@ Git.prototype.deleteRef = function(branch) {
240
242
* @return {Promise<Git> } A promise.
241
243
*/
242
244
Git . clone = function clone ( repo , dir , branch , options ) {
243
- return fs . exists ( dir ) . then ( exists => {
245
+ return fs . exists ( dir ) . then ( ( exists ) => {
244
246
if ( exists ) {
245
247
return Promise . resolve ( new Git ( dir , options . git ) ) ;
246
248
} else {
@@ -255,17 +257,17 @@ Git.clone = function clone(repo, dir, branch, options) {
255
257
'--origin' ,
256
258
options . remote ,
257
259
'--depth' ,
258
- options . depth
260
+ options . depth ,
259
261
] ;
260
262
return spawn ( options . git , args )
261
- . catch ( err => {
263
+ . catch ( ( err ) => {
262
264
// try again without branch or depth options
263
265
return spawn ( options . git , [
264
266
'clone' ,
265
267
repo ,
266
268
dir ,
267
269
'--origin' ,
268
- options . remote
270
+ options . remote ,
269
271
] ) ;
270
272
} )
271
273
. then ( ( ) => new Git ( dir , options . git ) ) ;
0 commit comments