The following code simply creates a blank index, adds 1 file to it, and checks the index for conflict. When running multiple times, once after another, the index will randomly have a conflict, and the conflicted entry will be the only entry, with a stage value of 3.
I would expect there never to be a conflict. Is this a bug or have I misunderstood a concept?
return Git.Repository.init(this.repoPath, 0)
.then(repo => {
return Git.Index.open('randomindexpath')
.then(index => {
//create file entry
var fileContent = new Buffer("first file content");
var newFileOid = Git.Blob.createFromBuffer(repo, fileContent, fileContent.length);
var fileEntry = new Git.IndexEntry();
fileEntry.path = 'firstfile.txt';
fileEntry.id = newFileOid;
fileEntry.mode = Git.TreeEntry.FILEMODE.BLOB;
//add entry to index
index.add(fileEntry);
if (index.hasConflicts()) {
throw new Error('Index is conflicted');
}
});
});
Added #820 which adds a test case, and enables Git.Index.create()
This might be related to #827.
I found that setting the index entry flags to 0 before adding to index seems to avoid the unexpected conflict state. Doing a dump showed that it might be left uninitialized otherwise, which probably confuses the add code.
Most helpful comment
I found that setting the index entry
flagsto0before adding to index seems to avoid the unexpected conflict state. Doing a dump showed that it might be left uninitialized otherwise, which probably confuses the add code.