Skip to content

Commit b346a97

Browse files
author
John Haley
committed
Add Repository.prototype.fetchheadForeach and tests
1 parent 1dc26c6 commit b346a97

File tree

5 files changed

+53
-6
lines changed

5 files changed

+53
-6
lines changed

generate/input/callbacks.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -371,9 +371,9 @@
371371
],
372372
"return": {
373373
"type": "int",
374-
"noResults": 1,
374+
"noResults": 0,
375375
"success": 0,
376-
"error": -1
376+
"error": 1
377377
}
378378
},
379379
"git_repository_mergehead_foreach_cb": {
@@ -389,9 +389,9 @@
389389
],
390390
"return": {
391391
"type": "int",
392-
"noResults": 1,
392+
"noResults": 0,
393393
"success": 0,
394-
"error": -1
394+
"error": 1
395395
}
396396
},
397397
"git_revwalk_hide_cb": {

generate/input/descriptor.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1456,7 +1456,10 @@
14561456
"ignore": true
14571457
},
14581458
"git_repository_fetchhead_foreach": {
1459-
"ignore": true
1459+
"isAsync": true,
1460+
"return": {
1461+
"isErrorCode": true
1462+
}
14601463
},
14611464
"git_repository_hashfile": {
14621465
"ignore": true

lib/repository.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -843,4 +843,14 @@ Repository.prototype.checkoutBranch = function(branch, opts) {
843843
});
844844
};
845845

846+
var fetchheadForeach = Repository.prototype.fetchheadForeach;
847+
/**
848+
* @async
849+
* @param {FetchheadForeachCb} callback The callback function to be called on
850+
* each entry
851+
*/
852+
Repository.prototype.fetchheadForeach = function(callback) {
853+
return fetchheadForeach.call(this, callback, null);
854+
};
855+
846856
module.exports = Repository;

test/runner.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ beforeEach(function() {
5555

5656
afterEach(function(done) {
5757
process.nextTick(function() {
58-
global.gc();
58+
if (global.gc) {
59+
global.gc();
60+
}
5961
done();
6062
});
6163
});

test/tests/repository.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,36 @@ describe("Repository", function() {
137137
});
138138
});
139139
});
140+
141+
it("gets fetch-heads", function() {
142+
var repo = this.repository;
143+
var foundMaster;
144+
145+
return repo.fetch("origin", {
146+
credentials: function(url, userName) {
147+
return NodeGit.Cred.sshKeyFromAgent(userName);
148+
},
149+
certificateCheck: function() {
150+
return 1;
151+
}
152+
})
153+
.then(function() {
154+
return repo.fetchheadForeach(function(refname, remoteUrl, oid, isMerge) {
155+
if (refname == "refs/heads/master") {
156+
foundMaster = true;
157+
assert.equal(refname, "refs/heads/master");
158+
assert.equal(remoteUrl, "https://github.com/nodegit/test");
159+
assert.equal(
160+
oid.toString(),
161+
"32789a79e71fbc9e04d3eff7425e1771eb595150");
162+
assert.equal(isMerge, 1);
163+
}
164+
});
165+
})
166+
.then(function() {
167+
if (!foundMaster) {
168+
throw new Error("Couldn't find master in iteration of fetch heads");
169+
}
170+
});
171+
});
140172
});

0 commit comments

Comments
 (0)