FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Expose mergehead_foreach by smith-kyle · Pull Request #937 · nodegit/nodegit · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .js  (4) .json  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
5 changes: 4 additions & 1 deletion generate/input/descriptor.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1759,7 +1759,10 @@
"ignore": true
},
"git_repository_mergehead_foreach": {
"ignore": true
"isAsync": true,
"return": {
"isErrorCode": true
}
},
"git_repository_message": {
"ignore": true
Expand Down
10 changes: 10 additions & 0 deletions lib/repository.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1200,6 +1200,16 @@ Repository.prototype.fetchheadForeach = function(callback) {
return fetchheadForeach.call(this, callback, null);
};

var mergeheadForeach = Repository.prototype.mergeheadForeach;
/**
* @async
* @param {MergeheadForeachCb} callback The callback function to be called on
* each entry
*/
Repository.prototype.mergeheadForeach = function(callback) {
return mergeheadForeach.call(this, callback, null);
};

/**
* Stages or unstages line selection of a specified file
*
Expand Down
6 changes: 5 additions & 1 deletion test/tests/index.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ describe("Index", function() {

it("can add a conflict to the index", function() {
var repo;
var repoPath = path.join(__dirname, "..", "repos", "index");
var repoPath = local("../repos/index");
var ourBranchName = "ours";
var theirBranchName = "theirs";
var fileName = "testFile.txt";
Expand All @@ -329,6 +329,10 @@ describe("Index", function() {
fileName
);
})
.then(function(index) {
assert.ok(index.hasConflicts());
return index.conflictGet(fileName);
})
.then(function(indexEntries) {
// Store all indexEntries for conflict
ancestorIndexEntry = indexEntries.ancestor_out;
Expand Down
46 changes: 46 additions & 0 deletions test/tests/repository.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ var path = require("path");
var promisify = require("promisify-node");
var fse = promisify(require("fs-extra"));
var local = path.join.bind(path, __dirname);
var IndexUtils = require("../utils/index_setup");
var RepoUtils = require("../utils/repository_setup");

describe("Repository", function() {
var NodeGit = require("../../");
Expand Down Expand Up @@ -260,4 +262,48 @@ describe("Repository", function() {
});
});
});

it("can get all merge heads in a repo with mergeheadForeach", function() {
var repo;
var repoPath = local("../repos/merge-head");
var ourBranchName = "ours";
var theirBranchName = "theirs";
var theirBranch;
var fileName = "testFile.txt";
var numMergeHeads = 0;
var assertBranchTargetIs = function (theirBranch, mergeHead) {
assert.equal(theirBranch.target(), mergeHead.toString());
numMergeHeads++;
};

return RepoUtils.createRepository(repoPath)
.then(function(_repo) {
repo = _repo;
return IndexUtils.createConflict(
repo,
ourBranchName,
theirBranchName,
fileName
);
})
.then(function() {
return repo.getBranch(theirBranchName);
})
.then(function(_theirBranch) {
// Write the MERGE_HEAD file manually since createConflict does not
theirBranch = _theirBranch;
return fse.writeFile(
path.join(repoPath, ".git", "MERGE_HEAD"),
theirBranch.target().toString() + "\n"
);
})
.then(function() {
return repo.mergeheadForeach(
assertBranchTargetIs.bind(this, theirBranch)
);
})
.then(function() {
assert.equal(numMergeHeads, 1);
});
});
});
22 changes: 7 additions & 15 deletions test/utils/index_setup.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
var assert = require("assert");
var NodeGit = require("../../");
var path = require("path");
var promisify = require("promisify-node");
Expand Down Expand Up @@ -75,25 +74,18 @@ var IndexSetup = {
return repository.createCommit(ourBranch.name(), ourSignature,
ourSignature, "we made a commit", oid, [ourCommit]);
})
.then(function(commitOid) {
var opts = {
checkoutStrategy: NodeGit.Checkout.STRATEGY.FORCE
};

return NodeGit.Checkout.head(repository, opts);
.then(function() {
return repository.checkoutBranch(
ourBranch,
new NodeGit.CheckoutOptions()
);
})
.then(function() {
return repository.mergeBranches(ourBranchName, theirBranchName);
})
.then(function(commit) {
assert.fail(commit, undefined,
"The index should have been thrown due to merge conflicts");
})
.catch(function(index) {
assert.ok(index);
assert.ok(index.hasConflicts());

return index.conflictGet(fileName);
return NodeGit.Checkout.index(repository, index)
.then(function() { return index; });
});
}
};
Expand Down

Back | FazBrowse Home | New Git URL