Skip to content

Commit 64abace

Browse files
committed
Add Index.remove_all() method
1 parent 33d3885 commit 64abace

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

pygit2/decl/index.h

+5
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ int git_index_add_all(
4848
unsigned int flags,
4949
git_index_matched_path_cb callback,
5050
void *payload);
51+
int git_index_remove_all(
52+
git_index *index,
53+
const git_strarray *pathspec,
54+
git_index_matched_path_cb callback,
55+
void *payload);
5156
int git_index_has_conflicts(const git_index *index);
5257
void git_index_conflict_iterator_free(
5358
git_index_conflict_iterator *iterator);

pygit2/index.py

+7
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,13 @@ def remove(self, path, level=0):
174174
err = C.git_index_remove(self._index, to_bytes(path), level)
175175
check_error(err, True)
176176

177+
def remove_all(self, pathspecs):
178+
"""Remove all index entries matching pathspecs.
179+
"""
180+
with StrArray(pathspecs) as arr:
181+
err = C.git_index_remove_all(self._index, arr, ffi.NULL, ffi.NULL)
182+
check_error(err, True)
183+
177184
def add_all(self, pathspecs=[]):
178185
"""Add or update index entries matching files in the working directory.
179186

test/test_index.py

+9
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,15 @@ def test_remove(self):
177177
index.remove('hello.txt')
178178
assert 'hello.txt' not in index
179179

180+
def test_remove_all(self):
181+
index = self.repo.index
182+
print([i.path for i in index])
183+
assert 'hello.txt' in index
184+
index.remove_all(['*.txt'])
185+
assert 'hello.txt' not in index
186+
187+
index.remove_all(['not-existing']) # this doesn't error
188+
180189
def test_change_attributes(self):
181190
index = self.repo.index
182191
entry = index['hello.txt']

0 commit comments

Comments
 (0)