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

Merge pull request #586 from nodegit/index-conflicts · nodegit/nodegit@6be369b · GitHub

Repository navigation

Commit 6be369b

Browse files
committed
Merge pull request #586 from nodegit/index-conflicts
Add `git_index_conflict_get` and test
2 parents 13d804c + 6ef3232 commit 6be369b

2 files changed

Lines changed: 153 additions & 1 deletion

File tree

‎generate/input/descriptor.json‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -847,7 +847,21 @@
847847
}
848848
},
849849
"git_index_conflict_get": {
850-
"ignore": true
850+
"isAsync": true,
851+
"args": {
852+
"ancestor_out": {
853+
"isReturn": true
854+
},
855+
"our_out": {
856+
"isReturn": true
857+
},
858+
"their_out": {
859+
"isReturn": true
860+
}
861+
},
862+
"return": {
863+
"isErrorCode": true
864+
}
851865
},
852866
"git_index_conflict_iterator_free": {
853867
"ignore": true

‎test/tests/index.js‎

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@ describe("Index", function() {
1515

1616
var reposPath = local("../repos/workdir");
1717

18+
var addFileToIndex = function(repository, fileName) {
19+
return repository.openIndex()
20+
.then(function(index) {
21+
index.read(1);
22+
index.addByPath(fileName);
23+
index.write();
24+
25+
return index.writeTree();
26+
});
27+
};
28+
1829
beforeEach(function() {
1930
var test = this;
2031

@@ -154,4 +165,131 @@ describe("Index", function() {
154165
return fse.remove(path.join(repo.workdir(), fileNames[1]));
155166
});
156167
});
168+
169+
it("can get a conflict from the index", function() {
170+
var fileName = "everyonesFile.txt";
171+
var rebaseReposPath = local("../repos/rebase");
172+
var ourBranchName = "ours";
173+
var theirBranchName = "theirs";
174+
175+
var baseFileContent = "How do you feel about Toll Roads?\n";
176+
var ourFileContent = "I like Toll Roads. I have an EZ-Pass!\n";
177+
var theirFileContent = "I'm skeptical about Toll Roads\n";
178+
179+
var ourSignature = NodeGit.Signature.create
180+
("Ron Paul", "RonPaul@TollRoadsRBest.info", 123456789, 60);
181+
var theirSignature = NodeGit.Signature.create
182+
("Greg Abbott", "Gregggg@IllTollYourFace.us", 123456789, 60);
183+
184+
var repository;
185+
var ourCommit;
186+
var ourBranch;
187+
var theirBranch;
188+
189+
return Repository.init(rebaseReposPath, 0)
190+
.then(function(repo) {
191+
repository = repo;
192+
return fse.writeFile(path.join(repository.workdir(), fileName),
193+
baseFileContent);
194+
})
195+
.then(function() {
196+
return addFileToIndex(repository, fileName);
197+
})
198+
.then(function(oid) {
199+
assert.equal(oid.toString(),
200+
"044704f62399fecbe22da6d7d47b14e52625630e");
201+
202+
return repository.createCommit("HEAD", ourSignature,
203+
ourSignature, "initial commit", oid, []);
204+
})
205+
.then(function(commitOid) {
206+
assert.equal(commitOid.toString(),
207+
"80111c46ac73b857a3493b24c81df08639b5de99");
208+
209+
return repository.getCommit(commitOid).then(function(commit) {
210+
ourCommit = commit;
211+
}).then(function() {
212+
return repository.createBranch(ourBranchName, commitOid)
213+
.then(function(branch) {
214+
ourBranch = branch;
215+
return repository.createBranch(theirBranchName, commitOid);
216+
});
217+
});
218+
})
219+
.then(function(branch) {
220+
theirBranch = branch;
221+
return fse.writeFile(path.join(repository.workdir(), fileName),
222+
baseFileContent + theirFileContent);
223+
})
224+
.then(function() {
225+
return addFileToIndex(repository, fileName);
226+
})
227+
.then(function(oid) {
228+
assert.equal(oid.toString(),
229+
"b826e989aca7647bea64810f0a2a38acbbdd4c1a");
230+
231+
return repository.createCommit(theirBranch.name(), theirSignature,
232+
theirSignature, "they made a commit", oid, [ourCommit]);
233+
})
234+
.then(function(commitOid) {
235+
assert.equal(commitOid.toString(),
236+
"b3c355bb606ec7da87174dfa1a0b0c0e3dc97bc0");
237+
238+
return fse.writeFile(path.join(repository.workdir(), fileName),
239+
baseFileContent + ourFileContent);
240+
})
241+
.then(function() {
242+
return addFileToIndex(repository, fileName);
243+
})
244+
.then(function(oid) {
245+
assert.equal(oid.toString(),
246+
"e7fe41bf7c0c28766887a63ffe2f03f624276fbe");
247+
248+
return repository.createCommit(ourBranch.name(), ourSignature,
249+
ourSignature, "we made a commit", oid, [ourCommit]);
250+
})
251+
.then(function(commitOid) {
252+
assert.equal(commitOid.toString(),
253+
"28cfeb17f66132edb3c4dacb7ff38e8dd48a1844");
254+
255+
var opts = {
256+
checkoutStrategy: NodeGit.Checkout.STRATEGY.FORCE
257+
};
258+
259+
return NodeGit.Checkout.head(repository, opts);
260+
})
261+
.then(function() {
262+
return repository.mergeBranches(ourBranchName, theirBranchName);
263+
})
264+
.then(function(commit) {
265+
assert.fail(commit, undefined,
266+
"The index should have been thrown due to merge conflicts");
267+
})
268+
.catch(function(index) {
269+
assert.ok(index);
270+
assert.ok(index.hasConflicts());
271+
272+
return index.conflictGet(fileName);
273+
})
274+
.then(function(conflict) {
275+
var promises = [];
276+
277+
promises.push(repository.getBlob(conflict.ancestor_out.id)
278+
.then(function(blob) {
279+
assert.equal(blob.toString(), baseFileContent);
280+
}));
281+
282+
promises.push(repository.getBlob(conflict.our_out.id)
283+
.then(function(blob) {
284+
assert.equal(blob.toString(), baseFileContent + ourFileContent);
285+
}));
286+
287+
promises.push(repository.getBlob(conflict.their_out.id)
288+
.then(function(blob) {
289+
assert.equal(blob.toString(), baseFileContent + theirFileContent);
290+
}));
291+
292+
return Promise.all(promises);
293+
});
294+
});
157295
});

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL