From 420a088ecc382411454c5829e9588b99419adae1 Mon Sep 17 00:00:00 2001 From: John Haley Date: Thu, 19 Feb 2015 09:56:17 -0700 Subject: [PATCH] Enable `git_index_remove_all` and `git_index_update_all` --- generate/input/descriptor.json | 32 ++++++++++++- lib/index.js | 10 ++++ test/tests/index.js | 87 ++++++++++++++++++++++++++++++++++ 3 files changed, 127 insertions(+), 2 deletions(-) diff --git a/generate/input/descriptor.json b/generate/input/descriptor.json index b9499381b..5ec000213 100644 --- a/generate/input/descriptor.json +++ b/generate/input/descriptor.json @@ -782,10 +782,38 @@ } }, "git_index_remove_all": { - "ignore": true + "args": { + "pathspec": { + "isOptional": true + }, + "flags": { + "isOptional": true + }, + "callback": { + "isOptional": true + } + }, + "isAsync": true, + "return": { + "isErrorCode": true + } }, "git_index_update_all": { - "ignore": true + "args": { + "pathspec": { + "isOptional": true + }, + "flags": { + "isOptional": true + }, + "callback": { + "isOptional": true + } + }, + "isAsync": true, + "return": { + "isErrorCode": true + } }, "git_index_write": { "args": { diff --git a/lib/index.js b/lib/index.js index c8d9b65e0..fcdb65d39 100644 --- a/lib/index.js +++ b/lib/index.js @@ -22,4 +22,14 @@ Index.prototype.addAll = function(pathspec, flags, matchedCallback) { return addAll.call(this, pathspec, flags, matchedCallback, null); }; +var removeAll = Index.prototype.removeAll; +Index.prototype.removeAll = function(pathspec, matchedCallback) { + return removeAll.call(this, pathspec, matchedCallback, null); +}; + +var updateAll = Index.prototype.updateAll; +Index.prototype.updateAll = function(pathspec, matchedCallback) { + return updateAll.call(this, pathspec, matchedCallback, null); +}; + module.exports = Index; diff --git a/test/tests/index.js b/test/tests/index.js index be1b280f4..babf4cbb7 100644 --- a/test/tests/index.js +++ b/test/tests/index.js @@ -54,6 +54,93 @@ describe("Index", function() { }); assert.equal(newFiles.length, 2); + }) + .then(function() { + return Promise.all(fileNames.map(function(fileName) { + fse.remove(path.join(repo.workdir(), fileName)); + })); + }) + .then(function() { + index.clear(); + }); + }); + + it("can remove entries from the index", function() { + var repo = this.repo; + var index = this.index; + var fileContent = { + newFile1: "this has some content", + newFile2: "and this will have more content", + differentFileName: "this has a different name and shouldn't be deleted" + }; + var fileNames = Object.keys(fileContent); + + return Promise.all(fileNames.map(function(fileName) { + fse.writeFile(path.join(repo.workdir(), fileName), fileContent[fileName]); + })) + .then(function() { + return index.addAll(); + }) + .then(function() { + var newFiles = index.entries().filter(function(entry) { + return ~fileNames.indexOf(entry.path()); + }); + + assert.equal(newFiles.length, 3); + + return index.removeAll("newFile*"); + }) + .then(function() { + var newFiles = index.entries().filter(function(entry) { + return ~fileNames.indexOf(entry.path()); + }); + + assert.equal(newFiles.length, 1); + }) + .then(function() { + return Promise.all(fileNames.map(function(fileName) { + fse.remove(path.join(repo.workdir(), fileName)); + })); + }) + .then(function() { + index.clear(); + }); + }); + + it("can update entries in the index", function() { + var repo = this.repo; + var index = this.index; + var fileContent = { + newFile1: "this has some content", + newFile2: "and this will have more content" + }; + var fileNames = Object.keys(fileContent); + + return Promise.all(fileNames.map(function(fileName) { + fse.writeFile(path.join(repo.workdir(), fileName), fileContent[fileName]); + })) + .then(function() { + return index.addAll(); + }) + .then(function() { + var newFiles = index.entries().filter(function(entry) { + return ~fileNames.indexOf(entry.path()); + }); + + assert.equal(newFiles.length, 2); + + return fse.remove(path.join(repo.workdir(), fileNames[0])); + }) + .then(function() { + return index.updateAll("newFile*"); + }) + .then(function() { + var newFiles = index.entries().filter(function(entry) { + return ~fileNames.indexOf(entry.path()); + }); + + assert.equal(newFiles.length, 1); + return fse.remove(path.join(repo.workdir(), fileNames[1])); }); }); });