Nodegit: Index randomly has conflict

Created on 9 Dec 2015  路  3Comments  路  Source: nodegit/nodegit

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');
    }
  });
});

Most helpful comment

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.

All 3 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

DawsonG picture DawsonG  路  8Comments

seokju-na picture seokju-na  路  4Comments

Yezior picture Yezior  路  8Comments

Sergeeeek picture Sergeeeek  路  9Comments

monkeyboy64 picture monkeyboy64  路  7Comments