-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
86 lines (78 loc) · 2.45 KB
/
index.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
/*!
* gitclone <https://github.com/tunnckoCore/gitclone>
*
* Copyright (c) 2014-2016 Charlike Mike Reagent <@tunnckoCore> (http://www.tunnckocore.tk)
* Released under the MIT license.
*/
'use strict'
var utils = require('./utils')
/**
* > Clones github repository, optionally
* pass destination folder. By defaults uses HTTPS
* to clone the repository. If you want SSH clone
* you should pass second, third or fourth argument
* boolean `true`, or object `{ssh: true}`.
* Pattern can be `user/repo#branch` as first
* argument. Or first argument `user`, second
* argument `repo`, third `branch`, fourth `ssh`.
*
* **Hint:** All arguments are super flexible and they are handled
* absolutely directly with [gitclone-defaults][],
* so read its [API docs](https://github.com/tunnckoCore/gitclone-defaults#api).
* In addition, you also can pass `callback` as last argument, otherwise
* it will return Spawn stream.
*
* **Example**
*
* ```js
* const gitclone = require('gitclone')
*
* // clones with SSH
* gitclone('node-minibase/minibase', true)
*
* // clone with HTTPS
* gitclone('node-minibase/minibase', (err) => {
* if (err) return console.error(err)
* })
*
* // clone `dev` branch from `verbose/verb` repo
* gitclone('verbose/verb#dev', console.log)
*
* // clone `jonschlinkert/nanomatch` with SSH
* gitclone('jonchlinkert', 'nanomatch', true)
*
* // clone to different destination folder
* gitclone('hybridables/always-done', { dest: 'foobar' })
*
* // clone SSH + dest + branch
* gitclone('verbose/verb', { dest: 'verb0.9.0', branch: 'dev', ssh: true })
* ```
*
* @param {Function} `[callback]` optional, if not given, returns a stream
* @return {Stream} if not `callback` given as last argument - a Spawn stream
* @api public
*/
module.exports = function gitclone () {
var argz = [].slice.call(arguments)
var cb = argz[argz.length - 1]
var opts = utils.gitcloneDefaults.apply(this, argz)
var args = ['clone']
var param = opts.ssh ? '[email protected]:' : 'https://github.com/'
args.push(param + opts.repository + '.git')
if (opts.branch !== 'master') {
args.push('-b')
args.push(opts.branch)
}
if (opts.dest) {
args.push(opts.dest)
}
gitclone.options = gitclone.options && typeof gitclone.options === 'object'
? gitclone.options
: { stdio: [null, null, null] }
var cp = utils.spawn('git', args, gitclone.options)
if (typeof cb === 'function') {
utils.capture(cp, cb)
return
}
return cp
}