From b346a97cc59a6ee63fb8fcf013efd05b0f4d8be7 Mon Sep 17 00:00:00 2001 From: John Haley Date: Thu, 26 Mar 2015 13:17:52 -0700 Subject: [PATCH] Add `Repository.prototype.fetchheadForeach` and tests --- generate/input/callbacks.json | 8 ++++---- generate/input/descriptor.json | 5 ++++- lib/repository.js | 10 ++++++++++ test/runner.js | 4 +++- test/tests/repository.js | 32 ++++++++++++++++++++++++++++++++ 5 files changed, 53 insertions(+), 6 deletions(-) diff --git a/generate/input/callbacks.json b/generate/input/callbacks.json index 46dbb4654..02cd33838 100644 --- a/generate/input/callbacks.json +++ b/generate/input/callbacks.json @@ -371,9 +371,9 @@ ], "return": { "type": "int", - "noResults": 1, + "noResults": 0, "success": 0, - "error": -1 + "error": 1 } }, "git_repository_mergehead_foreach_cb": { @@ -389,9 +389,9 @@ ], "return": { "type": "int", - "noResults": 1, + "noResults": 0, "success": 0, - "error": -1 + "error": 1 } }, "git_revwalk_hide_cb": { diff --git a/generate/input/descriptor.json b/generate/input/descriptor.json index 76fd9a99f..0d3a1b81d 100644 --- a/generate/input/descriptor.json +++ b/generate/input/descriptor.json @@ -1456,7 +1456,10 @@ "ignore": true }, "git_repository_fetchhead_foreach": { - "ignore": true + "isAsync": true, + "return": { + "isErrorCode": true + } }, "git_repository_hashfile": { "ignore": true diff --git a/lib/repository.js b/lib/repository.js index 57191e6d8..2c9058269 100644 --- a/lib/repository.js +++ b/lib/repository.js @@ -843,4 +843,14 @@ Repository.prototype.checkoutBranch = function(branch, opts) { }); }; +var fetchheadForeach = Repository.prototype.fetchheadForeach; +/** + * @async + * @param {FetchheadForeachCb} callback The callback function to be called on + * each entry + */ +Repository.prototype.fetchheadForeach = function(callback) { + return fetchheadForeach.call(this, callback, null); +}; + module.exports = Repository; diff --git a/test/runner.js b/test/runner.js index d3fe8ced3..8a4ff378f 100644 --- a/test/runner.js +++ b/test/runner.js @@ -55,7 +55,9 @@ beforeEach(function() { afterEach(function(done) { process.nextTick(function() { - global.gc(); + if (global.gc) { + global.gc(); + } done(); }); }); diff --git a/test/tests/repository.js b/test/tests/repository.js index 42006be03..4062e1440 100644 --- a/test/tests/repository.js +++ b/test/tests/repository.js @@ -137,4 +137,36 @@ describe("Repository", function() { }); }); }); + + it("gets fetch-heads", function() { + var repo = this.repository; + var foundMaster; + + return repo.fetch("origin", { + credentials: function(url, userName) { + return NodeGit.Cred.sshKeyFromAgent(userName); + }, + certificateCheck: function() { + return 1; + } + }) + .then(function() { + return repo.fetchheadForeach(function(refname, remoteUrl, oid, isMerge) { + if (refname == "refs/heads/master") { + foundMaster = true; + assert.equal(refname, "refs/heads/master"); + assert.equal(remoteUrl, "https://github.com/nodegit/test"); + assert.equal( + oid.toString(), + "32789a79e71fbc9e04d3eff7425e1771eb595150"); + assert.equal(isMerge, 1); + } + }); + }) + .then(function() { + if (!foundMaster) { + throw new Error("Couldn't find master in iteration of fetch heads"); + } + }); + }); });