Skip to content

Commit 5f60002

Browse files
committed
Merge pull request #414 from nodegit/enable-index-remove-update-all
Enable `git_index_remove_all` and `git_index_update_all`
2 parents 801fc83 + 420a088 commit 5f60002

3 files changed

Lines changed: 127 additions & 2 deletions

File tree

generate/input/descriptor.json

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -782,10 +782,38 @@
782782
}
783783
},
784784
"git_index_remove_all": {
785-
"ignore": true
785+
"args": {
786+
"pathspec": {
787+
"isOptional": true
788+
},
789+
"flags": {
790+
"isOptional": true
791+
},
792+
"callback": {
793+
"isOptional": true
794+
}
795+
},
796+
"isAsync": true,
797+
"return": {
798+
"isErrorCode": true
799+
}
786800
},
787801
"git_index_update_all": {
788-
"ignore": true
802+
"args": {
803+
"pathspec": {
804+
"isOptional": true
805+
},
806+
"flags": {
807+
"isOptional": true
808+
},
809+
"callback": {
810+
"isOptional": true
811+
}
812+
},
813+
"isAsync": true,
814+
"return": {
815+
"isErrorCode": true
816+
}
789817
},
790818
"git_index_write": {
791819
"args": {

lib/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,14 @@ Index.prototype.addAll = function(pathspec, flags, matchedCallback) {
2222
return addAll.call(this, pathspec, flags, matchedCallback, null);
2323
};
2424

25+
var removeAll = Index.prototype.removeAll;
26+
Index.prototype.removeAll = function(pathspec, matchedCallback) {
27+
return removeAll.call(this, pathspec, matchedCallback, null);
28+
};
29+
30+
var updateAll = Index.prototype.updateAll;
31+
Index.prototype.updateAll = function(pathspec, matchedCallback) {
32+
return updateAll.call(this, pathspec, matchedCallback, null);
33+
};
34+
2535
module.exports = Index;

test/tests/index.js

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,93 @@ describe("Index", function() {
5454
});
5555

5656
assert.equal(newFiles.length, 2);
57+
})
58+
.then(function() {
59+
return Promise.all(fileNames.map(function(fileName) {
60+
fse.remove(path.join(repo.workdir(), fileName));
61+
}));
62+
})
63+
.then(function() {
64+
index.clear();
65+
});
66+
});
67+
68+
it("can remove entries from the index", function() {
69+
var repo = this.repo;
70+
var index = this.index;
71+
var fileContent = {
72+
newFile1: "this has some content",
73+
newFile2: "and this will have more content",
74+
differentFileName: "this has a different name and shouldn't be deleted"
75+
};
76+
var fileNames = Object.keys(fileContent);
77+
78+
return Promise.all(fileNames.map(function(fileName) {
79+
fse.writeFile(path.join(repo.workdir(), fileName), fileContent[fileName]);
80+
}))
81+
.then(function() {
82+
return index.addAll();
83+
})
84+
.then(function() {
85+
var newFiles = index.entries().filter(function(entry) {
86+
return ~fileNames.indexOf(entry.path());
87+
});
88+
89+
assert.equal(newFiles.length, 3);
90+
91+
return index.removeAll("newFile*");
92+
})
93+
.then(function() {
94+
var newFiles = index.entries().filter(function(entry) {
95+
return ~fileNames.indexOf(entry.path());
96+
});
97+
98+
assert.equal(newFiles.length, 1);
99+
})
100+
.then(function() {
101+
return Promise.all(fileNames.map(function(fileName) {
102+
fse.remove(path.join(repo.workdir(), fileName));
103+
}));
104+
})
105+
.then(function() {
106+
index.clear();
107+
});
108+
});
109+
110+
it("can update entries in the index", function() {
111+
var repo = this.repo;
112+
var index = this.index;
113+
var fileContent = {
114+
newFile1: "this has some content",
115+
newFile2: "and this will have more content"
116+
};
117+
var fileNames = Object.keys(fileContent);
118+
119+
return Promise.all(fileNames.map(function(fileName) {
120+
fse.writeFile(path.join(repo.workdir(), fileName), fileContent[fileName]);
121+
}))
122+
.then(function() {
123+
return index.addAll();
124+
})
125+
.then(function() {
126+
var newFiles = index.entries().filter(function(entry) {
127+
return ~fileNames.indexOf(entry.path());
128+
});
129+
130+
assert.equal(newFiles.length, 2);
131+
132+
return fse.remove(path.join(repo.workdir(), fileNames[0]));
133+
})
134+
.then(function() {
135+
return index.updateAll("newFile*");
136+
})
137+
.then(function() {
138+
var newFiles = index.entries().filter(function(entry) {
139+
return ~fileNames.indexOf(entry.path());
140+
});
141+
142+
assert.equal(newFiles.length, 1);
143+
return fse.remove(path.join(repo.workdir(), fileNames[1]));
57144
});
58145
});
59146
});

0 commit comments

Comments
 (0)