mirror of
https://github.com/SkinnyMind/libgit2dart.git
synced 2025-05-05 04:39:07 -04:00
feat(repository): add ability to initialize repository
This commit is contained in:
parent
543ebff223
commit
696d55bb3a
3 changed files with 59 additions and 1 deletions
|
@ -69,6 +69,22 @@ String discover(String startPath, String ceilingDirs) {
|
|||
return result;
|
||||
}
|
||||
|
||||
/// Creates a new Git repository in the given folder.
|
||||
///
|
||||
/// Throws a [LibGit2Error] if error occured.
|
||||
Pointer<git_repository> init(String path, bool isBare) {
|
||||
final out = calloc<Pointer<git_repository>>();
|
||||
final pathC = path.toNativeUtf8().cast<Int8>();
|
||||
final isBareC = isBare ? 1 : 0;
|
||||
final error = libgit2.git_repository_init(out, pathC, isBareC);
|
||||
|
||||
if (error < 0) {
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
}
|
||||
|
||||
return out.value;
|
||||
}
|
||||
|
||||
/// Returns the path to the `.git` folder for normal repositories or the
|
||||
/// repository itself for bare repositories.
|
||||
String path(Pointer<git_repository> repo) {
|
||||
|
|
|
@ -10,12 +10,24 @@ import 'util.dart';
|
|||
|
||||
/// A Repository is the primary interface into a git repository
|
||||
class Repository {
|
||||
/// Initializes a new instance of the [Repository] class by creating a new
|
||||
/// Git repository in the given folder.
|
||||
///
|
||||
/// Should be freed with `free()` to release allocated memory.
|
||||
///
|
||||
/// Throws a [LibGit2Error] if error occured.
|
||||
Repository.init(String path, {bool isBare = false}) {
|
||||
libgit2.git_libgit2_init();
|
||||
|
||||
_repoPointer = bindings.init(path, isBare);
|
||||
}
|
||||
|
||||
/// Initializes a new instance of the [Repository] class.
|
||||
/// For a standard repository, [path] should either point to the `.git` folder
|
||||
/// or to the working directory. For a bare repository, [path] should directly
|
||||
/// point to the repository folder.
|
||||
///
|
||||
/// [Repository] object should be close with [free] function to release allocated memory.
|
||||
/// Should be freed with `free()` to release allocated memory.
|
||||
///
|
||||
/// Throws a [LibGit2Error] if error occured.
|
||||
Repository.open(String path) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue