Skip to content

Commit c31ea4e

Browse files
committed
Shallow clone before mutating the options object
1 parent 5fbb55f commit c31ea4e

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

lib/clone.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
var NodeGit = require("../");
2+
var shallowClone = require("./utils/shallow_clone");
23
var normalizeOptions = NodeGit.Utils.normalizeOptions;
34

45
var Clone = NodeGit.Clone;
@@ -17,7 +18,9 @@ Clone.clone = function(url, local_path, options) {
1718
var remoteCallbacks;
1819

1920
if (options) {
21+
options = shallowClone(options);
2022
remoteCallbacks = options.remoteCallbacks;
23+
delete options.remoteCallbacks;
2124
}
2225

2326
options = normalizeOptions(options, NodeGit.CloneOptions);

lib/utils/shallow_clone.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module.exports = function(obj) {
2+
var merges = Array.prototype.slice.call(arguments, 1);
3+
4+
return merges.reduce(function(obj, merge) {
5+
return Object.keys(merge).reduce(function(obj, key) {
6+
obj[key] = merge[key];
7+
return obj;
8+
}, obj);
9+
}, obj || {});
10+
};

0 commit comments

Comments
 (0)