Skip to content

Commit 7f04086

Browse files
committed
Ensure all options are normalized for proxy options
1 parent 8213d33 commit 7f04086

2 files changed

Lines changed: 83 additions & 5 deletions

File tree

lib/remote.js

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ var _connect = Remote.prototype.connect;
99
var _download = Remote.prototype.download;
1010
var _fetch = Remote.prototype.fetch;
1111
var _push = Remote.prototype.push;
12+
var _upload = Remote.prototype.upload;
1213

1314
/**
1415
* Retrieves the remote by name
@@ -54,24 +55,61 @@ Remote.prototype.connect = function(
5455
* @return {Number} error code
5556
*/
5657
Remote.prototype.download = function(refspecs, opts) {
58+
return _download
59+
.call(this, refspecs, normalizeFetchOptions(opts));
60+
};
61+
62+
/**
63+
* Connects to a remote
64+
*
65+
* @async
66+
* @param {Array} refSpecs The ref specs that should be pushed
67+
* @param {FetchOptions} opts The fetch options for download, contains callbacks
68+
* @param {String} message The message to use for the update reflog messages
69+
* @param {Function} callback
70+
* @return {Number} error code
71+
*/
72+
Remote.prototype.fetch = function(refspecs, opts, reflog_message) {
73+
return _fetch
74+
.call(this, refspecs, normalizeFetchOptions(opts), reflog_message);
75+
};
76+
77+
/**
78+
* Pushes to a remote
79+
*
80+
* @async
81+
* @param {Array} refSpecs The ref specs that should be pushed
82+
* @param {PushOptions} options Options for the checkout
83+
* @param {Function} callback
84+
* @return {Number} error code
85+
*/
86+
Remote.prototype.push = function(refSpecs, opts) {
5787
var callbacks;
88+
var proxyOpts;
5889

5990
if (opts) {
6091
opts = shallowClone(opts);
6192
callbacks = opts.callbacks;
93+
proxyOpts = opts.proxyOpts;
6294
delete opts.callbacks;
95+
delete opts.proxyOpts;
6396
} else {
6497
opts = {};
6598
}
6699

67-
opts = normalizeOptions(opts, NodeGit.FetchOptions);
100+
opts = normalizeOptions(opts, NodeGit.PushOptions);
68101

69102
if (callbacks) {
70103
opts.callbacks =
71104
normalizeOptions(callbacks, NodeGit.RemoteCallbacks);
72105
}
73106

74-
return _download.call(this, refspecs, opts);
107+
if (proxyOpts) {
108+
opts.proxyOpts =
109+
normalizeOptions(proxyOpts, NodeGit.ProxyOptions);
110+
}
111+
112+
return _push.call(this, refSpecs, opts);
75113
};
76114

77115
/**
@@ -85,7 +123,8 @@ Remote.prototype.download = function(refspecs, opts) {
85123
* @return {Number} error code
86124
*/
87125
Remote.prototype.fetch = function(refspecs, opts, reflog_message) {
88-
return _fetch.call(this, refspecs, normalizeFetchOptions(opts), reflog_message);
126+
return _fetch
127+
.call(this, refspecs, normalizeFetchOptions(opts), reflog_message);
89128
};
90129

91130
/**
@@ -97,12 +136,16 @@ Remote.prototype.fetch = function(refspecs, opts, reflog_message) {
97136
* @param {Function} callback
98137
* @return {Number} error code
99138
*/
100-
Remote.prototype.push = function(refSpecs, opts) {
139+
Remote.prototype.upload = function(refSpecs, opts) {
101140
var callbacks;
141+
var proxyOpts;
142+
102143
if (opts) {
103144
opts = shallowClone(opts);
104145
callbacks = opts.callbacks;
146+
proxyOpts = opts.proxyOpts;
105147
delete opts.callbacks;
148+
delete opts.proxyOpts;
106149
} else {
107150
opts = {};
108151
}
@@ -114,5 +157,10 @@ Remote.prototype.push = function(refSpecs, opts) {
114157
normalizeOptions(callbacks, NodeGit.RemoteCallbacks);
115158
}
116159

117-
return _push.call(this, refSpecs, opts);
160+
if (proxyOpts) {
161+
opts.proxyOpts =
162+
normalizeOptions(proxyOpts, NodeGit.ProxyOptions);
163+
}
164+
165+
return _upload.call(this, refSpecs, opts);
118166
};

lib/submodule.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,40 @@
11
var NodeGit = require("../");
2+
var normalizeFetchOptions = NodeGit.Utils.normalizeFetchOptions;
3+
var normalizeOptions = NodeGit.Utils.normalizeOptions;
4+
var shallowClone = NodeGit.Utils.shallowClone;
25

36
var Submodule = NodeGit.Submodule;
47

58
var _foreach = Submodule.foreach;
9+
var _update = Submodule.prototype.update;
610

711
// Override Submodule.foreach to eliminate the need to pass null payload
812
Submodule.foreach = function(repo, callback) {
913
return _foreach(repo, callback, null);
1014
};
15+
16+
/**
17+
* Updates a submodule
18+
*
19+
* @async
20+
* @param {Number} init Setting this to 1 will initialize submodule
21+
* before updating
22+
* @param {SubmoduleUpdateOptions} options Submodule update settings
23+
* @return {Number} 0 on success, any non-zero return value from a callback
24+
*/
25+
Submodule.prototype.update = function(init, options) {
26+
var fetchOpts = normalizeFetchOptions(options && options.fetchOpts);
27+
28+
if (options) {
29+
options = shallowClone(options);
30+
delete options.fetchOpts;
31+
}
32+
33+
options = normalizeOptions(options, NodeGit.SubmoduleUpdateOptions);
34+
35+
if (options) {
36+
options.fetchOpts = fetchOpts;
37+
}
38+
39+
return _update.call(this, init, options);
40+
};

0 commit comments

Comments
 (0)