mirror of
https://github.com/SkinnyMind/libgit2dart.git
synced 2025-05-05 04:39:07 -04:00
feat(config): add ability to get value(s) of multivar variable
This commit is contained in:
parent
4988b295a5
commit
6a08a7b803
3 changed files with 68 additions and 6 deletions
|
@ -247,8 +247,36 @@ void deleteVariable(Pointer<git_config> cfg, String name) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Iterate over the values of multivar
|
/// Iterate over the values of a multivar
|
||||||
// TODO
|
///
|
||||||
|
/// If regexp is present, then the iterator will only iterate over all
|
||||||
|
/// values which match the pattern.
|
||||||
|
List<String> getMultivar(
|
||||||
|
Pointer<git_config> cfg,
|
||||||
|
String name,
|
||||||
|
String? regexp,
|
||||||
|
) {
|
||||||
|
final nameC = name.toNativeUtf8().cast<Int8>();
|
||||||
|
final regexpC = regexp?.toNativeUtf8().cast<Int8>() ?? nullptr;
|
||||||
|
final iterator = calloc<Pointer<git_config_iterator>>();
|
||||||
|
final entry = calloc<Pointer<git_config_entry>>();
|
||||||
|
libgit2.git_config_multivar_iterator_new(iterator, cfg, nameC, regexpC);
|
||||||
|
var error = 0;
|
||||||
|
final entries = <String>[];
|
||||||
|
|
||||||
/// Multivars variables get/set
|
while (error == 0) {
|
||||||
// TODO
|
error = libgit2.git_config_next(entry, iterator.value);
|
||||||
|
if (error != -31) {
|
||||||
|
entries.add(entry.value.ref.value.cast<Utf8>().toDartString());
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
calloc.free(nameC);
|
||||||
|
calloc.free(regexpC);
|
||||||
|
calloc.free(iterator);
|
||||||
|
calloc.free(entry);
|
||||||
|
|
||||||
|
return entries;
|
||||||
|
}
|
||||||
|
|
|
@ -142,6 +142,14 @@ class Config {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns list of values for multivar [key]
|
||||||
|
///
|
||||||
|
/// If [regexp] is present, then the iterator will only iterate over all
|
||||||
|
/// values which match the pattern.
|
||||||
|
List<String> getMultivar(String key, {String? regexp}) {
|
||||||
|
return config.getMultivar(configPointer.value, key, regexp);
|
||||||
|
}
|
||||||
|
|
||||||
/// Releases memory allocated for config object.
|
/// Releases memory allocated for config object.
|
||||||
void close() {
|
void close() {
|
||||||
calloc.free(configPointer);
|
calloc.free(configPointer);
|
||||||
|
|
|
@ -8,6 +8,16 @@ import 'package:libgit2dart/src/error.dart';
|
||||||
void main() {
|
void main() {
|
||||||
final tmpDir = Directory.systemTemp.path;
|
final tmpDir = Directory.systemTemp.path;
|
||||||
const configFileName = 'test_config';
|
const configFileName = 'test_config';
|
||||||
|
const contents = '''
|
||||||
|
[core]
|
||||||
|
repositoryformatversion = 0
|
||||||
|
bare = false
|
||||||
|
gitproxy = proxy-command for kernel.org
|
||||||
|
gitproxy = default-proxy
|
||||||
|
[remote "origin"]
|
||||||
|
url = someurl
|
||||||
|
''';
|
||||||
|
|
||||||
late Config config;
|
late Config config;
|
||||||
|
|
||||||
group('Config', () {
|
group('Config', () {
|
||||||
|
@ -16,8 +26,7 @@ void main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
setUp(() {
|
setUp(() {
|
||||||
File('$tmpDir/$configFileName').writeAsStringSync(
|
File('$tmpDir/$configFileName').writeAsStringSync(contents);
|
||||||
'[core]\n\trepositoryformatversion = 0\n\tbare = false\n[remote "origin"]\n\turl = someurl');
|
|
||||||
config = Config.open(path: '$tmpDir/$configFileName');
|
config = Config.open(path: '$tmpDir/$configFileName');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -64,6 +73,23 @@ void main() {
|
||||||
throwsA(isA<LibGit2Error>()),
|
throwsA(isA<LibGit2Error>()),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('returns values of multivar', () {
|
||||||
|
expect(
|
||||||
|
config.getMultivar('core.gitproxy'),
|
||||||
|
[
|
||||||
|
'proxy-command for kernel.org',
|
||||||
|
'default-proxy',
|
||||||
|
],
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('returns values of multivar with regexp', () {
|
||||||
|
expect(
|
||||||
|
config.getMultivar('core.gitproxy', regexp: 'for kernel.org\$'),
|
||||||
|
['proxy-command for kernel.org'],
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue