Skip to content

Commit a4ead57

Browse files
committed
Build test for reference list
1 parent b46ba8c commit a4ead57

2 files changed

Lines changed: 87 additions & 3 deletions

File tree

lib/remote.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,21 +114,21 @@ Remote.prototype.push = function(refSpecs, opts) {
114114
};
115115

116116
/**
117-
* Lists advertised heads from remote
117+
* Lists advertised references from a remote
118118
*
119119
* @async
120120
* @param {RemoteCallbacks} callbacks The callback functions for the connection
121121
* @param {ProxyOptions} proxyOpts Proxy settings
122122
* @param {Array<string>} customHeaders extra HTTP headers to use
123123
* @param {Function} callback
124-
* @return {Number} error code
124+
* @return {Promise}
125125
*/
126126
Remote.prototype.referenceList = function(
127127
callbacks,
128128
proxyOpts,
129129
customHeaders
130130
) {
131-
callbacks = normalizeOptions(callbacks, NodeGit.RemoteCallbacks);
131+
callbacks = normalizeOptions(callbacks || {}, NodeGit.RemoteCallbacks);
132132
proxyOpts = normalizeOptions(proxyOpts || {}, NodeGit.ProxyOptions);
133133
customHeaders = customHeaders || [];
134134

test/tests/remote.js

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ var assert = require("assert");
22
var path = require("path");
33
var local = path.join.bind(path, __dirname);
44
var _ = require("lodash");
5+
var fp = require("lodash/fp");
56

67
var garbageCollect = require("../utils/garbage_collect.js");
78

@@ -444,4 +445,87 @@ describe("Remote", function() {
444445
Remote.getSelfFreeingInstanceCount());
445446
});
446447
});
448+
449+
it("can retrieve the list of references advertised by a remote", function() {
450+
var expectedRemoteHeads = {
451+
HEAD: {
452+
local: 0,
453+
oid: "32789a79e71fbc9e04d3eff7425e1771eb595150",
454+
loid: "0000000000000000000000000000000000000000",
455+
name: "HEAD",
456+
symrefTarget: "refs/heads/master"
457+
},
458+
"refs/heads/checkout-test": {
459+
local: 0,
460+
oid: "1729c73906bb8467f4095c2f4044083016b4dfde",
461+
loid: "0000000000000000000000000000000000000000",
462+
name: "refs/heads/checkout-test",
463+
symrefTarget: null
464+
},
465+
"refs/heads/master": {
466+
local: 0,
467+
oid: "32789a79e71fbc9e04d3eff7425e1771eb595150",
468+
loid: "0000000000000000000000000000000000000000",
469+
name: "refs/heads/master",
470+
symrefTarget: null
471+
},
472+
"refs/heads/rev-walk": {
473+
local: 0,
474+
oid: "32789a79e71fbc9e04d3eff7425e1771eb595150",
475+
loid: "0000000000000000000000000000000000000000",
476+
name: "refs/heads/rev-walk",
477+
symrefTarget: null
478+
},
479+
"refs/tags/annotated-tag": {
480+
local: 0,
481+
oid: "dc800017566123ff3c746b37284a24a66546667e",
482+
loid: "0000000000000000000000000000000000000000",
483+
name: "refs/tags/annotated-tag",
484+
symrefTarget: null
485+
},
486+
"refs/tags/annotated-tag^{}": {
487+
local: 0,
488+
oid: "32789a79e71fbc9e04d3eff7425e1771eb595150",
489+
loid: "0000000000000000000000000000000000000000",
490+
name: "refs/tags/annotated-tag^{}",
491+
symrefTarget: null
492+
},
493+
"refs/tags/light-weight-tag": {
494+
local: 0,
495+
oid: "32789a79e71fbc9e04d3eff7425e1771eb595150",
496+
loid: "0000000000000000000000000000000000000000",
497+
name: "refs/tags/light-weight-tag",
498+
symrefTarget: null
499+
}
500+
};
501+
502+
return this.repository.getRemote("origin")
503+
.then(function(remote) {
504+
return remote.referenceList();
505+
})
506+
.then(function(remoteHeads) {
507+
var remoteHeadsBySha = fp.flow([
508+
fp.map(function(remoteHead) {
509+
return {
510+
local: remoteHead.local(),
511+
oid: remoteHead.oid().toString(),
512+
loid: remoteHead.loid().toString(),
513+
name: remoteHead.name(),
514+
symrefTarget: remoteHead.symrefTarget()
515+
};
516+
}),
517+
fp.keyBy("name")
518+
])(remoteHeads);
519+
520+
fp.flow([
521+
fp.keys,
522+
fp.forEach(function(remoteHeadName) {
523+
assert(fp.isEqual(
524+
expectedRemoteHeads[remoteHeadName],
525+
remoteHeadsBySha[remoteHeadName]
526+
), "Expectations for head " + remoteHeadName + " were not met.");
527+
})
528+
])(expectedRemoteHeads);
529+
});
530+
});
447531
});

0 commit comments

Comments
 (0)