From f69164f41c2a9e4d90afc314ef01608793547337 Mon Sep 17 00:00:00 2001 From: John Haley Date: Wed, 20 May 2015 16:27:35 -0700 Subject: [PATCH 1/2] Add `git_index_conflict_get` and test --- generate/input/descriptor.json | 16 ++++- test/tests/index.js | 127 +++++++++++++++++++++++++++++++++ 2 files changed, 142 insertions(+), 1 deletion(-) diff --git a/generate/input/descriptor.json b/generate/input/descriptor.json index 7c3907615..1e835fee2 100644 --- a/generate/input/descriptor.json +++ b/generate/input/descriptor.json @@ -847,7 +847,21 @@ } }, "git_index_conflict_get": { - "ignore": true + "isAsync": true, + "args": { + "ancestor_out": { + "isReturn": true + }, + "our_out": { + "isReturn": true + }, + "their_out": { + "isReturn": true + } + }, + "return": { + "isErrorCode": true + } }, "git_index_conflict_iterator_free": { "ignore": true diff --git a/test/tests/index.js b/test/tests/index.js index f073977eb..43cb8bb3c 100644 --- a/test/tests/index.js +++ b/test/tests/index.js @@ -15,6 +15,17 @@ describe("Index", function() { var reposPath = local("../repos/workdir"); + var addFileToIndex = function(repository, fileName) { + return repository.openIndex() + .then(function(index) { + index.read(1); + index.addByPath(fileName); + index.write(); + + return index.writeTree(); + }); + }; + beforeEach(function() { var test = this; @@ -154,4 +165,120 @@ describe("Index", function() { return fse.remove(path.join(repo.workdir(), fileNames[1])); }); }); + + it("can get a conflict from the index", function() { + var fileName = "everyonesFile.txt"; + var rebaseReposPath = local("../repos/rebase"); + var ourBranchName = "ours"; + var theirBranchName = "theirs"; + + var baseFileContent = "How do you feel about Toll Roads?\n"; + var ourFileContent = "I like Toll Roads. I have an EZ-Pass!\n"; + var theirFileContent = "I'm skeptical about Toll Roads\n"; + + var ourSignature = NodeGit.Signature.create + ("Ron Paul", "RonPaul@TollRoadsRBest.info", 123456789, 60); + var theirSignature = NodeGit.Signature.create + ("Greg Abbott", "Gregggg@IllTollYourFace.us", 123456789, 60); + + var repository; + var ourCommit; + var ourBranch; + var theirBranch; + + return Repository.init(rebaseReposPath, 0) + .then(function(repo) { + repository = repo; + return fse.writeFile(path.join(repository.workdir(), fileName), + baseFileContent); + }) + .then(function() { + return addFileToIndex(repository, fileName); + }) + .then(function(oid) { + assert.equal(oid.toString(), + "044704f62399fecbe22da6d7d47b14e52625630e"); + + return repository.createCommit("HEAD", ourSignature, + ourSignature, "initial commit", oid, []); + }) + .then(function(commitOid) { + assert.equal(commitOid.toString(), + "80111c46ac73b857a3493b24c81df08639b5de99"); + + return repository.getCommit(commitOid).then(function(commit) { + ourCommit = commit; + }).then(function() { + return repository.createBranch(ourBranchName, commitOid) + .then(function(branch) { + ourBranch = branch; + return repository.createBranch(theirBranchName, commitOid); + }); + }); + }) + .then(function(branch) { + theirBranch = branch; + return fse.writeFile(path.join(repository.workdir(), fileName), + baseFileContent + theirFileContent); + }) + .then(function() { + return addFileToIndex(repository, fileName); + }) + .then(function(oid) { + assert.equal(oid.toString(), + "b826e989aca7647bea64810f0a2a38acbbdd4c1a"); + + return repository.createCommit(theirBranch.name(), theirSignature, + theirSignature, "they made a commit", oid, [ourCommit]); + }) + .then(function(commitOid) { + assert.equal(commitOid.toString(), + "b3c355bb606ec7da87174dfa1a0b0c0e3dc97bc0"); + + return fse.writeFile(path.join(repository.workdir(), fileName), + baseFileContent + ourFileContent); + }) + .then(function() { + return addFileToIndex(repository, fileName); + }) + .then(function(oid) { + assert.equal(oid.toString(), + "e7fe41bf7c0c28766887a63ffe2f03f624276fbe"); + + return repository.createCommit(ourBranch.name(), ourSignature, + ourSignature, "we made a commit", oid, [ourCommit]); + }) + .then(function(commitOid) { + assert.equal(commitOid.toString(), + "28cfeb17f66132edb3c4dacb7ff38e8dd48a1844"); + + var opts = { + checkoutStrategy: NodeGit.Checkout.STRATEGY.FORCE + }; + + return NodeGit.Checkout.head(repository, opts); + }) + .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); + }) + .then(function(conflict) { + var keys = Object.keys(conflict); + + assert.equal(keys.length, 3); + + keys.forEach(function(key) { + assert(conflict[key] instanceof NodeGit.IndexEntry); + }); + }); + }); }); From 6ef323280bdaa36ee29c5f2c9c1d036ae64abdef Mon Sep 17 00:00:00 2001 From: John Haley Date: Wed, 20 May 2015 18:08:16 -0700 Subject: [PATCH 2/2] Made the `Index.conflictGet` test a little better --- test/tests/index.js | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/test/tests/index.js b/test/tests/index.js index 43cb8bb3c..171439f31 100644 --- a/test/tests/index.js +++ b/test/tests/index.js @@ -272,13 +272,24 @@ describe("Index", function() { return index.conflictGet(fileName); }) .then(function(conflict) { - var keys = Object.keys(conflict); + var promises = []; - assert.equal(keys.length, 3); + promises.push(repository.getBlob(conflict.ancestor_out.id) + .then(function(blob) { + assert.equal(blob.toString(), baseFileContent); + })); - keys.forEach(function(key) { - assert(conflict[key] instanceof NodeGit.IndexEntry); - }); + promises.push(repository.getBlob(conflict.our_out.id) + .then(function(blob) { + assert.equal(blob.toString(), baseFileContent + ourFileContent); + })); + + promises.push(repository.getBlob(conflict.their_out.id) + .then(function(blob) { + assert.equal(blob.toString(), baseFileContent + theirFileContent); + })); + + return Promise.all(promises); }); }); });