Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions examples/add-and-commit.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,10 @@ nodegit.Repository.open(path.resolve(__dirname, "../.git"))
);
})
.then(function() {
return repo.openIndex();
return repo.refreshIndex();
})
.then(function(indexResult) {
index = indexResult;
return index.read(1);
})
.then(function() {
// this file is in the root of the directory and doesn't need a full path
Expand Down
3 changes: 1 addition & 2 deletions examples/create-new-repo.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ fse.ensureDir(path.resolve(__dirname, repoDir))
return fse.writeFile(path.join(repository.workdir(), fileName), fileContent);
})
.then(function(){
return repository.openIndex();
return repository.refreshIndex();
})
.then(function(idx) {
index = idx;
return index.read(1);
})
.then(function() {
return index.addByPath(fileName);
Expand Down
2 changes: 1 addition & 1 deletion examples/details-for-tree-entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ nodegit.Repository.open(path.resolve(__dirname, "../.git"))

// Tree entry doesn't have any data associated with the actual entry
// To get that we need to get the index entry that this points to
return repo.openIndex().then(function(index) {
return repo.refreshIndex().then(function(index) {
var indexEntry = index.getByPath(treeEntry.path());

// With the index entry we can now view the details for the tree entry
Expand Down
2 changes: 1 addition & 1 deletion examples/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ nodegit.Repository.open(path.resolve(__dirname, "../.git"))

// The [index file API][gi] allows you to read, traverse, update and write
// the Git index file (sometimes thought of as the staging area).
return repo.openIndex();
return repo.refreshIndex();
})

.then(function(index) {
Expand Down
2 changes: 1 addition & 1 deletion examples/index-add-and-remove.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var fse = promisify(require("fs-extra"));

nodegit.Repository.open(path.resolve(__dirname, "../.git"))
.then(function(repo) {
return repo.openIndex()
return repo.refreshIndex()
.then(function(index) {
var fileContent = {
newFile1: "this has some content",
Expand Down
6 changes: 2 additions & 4 deletions examples/merge-cleanly.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,9 @@ fse.remove(path.resolve(__dirname, repoDir))

// Load up the repository index and make our initial commit to HEAD
.then(function() {
return repository.openIndex();
return repository.refreshIndex();
})
.then(function(index) {
index.read(1);
index.addByPath(ourFileName);
index.write();

Expand Down Expand Up @@ -79,10 +78,9 @@ fse.remove(path.resolve(__dirname, repoDir))
);
})
.then(function() {
return repository.openIndex();
return repository.refreshIndex();
})
.then(function(index) {
index.read(1);
index.addByPath(theirFileName);
index.write();

Expand Down
12 changes: 4 additions & 8 deletions examples/merge-with-conflicts.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,9 @@ fse.remove(path.resolve(__dirname, repoDir))

// Load up the repository index and make our initial commit to HEAD
.then(function() {
return repository.openIndex();
return repository.refreshIndex();
})
.then(function(index) {
index.read(1);
index.addByPath(fileName);
index.write();

Expand Down Expand Up @@ -94,9 +93,8 @@ fse.remove(path.resolve(__dirname, repoDir))
);
})
.then(function() {
return repository.openIndex()
return repository.refreshIndex()
.then(function(index) {
index.read(1);
index.addByPath(fileName);
index.write();

Expand All @@ -122,8 +120,7 @@ fse.remove(path.resolve(__dirname, repoDir))
);
})
.then(function() {
return repository.openIndex().then(function(index) {
index.read(1);
return repository.refreshIndex().then(function(index) {
index.addByPath(fileName);
index.write();

Expand Down Expand Up @@ -173,9 +170,8 @@ 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.openIndex().then(function(index) {
return repository.refreshIndex().then(function(index) {

index.read(1);
index.addByPath(fileName);
index.write();

Expand Down
3 changes: 1 addition & 2 deletions examples/push.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@ fse.remove(path.resolve(__dirname, repoDir))

// Load up the repository index and make our initial commit to HEAD
.then(function() {
return repository.openIndex();
return repository.refreshIndex();
})
.then(function(index) {
index.read(1);
index.addByPath(fileName);
index.write();

Expand Down
3 changes: 1 addition & 2 deletions examples/remove-and-commit.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@ var _oid;
nodegit.Repository.open(path.resolve(__dirname, "../.git"))
.then(function(repo) {
_repository = repo;
return repo.openIndex();
return repo.refreshIndex();
})
.then(function(index){
_index = index;
return _index.read();
})
.then(function() {
//remove the file from the index...
Expand Down
6 changes: 5 additions & 1 deletion generate/input/descriptor.json
Original file line number Diff line number Diff line change
Expand Up @@ -1833,7 +1833,11 @@
}
},
"git_repository_set_index": {
"ignore": true
"args": {
"index": {
"isOptional": true
}
}
},
"git_repository_set_odb": {
"ignore": true
Expand Down
34 changes: 26 additions & 8 deletions lib/repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,27 @@ Object.defineProperty(Repository.prototype, "openIndex", {
enumerable: false,
value: Repository.prototype.index
});
/**
* Grabs a fresh copy of the index from the repository. Invalidates
* all previously grabbed indexes
*
* @async
* @return {Index}
*/
Repository.prototype.refreshIndex = function(callback) {
var repo = this;

repo.setIndex(); // clear the index

return repo.index()
.then(function(index) {
if (typeof callback === "function") {
callback(null, index);
}

return index;
}, callback);
};

/**
* Creates a branch with the passed in name pointing to the commit
Expand Down Expand Up @@ -521,10 +542,9 @@ Repository.prototype.createCommitOnHead = function(
var index;
var repo = this;

return repo.openIndex()
return repo.refreshIndex()
.then(function(index_) {
index = index_;
index.read(1);
if (!filesToAdd) { filesToAdd = []; }
filesToAdd.forEach(function(filePath) {
index.addByPath(filePath);
Expand Down Expand Up @@ -907,7 +927,7 @@ function performRebase(repository, rebase, signature, beforeNextFn) {
function getPromise() {
return rebase.next()
.then(function() {
return repository.openIndex()
return repository.refreshIndex()
.then(function(index) {
if (index.hasConflicts()) {
throw index;
Expand Down Expand Up @@ -1033,7 +1053,7 @@ Repository.prototype.continueRebase = function(signature, beforeNextFn) {

signature = signature || repo.defaultSignature();

return repo.openIndex()
return repo.refreshIndex()
.then(function(index) {
if (index.hasConflicts()) {
throw index;
Expand Down Expand Up @@ -1241,11 +1261,10 @@ Repository.prototype.stageFilemode = function(filePath, stageNew) {

return fse.remove(indexLock)
.then(function() {
return repo.openIndex();
return repo.refreshIndex();
})
.then(function(indexResult) {
index = indexResult;
return index.read(1);
})
.then(function() {
return diffPromise;
Expand Down Expand Up @@ -1449,10 +1468,9 @@ Repository.prototype.stageLines =
});
};

return repo.openIndex()
return repo.refreshIndex()
.then(function(indexResult) {
index = indexResult;
return index.read(1);
})
.then(function() {
return diffPromise();
Expand Down
3 changes: 1 addition & 2 deletions test/tests/checkout.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,8 @@ describe("Checkout", function() {
.then(function(branch) {
fse.writeFileSync(packageJsonPath, "\n");

return test.repository.openIndex()
return test.repository.refreshIndex()
.then(function(index) {
index.read(1);
index.addByPath(packageJsonName);
index.write();

Expand Down
12 changes: 4 additions & 8 deletions test/tests/commit.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,10 @@ describe("Commit", function() {

return fse.writeFile(path.join(repo.workdir(), fileName), fileContent)
.then(function() {
return repo.openIndex();
return repo.refreshIndex();
})
.then(function(indexResult) {
index = indexResult;
return index.read(1);
})
.then(function() {
return index.addByPath(fileName);
Expand Down Expand Up @@ -162,11 +161,10 @@ describe("Commit", function() {
return fse.writeFile(path.join(repo.workdir(), fileName), fileContent);
})
.then(function() {
return repo.openIndex();
return repo.refreshIndex();
})
.then(function(indexResult) {
index = indexResult;
return index.read(1);
})
.then(function() {
return index.addByPath(fileName);
Expand Down Expand Up @@ -242,11 +240,10 @@ describe("Commit", function() {
return fse.writeFile(path.join(repo.workdir(), fileName), fileContent);
})
.then(function() {
return repo.openIndex();
return repo.refreshIndex();
})
.then(function(indexResult) {
index = indexResult;
return index.read(1);
})
.then(function() {
return index.addByPath(fileName);
Expand Down Expand Up @@ -290,11 +287,10 @@ describe("Commit", function() {
);
})
.then(function() {
return repo.openIndex();
return repo.refreshIndex();
})
.then(function(indexResult) {
index = indexResult;
return index.read(1);
})
.then(function() {
return index.addByPath(newFileName);
Expand Down
4 changes: 2 additions & 2 deletions test/tests/diff.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe("Diff", function() {
return Repository.open(reposPath).then(function(repository) {
test.repository = repository;

return repository.openIndex();
return repository.refreshIndex();
})
.then(function(index) {
test.index = index;
Expand Down Expand Up @@ -307,7 +307,7 @@ describe("Diff", function() {
return Repository.open(reposPath).then(function(repository) {
test.repository = repository;

return repository.openIndex();
return repository.refreshIndex();
})
.then(function(index) {
test.index = index;
Expand Down
6 changes: 3 additions & 3 deletions test/tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe("Index", function() {
return Repository.open(reposPath)
.then(function(repo) {
test.repository = repo;
return repo.openIndex();
return repo.refreshIndex();
})
.then(function(index) {
test.index = index;
Expand Down Expand Up @@ -342,7 +342,7 @@ describe("Index", function() {
return RepoUtils.addFileToIndex(repo, fileName);
})
.then(function() {
return repo.openIndex();
return repo.index();
})
.then(function(index) {
assert.ok(!index.hasConflicts());
Expand All @@ -353,7 +353,7 @@ describe("Index", function() {
);
})
.then(function() {
return repo.openIndex();
return repo.index();
})
.then(function(index) {
assert(index.hasConflicts());
Expand Down
Loading