Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add binding for git_config_delete_multivar #1056

Merged
merged 1 commit into from
Dec 24, 2020
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
11 changes: 11 additions & 0 deletions pygit2/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,17 @@ def set_multivar(self, name, regex, value):
to_bytes(regex), to_bytes(value))
check_error(err)

def delete_multivar(self, name, regex):
"""Delete a multivar ''name''. ''regexp'' is a regular expression to
indicate which values to delete.
"""
assert_string(name, "name")
assert_string(regex, "regex")

err = C.git_config_delete_multivar(self._config, to_bytes(name),
to_bytes(regex))
check_error(err)

def get_bool(self, key):
"""Look up *key* and parse its value as a boolean as per the git-config
rules. Return a boolean value (True or False).
Expand Down
1 change: 1 addition & 0 deletions pygit2/decl/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ int git_config_next(git_config_entry **entry, git_config_iterator *iter);
void git_config_iterator_free(git_config_iterator *iter);
int git_config_multivar_iterator_new(git_config_iterator **out, const git_config *cfg, const char *name, const char *regexp);
int git_config_set_multivar(git_config *cfg, const char *name, const char *regexp, const char *value);
int git_config_delete_multivar(git_config *cfg, const char *name, const char *regexp);
int git_config_new(git_config **out);
int git_config_snapshot(git_config **out, git_config *config);
int git_config_open_ondisk(git_config **out, const char *path);
Expand Down
8 changes: 8 additions & 0 deletions test/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,14 @@ def test_write(config):
for i in l:
assert i == 'foo-123456'

config.delete_multivar('this.that', 'bar')
l = config.get_multivar('this.that', '')
assert 2 == len(list(l))

config.delete_multivar('this.that', r'foo-\d+')
l = config.get_multivar('this.that', '')
assert 0 == len(list(l))

def test_iterator(config):
lst = {}
for entry in config:
Expand Down