mirror of
https://github.com/SkinnyMind/libgit2dart.git
synced 2025-05-04 20:29:08 -04:00
feat(config): add ability to set value of multivar variable
This commit is contained in:
parent
6a08a7b803
commit
7bea406ab9
3 changed files with 51 additions and 6 deletions
|
@ -280,3 +280,23 @@ List<String> getMultivar(
|
||||||
|
|
||||||
return entries;
|
return entries;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Set the value of a multivar config variable in the config file with the
|
||||||
|
/// highest level (usually the local one).
|
||||||
|
///
|
||||||
|
/// The regular expression is applied case-sensitively on the value.
|
||||||
|
void setMultivar(
|
||||||
|
Pointer<git_config> cfg,
|
||||||
|
String name,
|
||||||
|
String regexp,
|
||||||
|
String value,
|
||||||
|
) {
|
||||||
|
final nameC = name.toNativeUtf8().cast<Int8>();
|
||||||
|
final regexpC = regexp.toNativeUtf8().cast<Int8>();
|
||||||
|
final valueC = value.toNativeUtf8().cast<Int8>();
|
||||||
|
libgit2.git_config_set_multivar(cfg, nameC, regexpC, valueC);
|
||||||
|
|
||||||
|
calloc.free(nameC);
|
||||||
|
calloc.free(regexpC);
|
||||||
|
calloc.free(valueC);
|
||||||
|
}
|
||||||
|
|
|
@ -113,7 +113,7 @@ class Config {
|
||||||
/// Map of key/value entries from config file.
|
/// Map of key/value entries from config file.
|
||||||
Map<String, dynamic> variables = {};
|
Map<String, dynamic> variables = {};
|
||||||
|
|
||||||
/// Sets value of config key
|
/// Sets the [value] of config [key]
|
||||||
void setVariable(String key, dynamic value) {
|
void setVariable(String key, dynamic value) {
|
||||||
try {
|
try {
|
||||||
if (value.runtimeType == bool) {
|
if (value.runtimeType == bool) {
|
||||||
|
@ -150,6 +150,15 @@ class Config {
|
||||||
return config.getMultivar(configPointer.value, key, regexp);
|
return config.getMultivar(configPointer.value, key, regexp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Sets the [value] of a multivar [key] in the config file with the
|
||||||
|
/// highest level (usually the local one).
|
||||||
|
///
|
||||||
|
/// The [regexp] is applied case-sensitively on the value.
|
||||||
|
/// Empty [regexp] sets [value] for all values of a multivar [key]
|
||||||
|
void setMultivar(String key, String regexp, String value) {
|
||||||
|
config.setMultivar(configPointer.value, key, regexp, value);
|
||||||
|
}
|
||||||
|
|
||||||
/// Releases memory allocated for config object.
|
/// Releases memory allocated for config object.
|
||||||
void close() {
|
void close() {
|
||||||
calloc.free(configPointer);
|
calloc.free(configPointer);
|
||||||
|
|
|
@ -10,12 +10,12 @@ void main() {
|
||||||
const configFileName = 'test_config';
|
const configFileName = 'test_config';
|
||||||
const contents = '''
|
const contents = '''
|
||||||
[core]
|
[core]
|
||||||
repositoryformatversion = 0
|
\trepositoryformatversion = 0
|
||||||
bare = false
|
\tbare = false
|
||||||
gitproxy = proxy-command for kernel.org
|
\tgitproxy = proxy-command for kernel.org
|
||||||
gitproxy = default-proxy
|
\tgitproxy = default-proxy
|
||||||
[remote "origin"]
|
[remote "origin"]
|
||||||
url = someurl
|
\turl = someurl
|
||||||
''';
|
''';
|
||||||
|
|
||||||
late Config config;
|
late Config config;
|
||||||
|
@ -90,6 +90,22 @@ void main() {
|
||||||
['proxy-command for kernel.org'],
|
['proxy-command for kernel.org'],
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('sets value of multivar', () {
|
||||||
|
config.setMultivar('core.gitproxy', 'default', 'updated');
|
||||||
|
final multivarValues = config.getMultivar('core.gitproxy');
|
||||||
|
expect(multivarValues, isNot(contains('default-proxy')));
|
||||||
|
expect(multivarValues, contains('updated'));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('sets value for all multivar values when regexp is empty', () {
|
||||||
|
config.setMultivar('core.gitproxy', '', 'updated');
|
||||||
|
final multivarValues = config.getMultivar('core.gitproxy');
|
||||||
|
expect(multivarValues, isNot(contains('default-proxy')));
|
||||||
|
expect(multivarValues, isNot(contains('proxy-command for kernel.org')));
|
||||||
|
expect(multivarValues, contains('updated'));
|
||||||
|
expect(multivarValues.length, equals(2));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue