mirror of
https://github.com/SkinnyMind/libgit2dart.git
synced 2025-05-05 04:39:07 -04:00
feat(reference): add base bindings and api
This commit is contained in:
parent
145af3054d
commit
5f60a693d3
8 changed files with 413 additions and 6 deletions
|
@ -1,5 +1,6 @@
|
|||
import 'dart:ffi';
|
||||
import 'package:ffi/ffi.dart';
|
||||
import 'reference.dart';
|
||||
import 'bindings/libgit2_bindings.dart';
|
||||
import 'bindings/repository.dart' as bindings;
|
||||
import 'util.dart';
|
||||
|
@ -24,9 +25,11 @@ class Repository {
|
|||
}
|
||||
}
|
||||
|
||||
/// Pointer to memory address for allocated repository object.
|
||||
late final Pointer<git_repository> _repoPointer;
|
||||
|
||||
/// Pointer to memory address for allocated repository object.
|
||||
Pointer<git_repository> get pointer => _repoPointer;
|
||||
|
||||
/// Returns path to the `.git` folder for normal repositories
|
||||
/// or path to the repository itself for bare repositories.
|
||||
String get path => bindings.path(_repoPointer);
|
||||
|
@ -86,6 +89,23 @@ class Repository {
|
|||
}
|
||||
}
|
||||
|
||||
/// Returns reference object pointing to repository head.
|
||||
Reference get head => Reference(bindings.head(_repoPointer));
|
||||
|
||||
/// Returns a map with all the references names and corresponding SHA hexes
|
||||
/// that can be found in a repository.
|
||||
Map<String, String> get references {
|
||||
var refMap = <String, String>{};
|
||||
final refList = Reference.list(_repoPointer);
|
||||
for (var ref in refList) {
|
||||
final r = Reference.lookup(this, ref);
|
||||
refMap[ref] = r.target;
|
||||
r.free();
|
||||
}
|
||||
|
||||
return refMap;
|
||||
}
|
||||
|
||||
/// Makes the repository HEAD point to the specified reference.
|
||||
///
|
||||
/// If the provided [reference] points to a Tree or a Blob, the HEAD is unaltered.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue