mirror of
https://github.com/SkinnyMind/libgit2dart.git
synced 2025-05-04 20:29:08 -04:00
feat(worktree): add base bindings and api
This commit is contained in:
parent
11dbb8195d
commit
a00078ba76
5 changed files with 224 additions and 2 deletions
73
test/worktree_test.dart
Normal file
73
test/worktree_test.dart
Normal file
|
@ -0,0 +1,73 @@
|
|||
import 'dart:io';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:libgit2dart/libgit2dart.dart';
|
||||
import 'helpers/util.dart';
|
||||
|
||||
void main() {
|
||||
late Repository repo;
|
||||
final tmpDir = '${Directory.systemTemp.path}/worktree_testrepo/';
|
||||
final worktreeDir = '${Directory.systemTemp.path}/worktree';
|
||||
|
||||
setUp(() async {
|
||||
if (await Directory(tmpDir).exists()) {
|
||||
await Directory(tmpDir).delete(recursive: true);
|
||||
}
|
||||
|
||||
if (await Directory(worktreeDir).exists()) {
|
||||
await Directory(worktreeDir).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);
|
||||
if (await Directory(worktreeDir).exists()) {
|
||||
await Directory(worktreeDir).delete(recursive: true);
|
||||
}
|
||||
});
|
||||
|
||||
group('Worktree', () {
|
||||
test('successfully creates worktree at provided path', () {
|
||||
const worktreeName = 'worktree';
|
||||
expect(Worktree.list(repo), []);
|
||||
|
||||
final worktree = Worktree.create(
|
||||
repo: repo,
|
||||
name: worktreeName,
|
||||
path: worktreeDir,
|
||||
);
|
||||
|
||||
expect(Worktree.list(repo), [worktreeName]);
|
||||
expect(repo.branches.list(), contains(worktreeName));
|
||||
expect(worktree.name, worktreeName);
|
||||
expect(worktree.path, worktreeDir);
|
||||
expect(File('$worktreeDir/.git').existsSync(), true);
|
||||
|
||||
worktree.free();
|
||||
});
|
||||
|
||||
test('successfully prunes worktree', () {
|
||||
const worktreeName = 'worktree';
|
||||
expect(Worktree.list(repo), []);
|
||||
|
||||
final worktree = Worktree.create(
|
||||
repo: repo,
|
||||
name: worktreeName,
|
||||
path: worktreeDir,
|
||||
);
|
||||
expect(Worktree.list(repo), [worktreeName]);
|
||||
|
||||
Directory(worktreeDir).deleteSync(recursive: true);
|
||||
worktree.prune();
|
||||
expect(Worktree.list(repo), []);
|
||||
|
||||
worktree.free();
|
||||
});
|
||||
});
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue