libgit2dart/test/reset_test.dart
2021-10-13 15:31:20 +03:00

63 lines
1.6 KiB
Dart

import 'dart:io';
import 'package:test/test.dart';
import 'package:libgit2dart/libgit2dart.dart';
import 'helpers/util.dart';
void main() {
late Repository repo;
late Directory tmpDir;
late File file;
const sha = '6cbc22e509d72758ab4c8d9f287ea846b90c448b';
setUp(() {
tmpDir = setupRepo(Directory('test/assets/testrepo/'));
file = File('${tmpDir.path}/feature_file');
repo = Repository.open(tmpDir.path);
});
tearDown(() {
repo.free();
tmpDir.deleteSync(recursive: true);
});
group('Reset', () {
test('successfully resets with hard', () {
var contents = file.readAsStringSync();
expect(contents, 'Feature edit\n');
repo.reset(oid: repo[sha], resetType: GitReset.hard);
contents = file.readAsStringSync();
expect(contents, isEmpty);
});
test('successfully resets with soft', () {
var contents = file.readAsStringSync();
expect(contents, 'Feature edit\n');
repo.reset(oid: repo[sha], resetType: GitReset.soft);
contents = file.readAsStringSync();
expect(contents, 'Feature edit\n');
final index = repo.index;
final diff = index.diffToWorkdir();
expect(diff.deltas, isEmpty);
index.free();
});
test('successfully resets with mixed', () {
var contents = file.readAsStringSync();
expect(contents, 'Feature edit\n');
repo.reset(oid: repo[sha], resetType: GitReset.mixed);
contents = file.readAsStringSync();
expect(contents, 'Feature edit\n');
final index = repo.index;
final diff = index.diffToWorkdir();
expect(diff.deltas.length, 1);
index.free();
});
});
}