Skip to content

Commit 23562fe

Browse files
author
John Haley
committed
Fix Repository.prototype.fetchAll
It turns out that the promise chain was messed up with doing a fetch-all with multiple remotes. This should fix it. Additionally it will append the name of the remote onto all of the callbacks so the caller can know which callback is for what remote.
1 parent 006c001 commit 23562fe

File tree

3 files changed

+48
-15
lines changed

3 files changed

+48
-15
lines changed

generate/templates/templates/nodegit.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ var importExtension = function(name) {
7171
rawApi.Utils = {};
7272
require("./utils/lookup_wrapper");
7373
require("./utils/normalize_options");
74+
require("./utils/shallow_clone");
7475

7576
// Load up extra types;
7677
require("./convenient_line");

lib/repository.js

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ var Blob = NodeGit.Blob;
44
var Checkout = NodeGit.Checkout;
55
var Commit = NodeGit.Commit;
66
var normalizeOptions = NodeGit.Utils.normalizeOptions;
7+
var shallowClone = NodeGit.Utils.shallowClone;
78
var Reference = NodeGit.Reference;
89
var Remote = NodeGit.Remote;
910
var Repository = NodeGit.Repository;
@@ -648,22 +649,49 @@ Repository.prototype.fetchAll = function(
648649
{
649650
var repo = this;
650651

651-
return repo.getRemotes().then(function(remotes) {
652-
var fetchPromise = Promise.resolve();
652+
function createCallbackWrapper(fn, remote) {
653+
return function() {
654+
var args = Array.prototype.slice.call(arguments);
655+
args.push(remote);
653656

654-
remotes.forEach(function(remote) {
655-
fetchPromise.then(function() {
656-
repo.fetch(remote, remoteCallbacks, autoTag, pruneAfter, callback);
657-
});
658-
});
657+
return fn.apply(this, args);
658+
}.bind(this);
659+
}
659660

660-
return fetchPromise
661-
.then(function() {
662-
if (typeof callback === "function") {
663-
callback();
661+
remoteCallbacks = remoteCallbacks || {};
662+
663+
var credentials = remoteCallbacks.credentials;
664+
var certificateCheck = remoteCallbacks.certificateCheck;
665+
var transferProgress = remoteCallbacks.transferProgress;
666+
667+
return repo.getRemotes()
668+
.then(function(remotes) {
669+
return Promise.all(remotes.map(function(remote) {
670+
var wrappedRemoteCallbacks = shallowClone(remoteCallbacks);
671+
672+
if (credentials) {
673+
wrappedRemoteCallbacks.credentials =
674+
createCallbackWrapper(credentials, remote);
664675
}
665-
});
666-
}, callback);
676+
677+
if (certificateCheck) {
678+
wrappedRemoteCallbacks.certificateCheck =
679+
createCallbackWrapper(certificateCheck, remote);
680+
}
681+
682+
if (transferProgress) {
683+
wrappedRemoteCallbacks.transferProgress =
684+
createCallbackWrapper(transferProgress, remote);
685+
}
686+
687+
return repo.fetch(remote, wrappedRemoteCallbacks, autoTag, pruneAfter);
688+
}));
689+
})
690+
.then(function() {
691+
if (typeof callback === "function") {
692+
callback();
693+
}
694+
});
667695
};
668696

669697
/**

lib/utils/shallow_clone.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
module.exports = function(obj) {
1+
var NodeGit = require("../../");
2+
3+
function shallowClone(obj) {
24
var merges = Array.prototype.slice.call(arguments, 1);
35

46
return merges.reduce(function(obj, merge) {
@@ -7,4 +9,6 @@ module.exports = function(obj) {
79
return obj;
810
}, obj);
911
}, obj || {});
10-
};
12+
}
13+
14+
NodeGit.Utils.shallowClone = module.exports = shallowClone;

0 commit comments

Comments
 (0)