mirror of
https://github.com/SkinnyMind/libgit2dart.git
synced 2025-05-05 04:39:07 -04:00
feat(repository): add ability to set and get namespace
This commit is contained in:
parent
b8b69100f1
commit
9acf3a8a9e
3 changed files with 45 additions and 19 deletions
|
@ -70,6 +70,24 @@ String getNamespace(Pointer<git_repository> repo) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Sets the active namespace for this repository.
|
||||||
|
///
|
||||||
|
/// This namespace affects all reference operations for the repo. See `man gitnamespaces`
|
||||||
|
///
|
||||||
|
/// The [namespace] should not include the refs folder, e.g. to namespace all references
|
||||||
|
/// under refs/namespaces/foo/, use foo as the namespace.
|
||||||
|
///
|
||||||
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
|
void setNamespace(Pointer<git_repository> repo, String? namespace) {
|
||||||
|
final nmspace = namespace?.toNativeUtf8().cast<Int8>() ?? nullptr;
|
||||||
|
final error = libgit2.git_repository_set_namespace(repo, nmspace);
|
||||||
|
calloc.free(nmspace);
|
||||||
|
|
||||||
|
if (error < 0) {
|
||||||
|
throw LibGit2Error(libgit2.git_error_last());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Check if a repository is bare or not.
|
/// Check if a repository is bare or not.
|
||||||
bool isBare(Pointer<git_repository> repo) {
|
bool isBare(Pointer<git_repository> repo) {
|
||||||
final result = libgit2.git_repository_is_bare(repo);
|
final result = libgit2.git_repository_is_bare(repo);
|
||||||
|
@ -331,24 +349,6 @@ void setHeadDetachedFromAnnotated(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the active namespace for this Git Repository
|
|
||||||
///
|
|
||||||
/// This namespace affects all reference operations for the repo. See `man gitnamespaces`
|
|
||||||
///
|
|
||||||
/// The [namespace] should not include the refs folder, e.g. to namespace all references
|
|
||||||
/// under refs/namespaces/foo/, use foo as the namespace.
|
|
||||||
///
|
|
||||||
/// Throws a [LibGit2Error] if error occured.
|
|
||||||
void setNamespace(Pointer<git_repository> repo, String namespace) {
|
|
||||||
final nmspace = namespace.toNativeUtf8().cast<Int8>();
|
|
||||||
final error = libgit2.git_repository_set_namespace(repo, nmspace);
|
|
||||||
calloc.free(nmspace);
|
|
||||||
|
|
||||||
if (error < 0) {
|
|
||||||
throw LibGit2Error(libgit2.git_error_last());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Set the path to the working directory for this repository
|
/// Set the path to the working directory for this repository
|
||||||
///
|
///
|
||||||
/// The working directory doesn't need to be the same one that contains the
|
/// The working directory doesn't need to be the same one that contains the
|
||||||
|
|
|
@ -44,6 +44,24 @@ class Repository {
|
||||||
/// empty string is returned.
|
/// empty string is returned.
|
||||||
String getNamespace() => bindings.getNamespace(_repoPointer);
|
String getNamespace() => bindings.getNamespace(_repoPointer);
|
||||||
|
|
||||||
|
/// Sets the active namespace for this repository.
|
||||||
|
///
|
||||||
|
/// This namespace affects all reference operations for the repo. See `man gitnamespaces`
|
||||||
|
///
|
||||||
|
/// The [namespace] should not include the refs folder, e.g. to namespace all references
|
||||||
|
/// under refs/namespaces/foo/, use foo as the namespace.
|
||||||
|
///
|
||||||
|
/// Pass null to unset.
|
||||||
|
///
|
||||||
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
|
void setNamespace(String? namespace) {
|
||||||
|
try {
|
||||||
|
bindings.setNamespace(_repoPointer, namespace);
|
||||||
|
} catch (e) {
|
||||||
|
rethrow;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Checks whether this repository is a bare repository or not.
|
/// Checks whether this repository is a bare repository or not.
|
||||||
bool isBare() => bindings.isBare(_repoPointer);
|
bool isBare() => bindings.isBare(_repoPointer);
|
||||||
|
|
||||||
|
@ -85,7 +103,7 @@ class Repository {
|
||||||
/// Sets the identity to be used for writing reflogs.
|
/// Sets the identity to be used for writing reflogs.
|
||||||
///
|
///
|
||||||
/// If both are set, this name and email will be used to write to the reflog.
|
/// If both are set, this name and email will be used to write to the reflog.
|
||||||
/// Pass NULL to unset. When unset, the identity will be taken from the repository's configuration.
|
/// Pass null to unset. When unset, the identity will be taken from the repository's configuration.
|
||||||
void setIdentity({required String? name, required String? email}) {
|
void setIdentity({required String? name, required String? email}) {
|
||||||
bindings.setIdentity(_repoPointer, name, email);
|
bindings.setIdentity(_repoPointer, name, email);
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,6 +83,14 @@ void main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('returns empty string when there is no namespace', () {
|
test('returns empty string when there is no namespace', () {
|
||||||
|
expect(repo.getNamespace(), isEmpty);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('successfully sets and unsets the namespace', () {
|
||||||
|
expect(repo.getNamespace(), '');
|
||||||
|
repo.setNamespace('some');
|
||||||
|
expect(repo.getNamespace(), 'some');
|
||||||
|
repo.setNamespace(null);
|
||||||
expect(repo.getNamespace(), '');
|
expect(repo.getNamespace(), '');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue