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
32 changes: 30 additions & 2 deletions generate/input/descriptor.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
10 changes: 10 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
87 changes: 87 additions & 0 deletions test/tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]));
});
});
});