diff --git a/examples/merge-cleanly.js b/examples/merge-cleanly.js index 94af29df6..c338cb90f 100644 --- a/examples/merge-cleanly.js +++ b/examples/merge-cleanly.js @@ -46,10 +46,13 @@ fse.remove(path.resolve(__dirname, repoDir)) return repository.refreshIndex(); }) .then(function(index) { - index.addByPath(ourFileName); - index.write(); - - return index.writeTree(); + return index.addByPath(ourFileName) + .then(function() { + return index.write(); + }) + .then(function() { + return index.writeTree(); + }); }) .then(function(oid) { return repository.createCommit("HEAD", ourSignature, @@ -81,10 +84,13 @@ fse.remove(path.resolve(__dirname, repoDir)) return repository.refreshIndex(); }) .then(function(index) { - index.addByPath(theirFileName); - index.write(); - - return index.writeTree(); + return index.addByPath(theirFileName) + .then(function() { + return index.write(); + }) + .then(function() { + return index.writeTree(); + }); }) .then(function(oid) { // You don"t have to change head to make a commit to a different branch. @@ -110,8 +116,10 @@ fse.remove(path.resolve(__dirname, repoDir)) // the repository instead of just writing it. .then(function(index) { if (!index.hasConflicts()) { - index.write(); - return index.writeTreeTo(repository); + return index.write() + .then(function() { + return index.writeTreeTo(repository); + }); } }) diff --git a/examples/merge-with-conflicts.js b/examples/merge-with-conflicts.js index 3320e2f6c..13e07c8d5 100644 --- a/examples/merge-with-conflicts.js +++ b/examples/merge-with-conflicts.js @@ -52,10 +52,13 @@ fse.remove(path.resolve(__dirname, repoDir)) return repository.refreshIndex(); }) .then(function(index) { - index.addByPath(fileName); - index.write(); - - return index.writeTree(); + return index.addByPath(fileName) + .then(function() { + return index.write(); + }) + .then(function() { + return index.writeTree(); + }); }) .then(function(oid) { return repository.createCommit("HEAD", baseSignature, @@ -95,10 +98,13 @@ fse.remove(path.resolve(__dirname, repoDir)) .then(function() { return repository.refreshIndex() .then(function(index) { - index.addByPath(fileName); - index.write(); - - return index.writeTree(); + return index.addByPath(fileName) + .then(function() { + return index.write(); + }) + .then(function() { + return index.writeTree(); + }); }); }) .then(function(oid) { @@ -120,11 +126,15 @@ fse.remove(path.resolve(__dirname, repoDir)) ); }) .then(function() { - return repository.refreshIndex().then(function(index) { - index.addByPath(fileName); - index.write(); - - return index.writeTree(); + return repository.refreshIndex() + .then(function(index) { + return index.addByPath(fileName) + .then(function() { + return index.write(); + }) + .then(function() { + return index.writeTree(); + }); }); }) .then(function(oid) { @@ -170,12 +180,15 @@ fse.remove(path.resolve(__dirname, repoDir)) // we need to get a new index as the other one isnt backed to // the repository in the usual fashion, and just behaves weirdly .then(function() { - return repository.refreshIndex().then(function(index) { - - index.addByPath(fileName); - index.write(); - - return index.writeTree(); + return repository.refreshIndex() + .then(function(index) { + return index.addByPath(fileName) + .then(function() { + return index.write(); + }) + .then(function() { + return index.writeTree(); + }); }); }) .then(function(oid) { diff --git a/examples/push.js b/examples/push.js index 70a533b21..ac340820f 100644 --- a/examples/push.js +++ b/examples/push.js @@ -33,10 +33,13 @@ fse.remove(path.resolve(__dirname, repoDir)) return repository.refreshIndex(); }) .then(function(index) { - index.addByPath(fileName); - index.write(); - - return index.writeTree(); + return index.addByPath(fileName) + .then(function() { + return index.write(); + }) + .then(function() { + return index.writeTree(); + }); }) .then(function(oid) { return repository.createCommit("HEAD", signature, signature, diff --git a/examples/remove-and-commit.js b/examples/remove-and-commit.js index c321d1715..10751f061 100644 --- a/examples/remove-and-commit.js +++ b/examples/remove-and-commit.js @@ -24,7 +24,9 @@ nodegit.Repository.open(path.resolve(__dirname, "../.git")) }) .then(function() { //remove the file from the index... - _index.removeByPath(fileName); + return _index.removeByPath(fileName); + }) + .then(function() { return _index.write(); }) .then(function() { diff --git a/generate/input/descriptor.json b/generate/input/descriptor.json index 2b8a32756..68bc7e683 100644 --- a/generate/input/descriptor.json +++ b/generate/input/descriptor.json @@ -959,6 +959,12 @@ }, "index": { "functions": { + "git_index_add": { + "isAsync": true, + "return": { + "isErrorCode": true + } + }, "git_index_add_all": { "args": { "pathspec": { @@ -976,11 +982,34 @@ "isErrorCode": true } }, + "git_index_add_bypath": { + "isAsync": true, + "return": { + "isErrorCode": true + } + }, "git_index_add_frombuffer": { "ignore": true }, - "git_index_conflict_get": { + "git_index_clear": { + "isAsync": true, + "return": { + "isErrorCode": true + } + }, + "git_index_conflict_add": { + "isAsync": true, + "return": { + "isErrorCode": true + } + }, + "git_index_conflict_cleanup": { "isAsync": true, + "return": { + "isErrorCode": true + } + }, + "git_index_conflict_get": { "args": { "ancestor_out": { "isReturn": true @@ -992,6 +1021,7 @@ "isReturn": true } }, + "isAsync": true, "return": { "isErrorCode": true } @@ -1005,6 +1035,12 @@ "git_index_conflict_next": { "ignore": true }, + "git_index_conflict_remove": { + "isAsync": true, + "return": { + "isErrorCode": true + } + }, "git_index_entrycount": { "jsFunctionName": "entryCount" }, @@ -1024,11 +1060,33 @@ "git_index_new": { "ignore": true }, + "git_index_open": { + "isAsync": true, + "return": { + "isErrorCode": true + } + }, "git_index_read": { "args": { "force": { "isOptional": true } + }, + "isAsync": true, + "return": { + "isErrorCode": true + } + }, + "git_index_read_tree": { + "isAsync": true, + "return": { + "isErrorCode": true + } + }, + "git_index_remove": { + "isAsync": true, + "return": { + "isErrorCode": true } }, "git_index_remove_all": { @@ -1048,6 +1106,18 @@ "isErrorCode": true } }, + "git_index_remove_bypath": { + "isAsync": true, + "return": { + "isErrorCode": true + } + }, + "git_index_remove_directory": { + "isAsync": true, + "return": { + "isErrorCode": true + } + }, "git_index_update_all": { "args": { "pathspec": { @@ -1070,7 +1140,23 @@ "force": { "isOptional": true } - } + }, + "isAsync": true, + "return": { + "isErrorCode": true + } + }, + "git_index_write_tree": { + "isAsync": true, + "return": { + "isErrorCode": true + } + }, + "git_index_write_tree_to": { + "isAsync": true, + "return": { + "isErrorCode": true + } } }, "dependencies": [ diff --git a/lib/repository.js b/lib/repository.js index ade1d9ce9..234166722 100644 --- a/lib/repository.js +++ b/lib/repository.js @@ -535,18 +535,27 @@ Repository.prototype.createCommitOnHead = function( message, callback) { - var index; var repo = this; return repo.refreshIndex() - .then(function(index_) { - index = index_; - if (!filesToAdd) { filesToAdd = []; } - filesToAdd.forEach(function(filePath) { - index.addByPath(filePath); - }); - index.write(); - return index.writeTree(); + .then(function(index) { + if (!filesToAdd) { + filesToAdd = []; + } + + return filesToAdd + .reduce(function(lastFilePromise, filePath) { + return lastFilePromise + .then(function() { + return index.addByPath(filePath); + }); + }, Promise.resolve()) + .then(function() { + return index.write(); + }) + .then(function() { + return index.writeTree(); + }); }) .then(function(treeOid) { return repo.getHeadCommit() @@ -849,7 +858,6 @@ Repository.prototype.mergeBranches = } // No conflicts so just go ahead with the merge - index.write(); return index.writeTreeTo(repo); }) .then(function(oid) { @@ -1287,15 +1295,20 @@ Repository.prototype.stageFilemode = function(filePath, stageNew) { return Promise.reject("No differences found for this file."); } - pathPatches.forEach(function(pathPatch) { - var entry = index.getByPath(pathPatch.newFile().path(), 0); + return pathPatches + .reduce(function(lastIndexAddPromise, pathPatch) { + var entry = index.getByPath(pathPatch.newFile().path(), 0); - entry.mode = stageNew ? - pathPatch.newFile().mode() : pathPatch.oldFile().mode(); - - index.add(entry); - }); + entry.mode = stageNew ? + pathPatch.newFile().mode() : pathPatch.oldFile().mode(); + return lastIndexAddPromise + .then(function() { + return index.add(entry); + }); + }, Promise.resolve()); + }) + .then(function() { return index.write(); }); }; @@ -1456,8 +1469,10 @@ Repository.prototype.stageLines = !pathPatch[0].isTypeChange(); } if (emptyPatch) { - index.addByPath(filePath); - return index.write(); + return index.addByPath(filePath) + .then(function() { + return index.write(); + }); } else { return result; } @@ -1509,7 +1524,9 @@ Repository.prototype.stageLines = entry.path = filePath; entry.fileSize = newBlob.content().length; - index.add(entry); + return index.add(entry); + }) + .then(function() { return index.write(); }) .then(function(result) { diff --git a/test/tests/checkout.js b/test/tests/checkout.js index cc510f304..cdde973ed 100644 --- a/test/tests/checkout.js +++ b/test/tests/checkout.js @@ -128,10 +128,13 @@ describe("Checkout", function() { return test.repository.refreshIndex() .then(function(index) { - index.addByPath(packageJsonName); - index.write(); - - return index.writeTree(); + return index.addByPath(packageJsonName) + .then(function() { + return index.write(); + }) + .then(function() { + return index.writeTree(); + }); }); }) .then(function(oid) { diff --git a/test/tests/cherrypick.js b/test/tests/cherrypick.js index 325fd410b..e4f2ca7e4 100644 --- a/test/tests/cherrypick.js +++ b/test/tests/cherrypick.js @@ -75,8 +75,6 @@ describe("Cherrypick", function() { }) .then(function(index) { assert(index); - index.write(); - return index.writeTreeTo(repo); }) .then(function(oid) { diff --git a/test/tests/index.js b/test/tests/index.js index bac0d7e34..aba18fa60 100644 --- a/test/tests/index.js +++ b/test/tests/index.js @@ -80,7 +80,7 @@ describe("Index", function() { })); }) .then(function() { - index.clear(); + return index.clear(); }); }); @@ -131,7 +131,7 @@ describe("Index", function() { })); }) .then(function() { - index.clear(); + return index.clear(); }); }); diff --git a/test/tests/merge.js b/test/tests/merge.js index 4af1f91cf..3a63b0ced 100644 --- a/test/tests/merge.js +++ b/test/tests/merge.js @@ -44,11 +44,14 @@ describe("Merge", function() { ourFileContent) // Load up the repository index and make our initial commit to HEAD .then(function() { - return repository.refreshIndex() - .then(function(index) { - index.addByPath(ourFileName); - index.write(); - + return repository.refreshIndex(); + }) + .then(function(index) { + return index.addByPath(ourFileName) + .then(function() { + return index.write(); + }) + .then(function() { return index.writeTree(); }); }) @@ -79,11 +82,14 @@ describe("Merge", function() { theirFileContent); }) .then(function() { - return repository.refreshIndex() - .then(function(index) { - index.addByPath(theirFileName); - index.write(); - + return repository.refreshIndex(); + }) + .then(function(index) { + return index.addByPath(theirFileName) + .then(function() { + return index.write(); + }) + .then(function() { return index.writeTree(); }); }) @@ -107,7 +113,6 @@ describe("Merge", function() { }) .then(function(index) { assert(!index.hasConflicts()); - index.write(); return index.writeTreeTo(repository); }) .then(function(oid) { @@ -147,13 +152,16 @@ describe("Merge", function() { ourFileContent) // Load up the repository index and make our initial commit to HEAD .then(function() { - return repository.refreshIndex() - .then(function(index) { - index.addByPath(ourFileName); - index.write(); - - return index.writeTree(); - }); + return repository.refreshIndex(); + }) + .then(function(index) { + return index.addByPath(ourFileName) + .then(function() { + return index.write(); + }) + .then(function() { + return index.writeTree(); + }); }) .then(function(oid) { assert.equal(oid.toString(), @@ -182,13 +190,16 @@ describe("Merge", function() { theirFileContent); }) .then(function() { - return repository.refreshIndex() - .then(function(index) { - index.addByPath(theirFileName); - index.write(); - - return index.writeTree(); - }); + return repository.refreshIndex(); + }) + .then(function(index) { + return index.addByPath(theirFileName) + .then(function() { + return index.write(); + }) + .then(function() { + return index.writeTree(); + }); }) .then(function(oid) { assert.equal(oid.toString(), @@ -257,13 +268,16 @@ describe("Merge", function() { ourFileContent) // Load up the repository index and make our initial commit to HEAD .then(function() { - return repository.refreshIndex() - .then(function(index) { - index.addByPath(ourFileName); - index.write(); - - return index.writeTree(); - }); + return repository.refreshIndex(); + }) + .then(function(index) { + return index.addByPath(ourFileName) + .then(function() { + return index.write(); + }) + .then(function() { + return index.writeTree(); + }); }) .then(function(oid) { assert.equal(oid.toString(), @@ -292,13 +306,16 @@ describe("Merge", function() { theirFileContent); }) .then(function() { - return repository.refreshIndex() - .then(function(index) { - index.addByPath(theirFileName); - index.write(); - - return index.writeTree(); - }); + return repository.refreshIndex(); + }) + .then(function(index) { + return index.addByPath(theirFileName) + .then(function() { + return index.write(); + }) + .then(function() { + return index.writeTree(); + }); }) .then(function(oid) { assert.equal(oid.toString(), @@ -374,13 +391,16 @@ describe("Merge", function() { initialFileContent) // Load up the repository index and make our initial commit to HEAD .then(function() { - return repository.refreshIndex() - .then(function(index) { - index.addByPath(initialFileName); - index.write(); - - return index.writeTree(); - }); + return repository.refreshIndex(); + }) + .then(function(index) { + return index.addByPath(initialFileName) + .then(function() { + return index.write(); + }) + .then(function() { + return index.writeTree(); + }); }) .then(function(oid) { assert.equal(oid.toString(), @@ -411,13 +431,16 @@ describe("Merge", function() { ourFileContent); }) .then(function() { - return repository.refreshIndex() - .then(function(index) { - index.addByPath(ourFileName); - index.write(); - - return index.writeTree(); - }); + return repository.refreshIndex(); + }) + .then(function(index) { + return index.addByPath(ourFileName) + .then(function() { + return index.write(); + }) + .then(function() { + return index.writeTree(); + }); }) .then(function(oid) { assert.equal(oid.toString(), @@ -439,13 +462,16 @@ describe("Merge", function() { theirFileContent); }) .then(function() { - return repository.refreshIndex() - .then(function(index) { - index.addByPath(theirFileName); - index.write(); - - return index.writeTree(); - }); + return repository.refreshIndex(); + }) + .then(function(index) { + return index.addByPath(theirFileName) + .then(function() { + return index.write(); + }) + .then(function() { + return index.writeTree(); + }); }) .then(function(oid) { assert.equal(oid.toString(), @@ -510,13 +536,16 @@ describe("Merge", function() { ourFileContent) // Load up the repository index and make our initial commit to HEAD .then(function() { - return repository.refreshIndex() - .then(function(index) { - index.addByPath(ourFileName); - index.write(); - - return index.writeTree(); - }); + return repository.refreshIndex(); + }) + .then(function(index) { + return index.addByPath(ourFileName) + .then(function() { + return index.write(); + }) + .then(function() { + return index.writeTree(); + }); }) .then(function(oid) { assert.equal(oid.toString(), @@ -545,13 +574,16 @@ describe("Merge", function() { theirFileContent); }) .then(function() { - return repository.refreshIndex() - .then(function(index) { - index.addByPath(theirFileName); - index.write(); - - return index.writeTree(); - }); + return repository.refreshIndex(); + }) + .then(function(index) { + return index.addByPath(theirFileName) + .then(function() { + return index.write(); + }) + .then(function() { + return index.writeTree(); + }); }) .then(function(oid) { assert.equal(oid.toString(), @@ -624,13 +656,16 @@ describe("Merge", function() { initialFileContent) // Load up the repository index and make our initial commit to HEAD .then(function() { - return repository.refreshIndex() - .then(function(index) { - index.addByPath(initialFileName); - index.write(); - - return index.writeTree(); - }); + return repository.refreshIndex(); + }) + .then(function(index) { + return index.addByPath(initialFileName) + .then(function() { + return index.write(); + }) + .then(function() { + return index.writeTree(); + }); }) .then(function(oid) { assert.equal(oid.toString(), @@ -661,13 +696,16 @@ describe("Merge", function() { ourFileContent); }) .then(function() { - return repository.refreshIndex() - .then(function(index) { - index.addByPath(ourFileName); - index.write(); - - return index.writeTree(); - }); + return repository.refreshIndex(); + }) + .then(function(index) { + return index.addByPath(ourFileName) + .then(function() { + return index.write(); + }) + .then(function() { + return index.writeTree(); + }); }) .then(function(oid) { assert.equal(oid.toString(), @@ -689,13 +727,16 @@ describe("Merge", function() { theirFileContent); }) .then(function() { - return repository.refreshIndex() - .then(function(index) { - index.addByPath(theirFileName); - index.write(); - - return index.writeTree(); - }); + return repository.refreshIndex(); + }) + .then(function(index) { + return index.addByPath(theirFileName) + .then(function() { + return index.write(); + }) + .then(function() { + return index.writeTree(); + }); }) .then(function(oid) { assert.equal(oid.toString(), @@ -762,13 +803,16 @@ describe("Merge", function() { initialFileContent) // Load up the repository index and make our initial commit to HEAD .then(function() { - return repository.refreshIndex() - .then(function(index) { - index.addByPath(initialFileName); - index.write(); - - return index.writeTree(); - }); + return repository.refreshIndex(); + }) + .then(function(index) { + return index.addByPath(initialFileName) + .then(function() { + return index.write(); + }) + .then(function() { + return index.writeTree(); + }); }) .then(function(oid) { assert.equal(oid.toString(), @@ -799,13 +843,16 @@ describe("Merge", function() { ourFileContent); }) .then(function() { - return repository.refreshIndex() - .then(function(index) { - index.addByPath(ourFileName); - index.write(); - - return index.writeTree(); - }); + return repository.refreshIndex(); + }) + .then(function(index) { + return index.addByPath(ourFileName) + .then(function() { + return index.write(); + }) + .then(function() { + return index.writeTree(); + }); }) .then(function(oid) { assert.equal(oid.toString(), @@ -827,13 +874,16 @@ describe("Merge", function() { theirFileContent); }) .then(function() { - return repository.refreshIndex() - .then(function(index) { - index.addByPath(theirFileName); - index.write(); - - return index.writeTree(); - }); + return repository.refreshIndex(); + }) + .then(function(index) { + return index.addByPath(theirFileName) + .then(function() { + return index.write(); + }) + .then(function(){ + return index.writeTree(); + }); }) .then(function(oid) { assert.equal(oid.toString(), @@ -886,11 +936,14 @@ describe("Merge", function() { return fse.writeFile(path.join(repository.workdir(), fileName), baseFileContent) .then(function() { - return repository.refreshIndex() - .then(function(index) { - index.addByPath(fileName); - index.write(); - + return repository.refreshIndex(); + }) + .then(function(index) { + return index.addByPath(fileName) + .then(function() { + return index.write(); + }) + .then(function() { return index.writeTree(); }); }) @@ -927,12 +980,16 @@ describe("Merge", function() { ourFileContent); }) .then(function() { - return repository.refreshIndex().then(function(index) { - index.addByPath(fileName); - index.write(); - - return index.writeTree(); - }); + return repository.refreshIndex(); + }) + .then(function(index) { + return index.addByPath(fileName) + .then(function() { + return index.write(); + }) + .then(function() { + return index.writeTree(); + }); }) .then(function(oid) { assert.equal(oid.toString(), @@ -954,12 +1011,16 @@ describe("Merge", function() { theirFileContent); }) .then(function() { - return repository.refreshIndex().then(function(index) { - index.addByPath(fileName); - index.write(); - - return index.writeTree(); - }); + return repository.refreshIndex(); + }) + .then(function(index) { + return index.addByPath(fileName) + .then(function() { + return index.write(); + }) + .then(function() { + return index.writeTree(); + }); }) .then(function(oid) { assert.equal(oid.toString(), @@ -991,12 +1052,16 @@ describe("Merge", function() { finalFileContent); }) .then(function() { - return repository.refreshIndex().then(function(index) { - index.addByPath(fileName); - index.write(); - - return index.writeTree(); - }); + return repository.refreshIndex(); + }) + .then(function(index) { + return index.addByPath(fileName) + .then(function() { + return index.write(); + }) + .then(function() { + return index.writeTree(); + }); }) .then(function(oid) { assert.equal(oid.toString(), @@ -1051,12 +1116,16 @@ describe("Merge", function() { return fse.writeFile(path.join(repository.workdir(), fileName), baseFileContent) .then(function() { - return repository.refreshIndex().then(function(index) { - index.addByPath(fileName); - index.write(); - - return index.writeTree(); - }); + return repository.refreshIndex(); + }) + .then(function(index) { + return index.addByPath(fileName) + .then(function() { + return index.write(); + }) + .then(function() { + return index.writeTree(); + }); }) .then(function(oid) { assert.equal(oid.toString(), @@ -1085,12 +1154,16 @@ describe("Merge", function() { baseFileContent + theirFileContent); }) .then(function() { - return repository.refreshIndex().then(function(index) { - index.addByPath(fileName); - index.write(); - - return index.writeTree(); - }); + return repository.refreshIndex(); + }) + .then(function(index) { + return index.addByPath(fileName) + .then(function() { + return index.write(); + }) + .then(function() { + return index.writeTree(); + }); }) .then(function(oid) { assert.equal(oid.toString(), @@ -1107,12 +1180,16 @@ describe("Merge", function() { baseFileContent + ourFileContent); }) .then(function() { - return repository.refreshIndex().then(function(index) { - index.addByPath(fileName); - index.write(); - - return index.writeTree(); - }); + return repository.refreshIndex(); + }) + .then(function(index) { + return index.addByPath(fileName) + .then(function() { + return index.write(); + }) + .then(function() { + return index.writeTree(); + }); }) .then(function(oid) { assert.equal(oid.toString(), @@ -1175,11 +1252,14 @@ describe("Merge", function() { conflictSolvedFileContent); }) .then(function() { - return repository.refreshIndex() - .then(function(index) { - index.addByPath(fileName); - index.write(); - + return repository.refreshIndex(); + }) + .then(function(index) { + return index.addByPath(fileName) + .then(function() { + return index.write(); + }) + .then(function() { return index.writeTree(); }); }) diff --git a/test/tests/rebase.js b/test/tests/rebase.js index adf325080..f40d73621 100644 --- a/test/tests/rebase.js +++ b/test/tests/rebase.js @@ -15,10 +15,13 @@ describe("Rebase", function() { var removeFileFromIndex = function(repository, fileName) { return repository.refreshIndex() .then(function(index) { - index.removeByPath(fileName); - index.write(); - - return index.writeTree(); + return index.removeByPath(fileName) + .then(function() { + return index.write(); + }) + .then(function() { + return index.writeTree(); + }); }); }; diff --git a/test/tests/repository.js b/test/tests/repository.js index a0635041d..307c52ee3 100644 --- a/test/tests/repository.js +++ b/test/tests/repository.js @@ -259,20 +259,20 @@ describe("Repository", function() { return fse.writeFile(filePath, fileContent) .then(function() { return repo.createCommitOnHead( - [filePath], + [fileName], authSig, commitSig, commitMsg ); }) .then(function(oidResult) { - return repo.getHeadCommit() - .then(function(commit) { - assert.equal( - commit.toString(), - oidResult.toString() - ); - }); + return repo.getHeadCommit() + .then(function(commit) { + assert.equal( + commit.toString(), + oidResult.toString() + ); + }); }); }); diff --git a/test/tests/revwalk.js b/test/tests/revwalk.js index 6400bf899..96bb736c8 100644 --- a/test/tests/revwalk.js +++ b/test/tests/revwalk.js @@ -253,12 +253,17 @@ describe("Revwalk", function() { ); }) .then(function() { - return repo.refreshIndex() - .then(function(index) { - index.addByPath(fileNameB); - index.removeByPath(fileNameA); - index.write(); - + return repo.refreshIndex(); + }) + .then(function(index) { + return index.addByPath(fileNameB) + .then(function() { + return index.removeByPath(fileNameA); + }) + .then(function() { + return index.write(); + }) + .then(function() { return index.writeTree(); }); }) diff --git a/test/tests/stage.js b/test/tests/stage.js index d88e65139..c1b9588d7 100644 --- a/test/tests/stage.js +++ b/test/tests/stage.js @@ -142,8 +142,7 @@ describe("Stage", function() { }); return test.repository.stageLines(fileName, linesToStage, !staging); }) - .then(function(stageResult) { - assert.equal(stageResult, 0); + .then(function() { return test.repository.refreshIndex(); }) .then(function(reloadedIndex) { @@ -302,8 +301,8 @@ describe("Stage", function() { .then(function() { return test.repository.refreshIndex(); }) - .then(function(repoIndex) { - index = repoIndex; + .then(function(_index) { + index = _index; return index.writeTree(); }) .then(function (oid) { @@ -345,7 +344,9 @@ describe("Stage", function() { .then(function(repoIndex) { //Now we stage the whole file... index = repoIndex; - index.addByPath(fileName); + return index.addByPath(fileName); + }) + .then(function() { return index.write(); }) .then(function() { @@ -429,13 +430,20 @@ describe("Stage", function() { })) .then(function() { // Initial commit - return test.repository.refreshIndex() - .then(function(index) { - fileName.forEach(function(file) { - index.addByPath(file); - }); - index.write(); - + return test.repository.refreshIndex(); + }) + .then(function(index) { + return fileName + .reduce(function(lastPromise, file) { + return lastPromise + .then(function() { + return index.addByPath(file); + }); + }, Promise.resolve()) + .then(function() { + return index.write(); + }) + .then(function() { return index.writeTree(); }); }) diff --git a/test/utils/repository_setup.js b/test/utils/repository_setup.js index 8a6319af6..c5d6ab3e2 100644 --- a/test/utils/repository_setup.js +++ b/test/utils/repository_setup.js @@ -9,10 +9,13 @@ var RepositorySetup = { function addFileToIndex(repository, fileName) { return repository.refreshIndex() .then(function(index) { - index.addByPath(fileName); - index.write(); - - return index.writeTree(); + return index.addByPath(fileName) + .then(function() { + return index.write(); + }) + .then(function() { + return index.writeTree(); + }); }); },