mirror of
https://github.com/SkinnyMind/libgit2dart.git
synced 2025-05-04 20:29:08 -04:00
feat(checkout): add bindings and api
This commit is contained in:
parent
659e69b1f2
commit
628aa610d8
4 changed files with 358 additions and 5 deletions
96
test/checkout_test.dart
Normal file
96
test/checkout_test.dart
Normal file
|
@ -0,0 +1,96 @@
|
|||
import 'dart:io';
|
||||
import 'package:libgit2dart/src/git_types.dart';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:libgit2dart/libgit2dart.dart';
|
||||
import 'helpers/util.dart';
|
||||
|
||||
void main() {
|
||||
late Repository repo;
|
||||
final tmpDir = '${Directory.systemTemp.path}/checkout_testrepo/';
|
||||
|
||||
setUp(() async {
|
||||
if (await Directory(tmpDir).exists()) {
|
||||
await Directory(tmpDir).delete(recursive: true);
|
||||
}
|
||||
await copyRepo(
|
||||
from: Directory('test/assets/testrepo/'),
|
||||
to: await Directory(tmpDir).create(),
|
||||
);
|
||||
repo = Repository.open(tmpDir);
|
||||
});
|
||||
|
||||
tearDown(() async {
|
||||
repo.free();
|
||||
await Directory(tmpDir).delete(recursive: true);
|
||||
});
|
||||
|
||||
group('Checkout', () {
|
||||
test('successfully checkouts head', () {
|
||||
File('${tmpDir}feature_file').writeAsStringSync('edit');
|
||||
expect(repo.status, contains('feature_file'));
|
||||
|
||||
repo.checkout(refName: 'HEAD', strategy: [GitCheckout.force]);
|
||||
expect(repo.status, isEmpty);
|
||||
});
|
||||
|
||||
test('successfully checkouts index', () {
|
||||
File('${repo.workdir}feature_file').writeAsStringSync('edit');
|
||||
expect(repo.status, contains('feature_file'));
|
||||
|
||||
repo.checkout(strategy: [GitCheckout.force]);
|
||||
expect(repo.status, isEmpty);
|
||||
});
|
||||
|
||||
test('successfully checkouts tree', () {
|
||||
final masterHead =
|
||||
repo['821ed6e80627b8769d170a293862f9fc60825226'] as Commit;
|
||||
final masterTree = repo[masterHead.tree.sha] as Tree;
|
||||
expect(
|
||||
masterTree.entries.any((e) => e.name == 'another_feature_file'),
|
||||
false,
|
||||
);
|
||||
|
||||
repo.checkout(refName: 'refs/heads/feature');
|
||||
final featureHead =
|
||||
repo['5aecfa0fb97eadaac050ccb99f03c3fb65460ad4'] as Commit;
|
||||
final featureTree = repo[featureHead.tree.sha] as Tree;
|
||||
final repoHead = repo.head;
|
||||
expect(repoHead.target.sha, featureHead.id.sha);
|
||||
expect(repo.status, isEmpty);
|
||||
expect(
|
||||
featureTree.entries.any((e) => e.name == 'another_feature_file'),
|
||||
true,
|
||||
);
|
||||
|
||||
repoHead.free();
|
||||
featureTree.free();
|
||||
featureHead.free();
|
||||
masterTree.free();
|
||||
masterHead.free();
|
||||
});
|
||||
|
||||
test('successfully checkouts with alrenative directory', () {
|
||||
final altDir = '${Directory.systemTemp.path}/alt_dir';
|
||||
// making sure there is no directory
|
||||
if (Directory(altDir).existsSync()) {
|
||||
Directory(altDir).deleteSync(recursive: true);
|
||||
}
|
||||
Directory(altDir).createSync();
|
||||
expect(Directory(altDir).listSync().length, 0);
|
||||
|
||||
repo.checkout(refName: 'refs/heads/feature', directory: altDir);
|
||||
expect(Directory(altDir).listSync().length, isNot(0));
|
||||
|
||||
Directory(altDir).deleteSync(recursive: true);
|
||||
});
|
||||
|
||||
test('successfully checkouts file with provided path', () {
|
||||
expect(repo.status, isEmpty);
|
||||
repo.checkout(
|
||||
refName: 'refs/heads/feature',
|
||||
paths: ['another_feature_file'],
|
||||
);
|
||||
expect(repo.status, {'another_feature_file': GitStatus.indexNew.value});
|
||||
});
|
||||
});
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue