Skip to content

Commit 07ab50d

Browse files
author
Kyle Smith
committed
Exposed function mergeheadForeach
1 parent 078163c commit 07ab50d

3 files changed

Lines changed: 51 additions & 1 deletion

File tree

generate/input/descriptor.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1759,7 +1759,10 @@
17591759
"ignore": true
17601760
},
17611761
"git_repository_mergehead_foreach": {
1762-
"ignore": true
1762+
"isAsync": true,
1763+
"return": {
1764+
"isErrorCode": true
1765+
}
17631766
},
17641767
"git_repository_message": {
17651768
"ignore": true

lib/repository.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,6 +1200,16 @@ Repository.prototype.fetchheadForeach = function(callback) {
12001200
return fetchheadForeach.call(this, callback, null);
12011201
};
12021202

1203+
var mergeheadForeach = Repository.prototype.mergeheadForeach;
1204+
/**
1205+
* @async
1206+
* @param {MergeheadForeachCb} callback The callback function to be called on
1207+
* each entry
1208+
*/
1209+
Repository.prototype.mergeheadForeach = function(callback) {
1210+
return mergeheadForeach.call(this, callback, null);
1211+
};
1212+
12031213
/**
12041214
* Stages or unstages line selection of a specified file
12051215
*

test/tests/repository.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ var path = require("path");
33
var promisify = require("promisify-node");
44
var fse = promisify(require("fs-extra"));
55
var local = path.join.bind(path, __dirname);
6+
var IndexUtils = require("../utils/index_setup");
7+
var RepoUtils = require("../utils/repository_setup");
68

79
describe("Repository", function() {
810
var NodeGit = require("../../");
@@ -260,4 +262,39 @@ describe("Repository", function() {
260262
});
261263
});
262264
});
265+
266+
it("can get all merge heads in a repo with mergeheadForeach", function() {
267+
var repo;
268+
var repoPath = path.join(__dirname, "..", "repos", "merge-head");
269+
var ourBranchName = "ours";
270+
var theirBranchName = "theirs";
271+
var fileName = "testFile.txt";
272+
var numMergeHeads = 0;
273+
var assertBranchTargetIs = function (theirBranch, mergeHead) {
274+
assert.equal(theirBranch.target(), mergeHead.toString());
275+
numMergeHeads++;
276+
};
277+
278+
return RepoUtils.createRepository(repoPath)
279+
.then(function(_repo) {
280+
repo = _repo;
281+
return IndexUtils.createConflict(
282+
repo,
283+
ourBranchName,
284+
theirBranchName,
285+
fileName
286+
);
287+
})
288+
.then(function() {
289+
return repo.getBranch(theirBranchName);
290+
})
291+
.then(function(theirBranch) {
292+
return repo.mergeheadForeach(
293+
assertBranchTargetIs.bind(this, theirBranch)
294+
);
295+
})
296+
.then(function() {
297+
assert.equal(numMergeHeads, 1);
298+
});
299+
});
263300
});

0 commit comments

Comments
 (0)