mirror of
https://github.com/SkinnyMind/libgit2dart.git
synced 2025-05-04 12:19:09 -04:00
docs(reference): update examples
This commit is contained in:
parent
627519a31f
commit
f5e43f3d90
2 changed files with 43 additions and 2 deletions
16
example/helpers.dart
Normal file
16
example/helpers.dart
Normal file
|
@ -0,0 +1,16 @@
|
|||
import 'dart:io';
|
||||
import '../test/helpers/util.dart';
|
||||
|
||||
Future<void> prepareRepo(String path) async {
|
||||
if (await Directory(path).exists()) {
|
||||
await Directory(path).delete(recursive: true);
|
||||
}
|
||||
await copyRepo(
|
||||
from: Directory('test/assets/testrepo/'),
|
||||
to: await Directory(path).create(),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> disposeRepo(String path) async {
|
||||
await Directory(path).delete(recursive: true);
|
||||
}
|
|
@ -1,18 +1,43 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:libgit2dart/libgit2dart.dart';
|
||||
import 'helpers.dart';
|
||||
|
||||
void main() {
|
||||
final repo = Repository.open(Directory.current.path);
|
||||
void main() async {
|
||||
// Preparing example repository.
|
||||
final tmpDir = '${Directory.systemTemp.path}/example_repo/';
|
||||
await prepareRepo(tmpDir);
|
||||
|
||||
final repo = Repository.open(tmpDir);
|
||||
|
||||
// Get list of repo's references.
|
||||
print('Repository references: ${repo.references.list()}');
|
||||
|
||||
// Get reference by name.
|
||||
final ref = repo.references['refs/heads/master'];
|
||||
|
||||
print('Reference SHA hex: ${ref.target.sha}');
|
||||
print('Is reference a local branch: ${ref.isBranch}');
|
||||
print('Reference full name: ${ref.name}');
|
||||
print('Reference shorthand name: ${ref.shorthand}');
|
||||
|
||||
// Create new reference (direct or symbolic).
|
||||
final newRef = repo.createReference(
|
||||
name: 'refs/tags/v1',
|
||||
target: 'refs/heads/master',
|
||||
);
|
||||
|
||||
// Rename reference.
|
||||
newRef.rename('refs/tags/v1.1');
|
||||
|
||||
// Delete reference.
|
||||
newRef.delete();
|
||||
|
||||
// free() should be called on object to free memory when done.
|
||||
ref.free();
|
||||
newRef.free();
|
||||
repo.free();
|
||||
|
||||
// Removing example repository.
|
||||
await disposeRepo(tmpDir);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue