forked from nodegit/nodegit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubmodule.js
More file actions
51 lines (42 loc) · 1.36 KB
/
submodule.js
File metadata and controls
51 lines (42 loc) · 1.36 KB
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
var NodeGit = require("../");
var normalizeFetchOptions = NodeGit.Utils.normalizeFetchOptions;
var normalizeOptions = NodeGit.Utils.normalizeOptions;
var shallowClone = NodeGit.Utils.shallowClone;
var Submodule = NodeGit.Submodule;
var _foreach = Submodule.foreach;
var _update = Submodule.prototype.update;
// Override Submodule.foreach to eliminate the need to pass null payload
Submodule.foreach = function(repo, callback) {
return _foreach(repo, callback, null);
};
/**
* Updates a submodule
*
* @async
* @param {Number} init Setting this to 1 will initialize submodule
* before updating
* @param {SubmoduleUpdateOptions} options Submodule update settings
* @return {Number} 0 on success, any non-zero return value from a callback
*/
Submodule.prototype.update = function(init, options) {
var fetchOpts;
var checkoutOpts;
if (options) {
options = shallowClone(options);
fetchOpts = options.fetchOpts;
checkoutOpts = options.checkoutOpts;
delete options.fetchOpts;
delete options.checkoutOpts;
}
options = normalizeOptions(options, NodeGit.SubmoduleUpdateOptions);
if (fetchOpts) {
options.fetchOpts = normalizeFetchOptions(fetchOpts);
}
if (checkoutOpts) {
options.checkoutOpts = normalizeOptions(
checkoutOpts,
NodeGit.CheckoutOptions
);
}
return _update.call(this, init, options);
};