Skip to content

Commit

Permalink
Merge pull request #1784 from themadtitanmathos/fix/remote-callbacks-…
Browse files Browse the repository at this point in the history
…pointer-cleanup

Remote needs to persist the callback/proxyOpts/headers
  • Loading branch information
implausible committed Jul 28, 2020
2 parents 69b010a + d5ad62c commit b7c1259
Showing 1 changed file with 48 additions and 1 deletion.
49 changes: 48 additions & 1 deletion lib/remote.js
Expand Up @@ -8,6 +8,7 @@ var shallowClone = NodeGit.Utils.shallowClone;
var Remote = NodeGit.Remote;
var _connect = Remote.prototype.connect;
var _createWithOpts = Remote.createWithOpts;
var _disconnect = Remote.prototype.disconnect;
var _download = Remote.prototype.download;
var _fetch = Remote.prototype.fetch;
var _push = Remote.prototype.push;
Expand Down Expand Up @@ -45,14 +46,60 @@ Remote.prototype.connect = function(
proxyOpts = normalizeOptions(proxyOpts || {}, NodeGit.ProxyOptions);
customHeaders = customHeaders || [];

return _connect.call(this, direction, callbacks, proxyOpts, customHeaders);
return _connect.call(this, direction, callbacks, proxyOpts, customHeaders)
.then(() => {
// Save options on the remote object. If we don't do this,
// the options may be cleaned up and cause a segfault
// when Remote.prototype.connect is called.
Object.defineProperties(this, {
callbacks: {
configurable: true,
value: callbacks,
writable: false
},
proxyOpts: {
configurable: true,
value: proxyOpts,
writable: false
},
customHeaders: {
configurable: true,
value: customHeaders,
writable: false
}
});
});
};

Remote.createWithOpts = function(url, options) {
return _createWithOpts(url, normalizeOptions(
options, NodeGit.RemoteCreateOptions));
};

Remote.prototype.disconnect = function() {
return _disconnect.call(this)
.then(() => {
// Release the options
Object.defineProperties(this, {
callbacks: {
configurable: true,
value: undefined,
writable: false
},
proxyOpts: {
configurable: true,
value: undefined,
writable: false
},
customHeaders: {
configurable: true,
value: undefined,
writable: false
}
});
});
};

/**
* Connects to a remote
*
Expand Down

0 comments on commit b7c1259

Please sign in to comment.