mirror of
https://github.com/SkinnyMind/libgit2dart.git
synced 2025-05-04 20:29:08 -04:00
refactor: extract repo setup for tests
This commit is contained in:
parent
10b9864219
commit
466f960c7b
26 changed files with 176 additions and 320 deletions
|
@ -1,13 +1,10 @@
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:libgit2dart/libgit2dart.dart';
|
import 'package:libgit2dart/libgit2dart.dart';
|
||||||
|
import '../test/helpers/util.dart';
|
||||||
import 'helpers.dart';
|
|
||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
// Preparing example repository.
|
// Preparing example repository.
|
||||||
final tmpDir = '${Directory.systemTemp.path}/example_repo/';
|
final tmpDir = await setupRepo(Directory('test/assets/testrepo/'));
|
||||||
await prepareRepo(tmpDir);
|
|
||||||
|
|
||||||
// Open system + global config file.
|
// Open system + global config file.
|
||||||
final config = Config.open();
|
final config = Config.open();
|
||||||
|
@ -22,7 +19,7 @@ void main() async {
|
||||||
// Open config file at provided path.
|
// Open config file at provided path.
|
||||||
// Exception is thrown if file not found.
|
// Exception is thrown if file not found.
|
||||||
try {
|
try {
|
||||||
final repoConfig = Config.open('$tmpDir/.git/config');
|
final repoConfig = Config.open('${tmpDir.path}/.git/config');
|
||||||
|
|
||||||
print('\nAll entries of repo config:');
|
print('\nAll entries of repo config:');
|
||||||
for (final entry in repoConfig) {
|
for (final entry in repoConfig) {
|
||||||
|
@ -57,5 +54,5 @@ void main() async {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Removing example repository.
|
// Removing example repository.
|
||||||
await disposeRepo(tmpDir);
|
await tmpDir.delete(recursive: true);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +0,0 @@
|
||||||
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,14 +1,12 @@
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:libgit2dart/libgit2dart.dart';
|
import 'package:libgit2dart/libgit2dart.dart';
|
||||||
import 'helpers.dart';
|
import '../test/helpers/util.dart';
|
||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
// Preparing example repository.
|
// Preparing example repository.
|
||||||
final tmpDir = '${Directory.systemTemp.path}/example_repo/';
|
final tmpDir = await setupRepo(Directory('test/assets/testrepo/'));
|
||||||
await prepareRepo(tmpDir);
|
|
||||||
|
|
||||||
final repo = Repository.open(tmpDir);
|
final repo = Repository.open(tmpDir.path);
|
||||||
|
|
||||||
// Get list of repo's references.
|
// Get list of repo's references.
|
||||||
print('Repository references: ${repo.references.list()}');
|
print('Repository references: ${repo.references.list()}');
|
||||||
|
@ -39,5 +37,5 @@ void main() async {
|
||||||
repo.free();
|
repo.free();
|
||||||
|
|
||||||
// Removing example repository.
|
// Removing example repository.
|
||||||
await disposeRepo(tmpDir);
|
await tmpDir.delete(recursive: true);
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,27 +7,21 @@ import 'helpers/util.dart';
|
||||||
void main() {
|
void main() {
|
||||||
late Repository repo;
|
late Repository repo;
|
||||||
late Blob blob;
|
late Blob blob;
|
||||||
final tmpDir = '${Directory.systemTemp.path}/blob_testrepo/';
|
late Directory tmpDir;
|
||||||
const blobSHA = '9c78c21d6680a7ffebc76f7ac68cacc11d8f48bc';
|
const blobSHA = '9c78c21d6680a7ffebc76f7ac68cacc11d8f48bc';
|
||||||
const blobContent = 'Feature edit\n';
|
const blobContent = 'Feature edit\n';
|
||||||
const newBlobContent = 'New blob\n';
|
const newBlobContent = 'New blob\n';
|
||||||
|
|
||||||
setUp(() async {
|
setUp(() async {
|
||||||
if (await Directory(tmpDir).exists()) {
|
tmpDir = await setupRepo(Directory('test/assets/testrepo/'));
|
||||||
await Directory(tmpDir).delete(recursive: true);
|
repo = Repository.open(tmpDir.path);
|
||||||
}
|
|
||||||
await copyRepo(
|
|
||||||
from: Directory('test/assets/testrepo/'),
|
|
||||||
to: await Directory(tmpDir).create(),
|
|
||||||
);
|
|
||||||
repo = Repository.open(tmpDir);
|
|
||||||
blob = Blob.lookup(repo, blobSHA);
|
blob = Blob.lookup(repo, blobSHA);
|
||||||
});
|
});
|
||||||
|
|
||||||
tearDown(() async {
|
tearDown(() async {
|
||||||
blob.free();
|
blob.free();
|
||||||
repo.free();
|
repo.free();
|
||||||
await Directory(tmpDir).delete(recursive: true);
|
await tmpDir.delete(recursive: true);
|
||||||
});
|
});
|
||||||
|
|
||||||
group('Blob', () {
|
group('Blob', () {
|
||||||
|
|
|
@ -5,24 +5,18 @@ import 'helpers/util.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
late Repository repo;
|
late Repository repo;
|
||||||
final tmpDir = '${Directory.systemTemp.path}/branch_testrepo/';
|
late Directory tmpDir;
|
||||||
const lastCommit = '821ed6e80627b8769d170a293862f9fc60825226';
|
const lastCommit = '821ed6e80627b8769d170a293862f9fc60825226';
|
||||||
const featureCommit = '5aecfa0fb97eadaac050ccb99f03c3fb65460ad4';
|
const featureCommit = '5aecfa0fb97eadaac050ccb99f03c3fb65460ad4';
|
||||||
|
|
||||||
setUp(() async {
|
setUp(() async {
|
||||||
if (await Directory(tmpDir).exists()) {
|
tmpDir = await setupRepo(Directory('test/assets/testrepo/'));
|
||||||
await Directory(tmpDir).delete(recursive: true);
|
repo = Repository.open(tmpDir.path);
|
||||||
}
|
|
||||||
await copyRepo(
|
|
||||||
from: Directory('test/assets/testrepo/'),
|
|
||||||
to: await Directory(tmpDir).create(),
|
|
||||||
);
|
|
||||||
repo = Repository.open(tmpDir);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
tearDown(() async {
|
tearDown(() async {
|
||||||
repo.free();
|
repo.free();
|
||||||
await Directory(tmpDir).delete(recursive: true);
|
await tmpDir.delete(recursive: true);
|
||||||
});
|
});
|
||||||
|
|
||||||
group('Branch', () {
|
group('Branch', () {
|
||||||
|
|
|
@ -6,27 +6,21 @@ import 'helpers/util.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
late Repository repo;
|
late Repository repo;
|
||||||
final tmpDir = '${Directory.systemTemp.path}/checkout_testrepo/';
|
late Directory tmpDir;
|
||||||
|
|
||||||
setUp(() async {
|
setUp(() async {
|
||||||
if (await Directory(tmpDir).exists()) {
|
tmpDir = await setupRepo(Directory('test/assets/testrepo/'));
|
||||||
await Directory(tmpDir).delete(recursive: true);
|
repo = Repository.open(tmpDir.path);
|
||||||
}
|
|
||||||
await copyRepo(
|
|
||||||
from: Directory('test/assets/testrepo/'),
|
|
||||||
to: await Directory(tmpDir).create(),
|
|
||||||
);
|
|
||||||
repo = Repository.open(tmpDir);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
tearDown(() async {
|
tearDown(() async {
|
||||||
repo.free();
|
repo.free();
|
||||||
await Directory(tmpDir).delete(recursive: true);
|
await tmpDir.delete(recursive: true);
|
||||||
});
|
});
|
||||||
|
|
||||||
group('Checkout', () {
|
group('Checkout', () {
|
||||||
test('successfully checkouts head', () {
|
test('successfully checkouts head', () {
|
||||||
File('${tmpDir}feature_file').writeAsStringSync('edit');
|
File('${tmpDir.path}/feature_file').writeAsStringSync('edit');
|
||||||
expect(repo.status, contains('feature_file'));
|
expect(repo.status, contains('feature_file'));
|
||||||
|
|
||||||
repo.checkout(refName: 'HEAD', strategy: {GitCheckout.force});
|
repo.checkout(refName: 'HEAD', strategy: {GitCheckout.force});
|
||||||
|
@ -73,18 +67,18 @@ void main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('successfully checkouts with alrenative directory', () {
|
test('successfully checkouts with alrenative directory', () {
|
||||||
final altDir = '${Directory.systemTemp.path}/alt_dir';
|
final altDir = Directory('${Directory.systemTemp.path}/alt_dir');
|
||||||
// making sure there is no directory
|
// making sure there is no directory
|
||||||
if (Directory(altDir).existsSync()) {
|
if (altDir.existsSync()) {
|
||||||
Directory(altDir).deleteSync(recursive: true);
|
altDir.deleteSync(recursive: true);
|
||||||
}
|
}
|
||||||
Directory(altDir).createSync();
|
altDir.createSync();
|
||||||
expect(Directory(altDir).listSync().length, 0);
|
expect(altDir.listSync().length, 0);
|
||||||
|
|
||||||
repo.checkout(refName: 'refs/heads/feature', directory: altDir);
|
repo.checkout(refName: 'refs/heads/feature', directory: altDir.path);
|
||||||
expect(Directory(altDir).listSync().length, isNot(0));
|
expect(altDir.listSync().length, isNot(0));
|
||||||
|
|
||||||
Directory(altDir).deleteSync(recursive: true);
|
altDir.deleteSync(recursive: true);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('successfully checkouts file with provided path', () {
|
test('successfully checkouts file with provided path', () {
|
||||||
|
|
|
@ -5,25 +5,18 @@ import 'package:libgit2dart/libgit2dart.dart';
|
||||||
import 'helpers/util.dart';
|
import 'helpers/util.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
const mergeCommit = '78b8bf123e3952c970ae5c1ce0a3ea1d1336f6e8';
|
|
||||||
|
|
||||||
late Repository repo;
|
late Repository repo;
|
||||||
final tmpDir = '${Directory.systemTemp.path}/commit_testrepo/';
|
late Directory tmpDir;
|
||||||
|
|
||||||
|
const mergeCommit = '78b8bf123e3952c970ae5c1ce0a3ea1d1336f6e8';
|
||||||
const message = "Commit message.\n\nSome description.\n";
|
const message = "Commit message.\n\nSome description.\n";
|
||||||
const tree = '7796359a96eb722939c24bafdb1afe9f07f2f628';
|
const tree = '7796359a96eb722939c24bafdb1afe9f07f2f628';
|
||||||
late Signature author;
|
late Signature author;
|
||||||
late Signature commiter;
|
late Signature commiter;
|
||||||
|
|
||||||
setUp(() async {
|
setUp(() async {
|
||||||
if (await Directory(tmpDir).exists()) {
|
tmpDir = await setupRepo(Directory('test/assets/testrepo/'));
|
||||||
await Directory(tmpDir).delete(recursive: true);
|
repo = Repository.open(tmpDir.path);
|
||||||
}
|
|
||||||
await copyRepo(
|
|
||||||
from: Directory('test/assets/testrepo/'),
|
|
||||||
to: await Directory(tmpDir).create(),
|
|
||||||
);
|
|
||||||
repo = Repository.open(tmpDir);
|
|
||||||
author = Signature.create(
|
author = Signature.create(
|
||||||
name: 'Author Name',
|
name: 'Author Name',
|
||||||
email: 'author@email.com',
|
email: 'author@email.com',
|
||||||
|
@ -40,7 +33,7 @@ void main() {
|
||||||
author.free();
|
author.free();
|
||||||
commiter.free();
|
commiter.free();
|
||||||
repo.free();
|
repo.free();
|
||||||
await Directory(tmpDir).delete(recursive: true);
|
await tmpDir.delete(recursive: true);
|
||||||
});
|
});
|
||||||
|
|
||||||
group('Commit', () {
|
group('Commit', () {
|
||||||
|
|
|
@ -6,7 +6,7 @@ import 'helpers/util.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
late Repository repo;
|
late Repository repo;
|
||||||
final tmpDir = '${Directory.systemTemp.path}/diff_testrepo/';
|
late Directory tmpDir;
|
||||||
const indexToWorkdir = [
|
const indexToWorkdir = [
|
||||||
'file_deleted',
|
'file_deleted',
|
||||||
'modified_file',
|
'modified_file',
|
||||||
|
@ -76,19 +76,13 @@ index e69de29..c217c63 100644
|
||||||
""";
|
""";
|
||||||
|
|
||||||
setUp(() async {
|
setUp(() async {
|
||||||
if (await Directory(tmpDir).exists()) {
|
tmpDir = await setupRepo(Directory('test/assets/dirtyrepo/'));
|
||||||
await Directory(tmpDir).delete(recursive: true);
|
repo = Repository.open(tmpDir.path);
|
||||||
}
|
|
||||||
await copyRepo(
|
|
||||||
from: Directory('test/assets/dirtyrepo/'),
|
|
||||||
to: await Directory(tmpDir).create(),
|
|
||||||
);
|
|
||||||
repo = Repository.open(tmpDir);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
tearDown(() async {
|
tearDown(() async {
|
||||||
repo.free();
|
repo.free();
|
||||||
await Directory(tmpDir).delete(recursive: true);
|
await tmpDir.delete(recursive: true);
|
||||||
});
|
});
|
||||||
|
|
||||||
group('Diff', () {
|
group('Diff', () {
|
||||||
|
@ -198,7 +192,7 @@ index e69de29..c217c63 100644
|
||||||
'checks if diff can be applied to repository and successfully applies it',
|
'checks if diff can be applied to repository and successfully applies it',
|
||||||
() {
|
() {
|
||||||
final diff = Diff.parse(patchText);
|
final diff = Diff.parse(patchText);
|
||||||
final file = File('${tmpDir}subdir/modified_file');
|
final file = File('${tmpDir.path}/subdir/modified_file');
|
||||||
|
|
||||||
repo.reset('a763aa560953e7cfb87ccbc2f536d665aa4dff22', GitReset.hard);
|
repo.reset('a763aa560953e7cfb87ccbc2f536d665aa4dff22', GitReset.hard);
|
||||||
expect(file.readAsStringSync(), '');
|
expect(file.readAsStringSync(), '');
|
||||||
|
|
|
@ -1,21 +1,26 @@
|
||||||
import 'dart:async';
|
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
import 'package:path/path.dart' as p;
|
import 'package:path/path.dart' as p;
|
||||||
|
|
||||||
Future<void> copyRepo({
|
final tmpDir = Directory.systemTemp.createTempSync('testrepo');
|
||||||
required Directory from,
|
|
||||||
required Directory to,
|
Future<Directory> setupRepo(Directory repoDir) async {
|
||||||
}) async {
|
if (await tmpDir.exists()) {
|
||||||
|
await tmpDir.delete(recursive: true);
|
||||||
|
}
|
||||||
|
await copyRepo(from: repoDir, to: await tmpDir.create());
|
||||||
|
return tmpDir;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> copyRepo({required Directory from, required Directory to}) async {
|
||||||
await for (final entity in from.list()) {
|
await for (final entity in from.list()) {
|
||||||
if (entity is Directory) {
|
if (entity is Directory) {
|
||||||
late Directory newDir;
|
Directory newDir;
|
||||||
if (p.basename(entity.path) == '.gitdir') {
|
if (p.basename(entity.path) == '.gitdir') {
|
||||||
newDir = Directory(p.join(to.absolute.path, '.git'));
|
newDir = Directory(p.join(to.absolute.path, '.git'));
|
||||||
} else {
|
} else {
|
||||||
newDir = Directory(p.join(to.absolute.path, p.basename(entity.path)));
|
newDir = Directory(p.join(to.absolute.path, p.basename(entity.path)));
|
||||||
}
|
}
|
||||||
await newDir.create();
|
await copyRepo(from: entity.absolute, to: await newDir.create());
|
||||||
await copyRepo(from: entity.absolute, to: newDir);
|
|
||||||
} else if (entity is File) {
|
} else if (entity is File) {
|
||||||
if (p.basename(entity.path) == 'gitignore') {
|
if (p.basename(entity.path) == 'gitignore') {
|
||||||
await entity.copy(p.join(to.path, '.gitignore'));
|
await entity.copy(p.join(to.path, '.gitignore'));
|
||||||
|
|
|
@ -7,24 +7,18 @@ import 'helpers/util.dart';
|
||||||
void main() {
|
void main() {
|
||||||
late Repository repo;
|
late Repository repo;
|
||||||
late Index index;
|
late Index index;
|
||||||
final tmpDir = '${Directory.systemTemp.path}/index_testrepo/';
|
late Directory tmpDir;
|
||||||
|
|
||||||
setUp(() async {
|
setUp(() async {
|
||||||
if (await Directory(tmpDir).exists()) {
|
tmpDir = await setupRepo(Directory('test/assets/testrepo/'));
|
||||||
await Directory(tmpDir).delete(recursive: true);
|
repo = Repository.open(tmpDir.path);
|
||||||
}
|
|
||||||
await copyRepo(
|
|
||||||
from: Directory('test/assets/testrepo/'),
|
|
||||||
to: await Directory(tmpDir).create(),
|
|
||||||
);
|
|
||||||
repo = Repository.open(tmpDir);
|
|
||||||
index = repo.index;
|
index = repo.index;
|
||||||
});
|
});
|
||||||
|
|
||||||
tearDown(() async {
|
tearDown(() async {
|
||||||
index.free();
|
index.free();
|
||||||
repo.free();
|
repo.free();
|
||||||
await Directory(tmpDir).delete(recursive: true);
|
await tmpDir.delete(recursive: true);
|
||||||
});
|
});
|
||||||
|
|
||||||
group('Index', () {
|
group('Index', () {
|
||||||
|
@ -136,7 +130,7 @@ void main() {
|
||||||
test('writes to disk', () {
|
test('writes to disk', () {
|
||||||
expect(index.length, 4);
|
expect(index.length, 4);
|
||||||
|
|
||||||
File('$tmpDir/new_file').createSync();
|
File('${tmpDir.path}/new_file').createSync();
|
||||||
|
|
||||||
index.add('new_file');
|
index.add('new_file');
|
||||||
index.write();
|
index.write();
|
||||||
|
|
|
@ -6,22 +6,16 @@ import 'helpers/util.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
late Repository repo;
|
late Repository repo;
|
||||||
final tmpDir = '${Directory.systemTemp.path}/mergerepo/';
|
late Directory tmpDir;
|
||||||
|
|
||||||
setUp(() async {
|
setUp(() async {
|
||||||
if (await Directory(tmpDir).exists()) {
|
tmpDir = await setupRepo(Directory('test/assets/mergerepo/'));
|
||||||
await Directory(tmpDir).delete(recursive: true);
|
repo = Repository.open(tmpDir.path);
|
||||||
}
|
|
||||||
await copyRepo(
|
|
||||||
from: Directory('test/assets/mergerepo/'),
|
|
||||||
to: await Directory(tmpDir).create(),
|
|
||||||
);
|
|
||||||
repo = Repository.open(tmpDir);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
tearDown(() async {
|
tearDown(() async {
|
||||||
repo.free();
|
repo.free();
|
||||||
await Directory(tmpDir).delete(recursive: true);
|
await tmpDir.delete(recursive: true);
|
||||||
});
|
});
|
||||||
|
|
||||||
group('Merge', () {
|
group('Merge', () {
|
||||||
|
|
|
@ -5,29 +5,25 @@ import 'package:libgit2dart/libgit2dart.dart';
|
||||||
import 'helpers/util.dart';
|
import 'helpers/util.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
const lastCommit = '78b8bf123e3952c970ae5c1ce0a3ea1d1336f6e8';
|
|
||||||
late Repository repo;
|
late Repository repo;
|
||||||
final tmpDir = '${Directory.systemTemp.path}/odb_testrepo/';
|
late Directory tmpDir;
|
||||||
|
const lastCommit = '78b8bf123e3952c970ae5c1ce0a3ea1d1336f6e8';
|
||||||
|
|
||||||
setUp(() async {
|
setUp(() async {
|
||||||
if (await Directory(tmpDir).exists()) {
|
tmpDir = await setupRepo(Directory('test/assets/testrepo/'));
|
||||||
await Directory(tmpDir).delete(recursive: true);
|
repo = Repository.open(tmpDir.path);
|
||||||
}
|
|
||||||
await copyRepo(
|
|
||||||
from: Directory('test/assets/testrepo/'),
|
|
||||||
to: await Directory(tmpDir).create(),
|
|
||||||
);
|
|
||||||
repo = Repository.open(tmpDir);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
tearDown(() async {
|
tearDown(() async {
|
||||||
repo.free();
|
repo.free();
|
||||||
await Directory(tmpDir).delete(recursive: true);
|
await tmpDir.delete(recursive: true);
|
||||||
});
|
});
|
||||||
|
|
||||||
group('Odb', () {
|
group('Odb', () {
|
||||||
test('successfully initializes', () {
|
test('successfully initializes', () {
|
||||||
expect(repo.odb, isA<Odb>());
|
final odb = repo.odb;
|
||||||
repo.odb.free();
|
expect(odb, isA<Odb>());
|
||||||
|
odb.free();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('finds object by short oid', () {
|
test('finds object by short oid', () {
|
||||||
|
|
|
@ -5,26 +5,20 @@ import 'package:libgit2dart/libgit2dart.dart';
|
||||||
import 'helpers/util.dart';
|
import 'helpers/util.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
|
late Repository repo;
|
||||||
|
late Directory tmpDir;
|
||||||
const sha = '78b8bf123e3952c970ae5c1ce0a3ea1d1336f6e8';
|
const sha = '78b8bf123e3952c970ae5c1ce0a3ea1d1336f6e8';
|
||||||
const biggerSha = '78b8bf123e3952c970ae5c1ce0a3ea1d1336f6e9';
|
const biggerSha = '78b8bf123e3952c970ae5c1ce0a3ea1d1336f6e9';
|
||||||
const lesserSha = '78b8bf123e3952c970ae5c1ce0a3ea1d1336f6e7';
|
const lesserSha = '78b8bf123e3952c970ae5c1ce0a3ea1d1336f6e7';
|
||||||
late Repository repo;
|
|
||||||
final tmpDir = '${Directory.systemTemp.path}/oid_testrepo/';
|
|
||||||
|
|
||||||
setUp(() async {
|
setUp(() async {
|
||||||
if (await Directory(tmpDir).exists()) {
|
tmpDir = await setupRepo(Directory('test/assets/testrepo/'));
|
||||||
await Directory(tmpDir).delete(recursive: true);
|
repo = Repository.open(tmpDir.path);
|
||||||
}
|
|
||||||
await copyRepo(
|
|
||||||
from: Directory('test/assets/testrepo/'),
|
|
||||||
to: await Directory(tmpDir).create(),
|
|
||||||
);
|
|
||||||
repo = Repository.open(tmpDir);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
tearDown(() async {
|
tearDown(() async {
|
||||||
repo.free();
|
repo.free();
|
||||||
await Directory(tmpDir).delete(recursive: true);
|
await tmpDir.delete(recursive: true);
|
||||||
});
|
});
|
||||||
|
|
||||||
group('Oid', () {
|
group('Oid', () {
|
||||||
|
|
|
@ -5,7 +5,7 @@ import 'helpers/util.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
late Repository repo;
|
late Repository repo;
|
||||||
final tmpDir = '${Directory.systemTemp.path}/patch_testrepo/';
|
late Directory tmpDir;
|
||||||
const oldBlob = '';
|
const oldBlob = '';
|
||||||
const newBlob = 'Feature edit\n';
|
const newBlob = 'Feature edit\n';
|
||||||
const path = 'feature_file';
|
const path = 'feature_file';
|
||||||
|
@ -39,19 +39,13 @@ index e69de29..0000000
|
||||||
""";
|
""";
|
||||||
|
|
||||||
setUp(() async {
|
setUp(() async {
|
||||||
if (await Directory(tmpDir).exists()) {
|
tmpDir = await setupRepo(Directory('test/assets/testrepo/'));
|
||||||
await Directory(tmpDir).delete(recursive: true);
|
repo = Repository.open(tmpDir.path);
|
||||||
}
|
|
||||||
await copyRepo(
|
|
||||||
from: Directory('test/assets/testrepo/'),
|
|
||||||
to: await Directory(tmpDir).create(),
|
|
||||||
);
|
|
||||||
repo = Repository.open(tmpDir);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
tearDown(() async {
|
tearDown(() async {
|
||||||
repo.free();
|
repo.free();
|
||||||
await Directory(tmpDir).delete(recursive: true);
|
await tmpDir.delete(recursive: true);
|
||||||
});
|
});
|
||||||
|
|
||||||
group('Patch', () {
|
group('Patch', () {
|
||||||
|
|
|
@ -6,25 +6,19 @@ import 'package:libgit2dart/libgit2dart.dart';
|
||||||
import 'helpers/util.dart';
|
import 'helpers/util.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
|
late Repository repo;
|
||||||
|
late Directory tmpDir;
|
||||||
const lastCommit = '821ed6e80627b8769d170a293862f9fc60825226';
|
const lastCommit = '821ed6e80627b8769d170a293862f9fc60825226';
|
||||||
const newCommit = 'c68ff54aabf660fcdd9a2838d401583fe31249e3';
|
const newCommit = 'c68ff54aabf660fcdd9a2838d401583fe31249e3';
|
||||||
late Repository repo;
|
|
||||||
final tmpDir = '${Directory.systemTemp.path}/ref_testrepo/';
|
|
||||||
|
|
||||||
setUp(() async {
|
setUp(() async {
|
||||||
if (await Directory(tmpDir).exists()) {
|
tmpDir = await setupRepo(Directory('test/assets/testrepo/'));
|
||||||
await Directory(tmpDir).delete(recursive: true);
|
repo = Repository.open(tmpDir.path);
|
||||||
}
|
|
||||||
await copyRepo(
|
|
||||||
from: Directory('test/assets/testrepo/'),
|
|
||||||
to: await Directory(tmpDir).create(),
|
|
||||||
);
|
|
||||||
repo = Repository.open(tmpDir);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
tearDown(() async {
|
tearDown(() async {
|
||||||
repo.free();
|
repo.free();
|
||||||
await Directory(tmpDir).delete(recursive: true);
|
await tmpDir.delete(recursive: true);
|
||||||
});
|
});
|
||||||
|
|
||||||
group('Reference', () {
|
group('Reference', () {
|
||||||
|
@ -516,7 +510,7 @@ void main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('successfully compresses references', () {
|
test('successfully compresses references', () {
|
||||||
final packedRefsFile = File('$tmpDir.git/packed-refs');
|
final packedRefsFile = File('${tmpDir.path}/.git/packed-refs');
|
||||||
expect(packedRefsFile.existsSync(), false);
|
expect(packedRefsFile.existsSync(), false);
|
||||||
final oldRefs = repo.references.list();
|
final oldRefs = repo.references.list();
|
||||||
|
|
||||||
|
|
|
@ -8,17 +8,11 @@ void main() {
|
||||||
late Repository repo;
|
late Repository repo;
|
||||||
late RefLog reflog;
|
late RefLog reflog;
|
||||||
late Reference head;
|
late Reference head;
|
||||||
final tmpDir = '${Directory.systemTemp.path}/reflog_testrepo/';
|
late Directory tmpDir;
|
||||||
|
|
||||||
setUp(() async {
|
setUp(() async {
|
||||||
if (await Directory(tmpDir).exists()) {
|
tmpDir = await setupRepo(Directory('test/assets/testrepo/'));
|
||||||
await Directory(tmpDir).delete(recursive: true);
|
repo = Repository.open(tmpDir.path);
|
||||||
}
|
|
||||||
await copyRepo(
|
|
||||||
from: Directory('test/assets/testrepo/'),
|
|
||||||
to: await Directory(tmpDir).create(),
|
|
||||||
);
|
|
||||||
repo = Repository.open(tmpDir);
|
|
||||||
head = repo.head;
|
head = repo.head;
|
||||||
reflog = RefLog(head);
|
reflog = RefLog(head);
|
||||||
});
|
});
|
||||||
|
@ -27,8 +21,9 @@ void main() {
|
||||||
reflog.free();
|
reflog.free();
|
||||||
head.free();
|
head.free();
|
||||||
repo.free();
|
repo.free();
|
||||||
await Directory(tmpDir).delete(recursive: true);
|
await tmpDir.delete(recursive: true);
|
||||||
});
|
});
|
||||||
|
|
||||||
group('RefLog', () {
|
group('RefLog', () {
|
||||||
test('initializes successfully', () {
|
test('initializes successfully', () {
|
||||||
expect(reflog, isA<RefLog>());
|
expect(reflog, isA<RefLog>());
|
||||||
|
|
|
@ -5,24 +5,18 @@ import 'helpers/util.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
late Repository repo;
|
late Repository repo;
|
||||||
final tmpDir = '${Directory.systemTemp.path}/remote_testrepo/';
|
late Directory tmpDir;
|
||||||
const remoteName = 'origin';
|
const remoteName = 'origin';
|
||||||
const remoteUrl = 'git://github.com/SkinnyMind/libgit2dart.git';
|
const remoteUrl = 'git://github.com/SkinnyMind/libgit2dart.git';
|
||||||
|
|
||||||
setUp(() async {
|
setUp(() async {
|
||||||
if (await Directory(tmpDir).exists()) {
|
tmpDir = await setupRepo(Directory('test/assets/testrepo/'));
|
||||||
await Directory(tmpDir).delete(recursive: true);
|
repo = Repository.open(tmpDir.path);
|
||||||
}
|
|
||||||
await copyRepo(
|
|
||||||
from: Directory('test/assets/testrepo/'),
|
|
||||||
to: await Directory(tmpDir).create(),
|
|
||||||
);
|
|
||||||
repo = Repository.open(tmpDir);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
tearDown(() async {
|
tearDown(() async {
|
||||||
repo.free();
|
repo.free();
|
||||||
await Directory(tmpDir).delete(recursive: true);
|
await tmpDir.delete(recursive: true);
|
||||||
});
|
});
|
||||||
|
|
||||||
group('Remote', () {
|
group('Remote', () {
|
||||||
|
@ -229,18 +223,19 @@ void main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('successfully pushes', () async {
|
test('successfully pushes', () async {
|
||||||
final originDir = '${Directory.systemTemp.path}/origin_testrepo/';
|
final originDir =
|
||||||
|
Directory('${Directory.systemTemp.path}/origin_testrepo');
|
||||||
|
|
||||||
if (await Directory(originDir).exists()) {
|
if (await originDir.exists()) {
|
||||||
await Directory(originDir).delete(recursive: true);
|
await originDir.delete(recursive: true);
|
||||||
}
|
}
|
||||||
await copyRepo(
|
await copyRepo(
|
||||||
from: Directory('test/assets/empty_bare.git/'),
|
from: Directory('test/assets/empty_bare.git/'),
|
||||||
to: await Directory(originDir).create(),
|
to: await originDir.create(),
|
||||||
);
|
);
|
||||||
final originRepo = Repository.open(originDir);
|
final originRepo = Repository.open(originDir.path);
|
||||||
|
|
||||||
repo.remotes.create(name: 'local', url: originDir);
|
repo.remotes.create(name: 'local', url: originDir.path);
|
||||||
final remote = repo.remotes['local'];
|
final remote = repo.remotes['local'];
|
||||||
|
|
||||||
remote.push(['refs/heads/master']);
|
remote.push(['refs/heads/master']);
|
||||||
|
@ -251,7 +246,7 @@ void main() {
|
||||||
|
|
||||||
remote.free();
|
remote.free();
|
||||||
originRepo.free();
|
originRepo.free();
|
||||||
await Directory(originDir).delete(recursive: true);
|
originDir.delete(recursive: true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,30 +15,30 @@ void main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
group('.init()', () {
|
group('.init()', () {
|
||||||
final initDir = '${Directory.systemTemp.path}/init_repo/';
|
final initDir = Directory('${Directory.systemTemp.path}/init_repo');
|
||||||
|
|
||||||
setUp(() async {
|
setUp(() async {
|
||||||
if (await Directory(initDir).exists()) {
|
if (await initDir.exists()) {
|
||||||
await Directory(initDir).delete(recursive: true);
|
await initDir.delete(recursive: true);
|
||||||
} else {
|
} else {
|
||||||
await Directory(initDir).create();
|
await initDir.create();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
tearDown(() async {
|
tearDown(() async {
|
||||||
repo.free();
|
repo.free();
|
||||||
await Directory(initDir).delete(recursive: true);
|
await initDir.delete(recursive: true);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('successfully creates new bare repo at provided path', () {
|
test('successfully creates new bare repo at provided path', () {
|
||||||
repo = Repository.init(initDir, isBare: true);
|
repo = Repository.init(initDir.path, isBare: true);
|
||||||
expect(repo.path, initDir);
|
expect(repo.path, '${initDir.path}/');
|
||||||
expect(repo.isBare, true);
|
expect(repo.isBare, true);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('successfully creates new standard repo at provided path', () {
|
test('successfully creates new standard repo at provided path', () {
|
||||||
repo = Repository.init(initDir);
|
repo = Repository.init(initDir.path);
|
||||||
expect(repo.path, '$initDir.git/');
|
expect(repo.path, '${initDir.path}/.git/');
|
||||||
expect(repo.isBare, false);
|
expect(repo.isBare, false);
|
||||||
expect(repo.isEmpty, true);
|
expect(repo.isEmpty, true);
|
||||||
});
|
});
|
||||||
|
@ -153,22 +153,16 @@ void main() {
|
||||||
const lastCommit = '821ed6e80627b8769d170a293862f9fc60825226';
|
const lastCommit = '821ed6e80627b8769d170a293862f9fc60825226';
|
||||||
const featureCommit = '5aecfa0fb97eadaac050ccb99f03c3fb65460ad4';
|
const featureCommit = '5aecfa0fb97eadaac050ccb99f03c3fb65460ad4';
|
||||||
|
|
||||||
final tmpDir = '${Directory.systemTemp.path}/testrepo/';
|
late Directory tmpDir;
|
||||||
|
|
||||||
setUp(() async {
|
setUp(() async {
|
||||||
if (await Directory(tmpDir).exists()) {
|
tmpDir = await setupRepo(Directory('test/assets/testrepo/'));
|
||||||
await Directory(tmpDir).delete(recursive: true);
|
repo = Repository.open(tmpDir.path);
|
||||||
}
|
|
||||||
await copyRepo(
|
|
||||||
from: Directory('test/assets/testrepo/'),
|
|
||||||
to: await Directory(tmpDir).create(),
|
|
||||||
);
|
|
||||||
repo = Repository.open(tmpDir);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
tearDown(() async {
|
tearDown(() async {
|
||||||
repo.free();
|
repo.free();
|
||||||
await Directory(tmpDir).delete(recursive: true);
|
await tmpDir.delete(recursive: true);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('returns config for repository', () {
|
test('returns config for repository', () {
|
||||||
|
@ -203,7 +197,7 @@ void main() {
|
||||||
|
|
||||||
group('.discover()', () {
|
group('.discover()', () {
|
||||||
test('discovers repository', () async {
|
test('discovers repository', () async {
|
||||||
final subDir = '${tmpDir}subdir1/subdir2/';
|
final subDir = '${tmpDir.path}/subdir1/subdir2/';
|
||||||
await Directory(subDir).create(recursive: true);
|
await Directory(subDir).create(recursive: true);
|
||||||
expect(Repository.discover(subDir), repo.path);
|
expect(Repository.discover(subDir), repo.path);
|
||||||
});
|
});
|
||||||
|
@ -226,13 +220,14 @@ void main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('successfully sets working directory', () {
|
test('successfully sets working directory', () {
|
||||||
final tmpWorkDir = '${Directory.systemTemp.path}/tmp_work_dir/';
|
final tmpWorkDir =
|
||||||
Directory(tmpWorkDir).createSync();
|
Directory('${Directory.systemTemp.path}/tmp_work_dir');
|
||||||
|
tmpWorkDir.createSync();
|
||||||
|
|
||||||
repo.setWorkdir(tmpWorkDir);
|
repo.setWorkdir(tmpWorkDir.path);
|
||||||
expect(repo.workdir, tmpWorkDir);
|
expect(repo.workdir, '${tmpWorkDir.path}/');
|
||||||
|
|
||||||
Directory(tmpWorkDir).deleteSync();
|
tmpWorkDir.deleteSync();
|
||||||
});
|
});
|
||||||
|
|
||||||
group('setHead', () {
|
group('setHead', () {
|
||||||
|
@ -341,7 +336,7 @@ void main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('returns status of a repository', () {
|
test('returns status of a repository', () {
|
||||||
File('${tmpDir}new_file.txt').createSync();
|
File('${tmpDir.path}/new_file.txt').createSync();
|
||||||
final index = repo.index;
|
final index = repo.index;
|
||||||
index.remove('file');
|
index.remove('file');
|
||||||
index.add('new_file.txt');
|
index.add('new_file.txt');
|
||||||
|
|
|
@ -6,24 +6,19 @@ import 'helpers/util.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
late Repository repo;
|
late Repository repo;
|
||||||
final tmpDir = '${Directory.systemTemp.path}/reset_testrepo/';
|
late Directory tmpDir;
|
||||||
|
late File file;
|
||||||
const sha = '6cbc22e509d72758ab4c8d9f287ea846b90c448b';
|
const sha = '6cbc22e509d72758ab4c8d9f287ea846b90c448b';
|
||||||
final file = File('${tmpDir}feature_file');
|
|
||||||
|
|
||||||
setUp(() async {
|
setUp(() async {
|
||||||
if (await Directory(tmpDir).exists()) {
|
tmpDir = await setupRepo(Directory('test/assets/testrepo/'));
|
||||||
await Directory(tmpDir).delete(recursive: true);
|
file = File('${tmpDir.path}/feature_file');
|
||||||
}
|
repo = Repository.open(tmpDir.path);
|
||||||
await copyRepo(
|
|
||||||
from: Directory('test/assets/testrepo/'),
|
|
||||||
to: await Directory(tmpDir).create(),
|
|
||||||
);
|
|
||||||
repo = Repository.open(tmpDir);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
tearDown(() async {
|
tearDown(() async {
|
||||||
repo.free();
|
repo.free();
|
||||||
await Directory(tmpDir).delete(recursive: true);
|
await tmpDir.delete(recursive: true);
|
||||||
});
|
});
|
||||||
|
|
||||||
group('Reset', () {
|
group('Reset', () {
|
||||||
|
|
|
@ -6,24 +6,18 @@ import 'helpers/util.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
late Repository repo;
|
late Repository repo;
|
||||||
final tmpDir = '${Directory.systemTemp.path}/revparse_testrepo/';
|
late Directory tmpDir;
|
||||||
const headSHA = '821ed6e80627b8769d170a293862f9fc60825226';
|
const headSHA = '821ed6e80627b8769d170a293862f9fc60825226';
|
||||||
const parentSHA = '78b8bf123e3952c970ae5c1ce0a3ea1d1336f6e8';
|
const parentSHA = '78b8bf123e3952c970ae5c1ce0a3ea1d1336f6e8';
|
||||||
|
|
||||||
setUp(() async {
|
setUp(() async {
|
||||||
if (await Directory(tmpDir).exists()) {
|
tmpDir = await setupRepo(Directory('test/assets/testrepo/'));
|
||||||
await Directory(tmpDir).delete(recursive: true);
|
repo = Repository.open(tmpDir.path);
|
||||||
}
|
|
||||||
await copyRepo(
|
|
||||||
from: Directory('test/assets/testrepo/'),
|
|
||||||
to: await Directory(tmpDir).create(),
|
|
||||||
);
|
|
||||||
repo = Repository.open(tmpDir);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
tearDown(() async {
|
tearDown(() async {
|
||||||
repo.free();
|
repo.free();
|
||||||
await Directory(tmpDir).delete(recursive: true);
|
await tmpDir.delete(recursive: true);
|
||||||
});
|
});
|
||||||
|
|
||||||
group('revParse', () {
|
group('revParse', () {
|
||||||
|
|
|
@ -5,6 +5,8 @@ import 'package:libgit2dart/libgit2dart.dart';
|
||||||
import 'helpers/util.dart';
|
import 'helpers/util.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
|
late Repository repo;
|
||||||
|
late Directory tmpDir;
|
||||||
const log = [
|
const log = [
|
||||||
'78b8bf123e3952c970ae5c1ce0a3ea1d1336f6e8',
|
'78b8bf123e3952c970ae5c1ce0a3ea1d1336f6e8',
|
||||||
'c68ff54aabf660fcdd9a2838d401583fe31249e3',
|
'c68ff54aabf660fcdd9a2838d401583fe31249e3',
|
||||||
|
@ -12,24 +14,17 @@ void main() {
|
||||||
'6cbc22e509d72758ab4c8d9f287ea846b90c448b',
|
'6cbc22e509d72758ab4c8d9f287ea846b90c448b',
|
||||||
'f17d0d48eae3aa08cecf29128a35e310c97b3521',
|
'f17d0d48eae3aa08cecf29128a35e310c97b3521',
|
||||||
];
|
];
|
||||||
late Repository repo;
|
|
||||||
final tmpDir = '${Directory.systemTemp.path}/revwalk_testrepo/';
|
|
||||||
|
|
||||||
setUp(() async {
|
setUp(() async {
|
||||||
if (await Directory(tmpDir).exists()) {
|
tmpDir = await setupRepo(Directory('test/assets/testrepo/'));
|
||||||
await Directory(tmpDir).delete(recursive: true);
|
repo = Repository.open(tmpDir.path);
|
||||||
}
|
|
||||||
await copyRepo(
|
|
||||||
from: Directory('test/assets/testrepo/'),
|
|
||||||
to: await Directory(tmpDir).create(),
|
|
||||||
);
|
|
||||||
repo = Repository.open(tmpDir);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
tearDown(() async {
|
tearDown(() async {
|
||||||
repo.free();
|
repo.free();
|
||||||
await Directory(tmpDir).delete(recursive: true);
|
await tmpDir.delete(recursive: true);
|
||||||
});
|
});
|
||||||
|
|
||||||
group('RevWalk', () {
|
group('RevWalk', () {
|
||||||
test('returns list of commits with default sorting', () {
|
test('returns list of commits with default sorting', () {
|
||||||
final walker = RevWalk(repo);
|
final walker = RevWalk(repo);
|
||||||
|
|
|
@ -5,18 +5,12 @@ import 'helpers/util.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
late Repository repo;
|
late Repository repo;
|
||||||
|
late Directory tmpDir;
|
||||||
late Signature stasher;
|
late Signature stasher;
|
||||||
final tmpDir = '${Directory.systemTemp.path}/stash_testrepo/';
|
|
||||||
|
|
||||||
setUp(() async {
|
setUp(() async {
|
||||||
if (await Directory(tmpDir).exists()) {
|
tmpDir = await setupRepo(Directory('test/assets/testrepo/'));
|
||||||
await Directory(tmpDir).delete(recursive: true);
|
repo = Repository.open(tmpDir.path);
|
||||||
}
|
|
||||||
await copyRepo(
|
|
||||||
from: Directory('test/assets/testrepo/'),
|
|
||||||
to: await Directory(tmpDir).create(),
|
|
||||||
);
|
|
||||||
repo = Repository.open(tmpDir);
|
|
||||||
stasher = Signature.create(
|
stasher = Signature.create(
|
||||||
name: 'Stasher',
|
name: 'Stasher',
|
||||||
email: 'stasher@email.com',
|
email: 'stasher@email.com',
|
||||||
|
@ -26,12 +20,12 @@ void main() {
|
||||||
tearDown(() async {
|
tearDown(() async {
|
||||||
stasher.free();
|
stasher.free();
|
||||||
repo.free();
|
repo.free();
|
||||||
await Directory(tmpDir).delete(recursive: true);
|
await tmpDir.delete(recursive: true);
|
||||||
});
|
});
|
||||||
|
|
||||||
group('Stash', () {
|
group('Stash', () {
|
||||||
test('successfully saves changes to stash', () {
|
test('successfully saves changes to stash', () {
|
||||||
File('${tmpDir}file').writeAsStringSync(
|
File('${tmpDir.path}/file').writeAsStringSync(
|
||||||
'edit',
|
'edit',
|
||||||
mode: FileMode.append,
|
mode: FileMode.append,
|
||||||
);
|
);
|
||||||
|
@ -41,7 +35,7 @@ void main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('successfully applies changes from stash', () {
|
test('successfully applies changes from stash', () {
|
||||||
File('${tmpDir}file').writeAsStringSync(
|
File('${tmpDir.path}/file').writeAsStringSync(
|
||||||
'edit',
|
'edit',
|
||||||
mode: FileMode.append,
|
mode: FileMode.append,
|
||||||
);
|
);
|
||||||
|
@ -54,7 +48,7 @@ void main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('successfully drops stash', () {
|
test('successfully drops stash', () {
|
||||||
File('${tmpDir}file').writeAsStringSync(
|
File('${tmpDir.path}/file').writeAsStringSync(
|
||||||
'edit',
|
'edit',
|
||||||
mode: FileMode.append,
|
mode: FileMode.append,
|
||||||
);
|
);
|
||||||
|
@ -66,7 +60,7 @@ void main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('successfully pops from stash', () {
|
test('successfully pops from stash', () {
|
||||||
File('${tmpDir}file').writeAsStringSync(
|
File('${tmpDir.path}/file').writeAsStringSync(
|
||||||
'edit',
|
'edit',
|
||||||
mode: FileMode.append,
|
mode: FileMode.append,
|
||||||
);
|
);
|
||||||
|
@ -78,7 +72,7 @@ void main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('returns list of stashes', () {
|
test('returns list of stashes', () {
|
||||||
File('${tmpDir}file').writeAsStringSync(
|
File('${tmpDir.path}/file').writeAsStringSync(
|
||||||
'edit',
|
'edit',
|
||||||
mode: FileMode.append,
|
mode: FileMode.append,
|
||||||
);
|
);
|
||||||
|
|
|
@ -7,25 +7,19 @@ import 'helpers/util.dart';
|
||||||
void main() {
|
void main() {
|
||||||
late Repository repo;
|
late Repository repo;
|
||||||
late Tag tag;
|
late Tag tag;
|
||||||
final tmpDir = '${Directory.systemTemp.path}/tag_testrepo/';
|
late Directory tmpDir;
|
||||||
const tagSHA = 'f0fdbf506397e9f58c59b88dfdd72778ec06cc0c';
|
const tagSHA = 'f0fdbf506397e9f58c59b88dfdd72778ec06cc0c';
|
||||||
|
|
||||||
setUp(() async {
|
setUp(() async {
|
||||||
if (await Directory(tmpDir).exists()) {
|
tmpDir = await setupRepo(Directory('test/assets/testrepo/'));
|
||||||
await Directory(tmpDir).delete(recursive: true);
|
repo = Repository.open(tmpDir.path);
|
||||||
}
|
|
||||||
await copyRepo(
|
|
||||||
from: Directory('test/assets/testrepo/'),
|
|
||||||
to: await Directory(tmpDir).create(),
|
|
||||||
);
|
|
||||||
repo = Repository.open(tmpDir);
|
|
||||||
tag = Tag.lookup(repo, tagSHA);
|
tag = Tag.lookup(repo, tagSHA);
|
||||||
});
|
});
|
||||||
|
|
||||||
tearDown(() async {
|
tearDown(() async {
|
||||||
tag.free();
|
tag.free();
|
||||||
repo.free();
|
repo.free();
|
||||||
await Directory(tmpDir).delete(recursive: true);
|
await tmpDir.delete(recursive: true);
|
||||||
});
|
});
|
||||||
|
|
||||||
group('Tag', () {
|
group('Tag', () {
|
||||||
|
|
|
@ -7,26 +7,20 @@ import 'helpers/util.dart';
|
||||||
void main() {
|
void main() {
|
||||||
late Repository repo;
|
late Repository repo;
|
||||||
late Tree tree;
|
late Tree tree;
|
||||||
final tmpDir = '${Directory.systemTemp.path}/tree_testrepo/';
|
late Directory tmpDir;
|
||||||
const treeSHA = 'a8ae3dd59e6e1802c6f78e05e301bfd57c9f334f';
|
const treeSHA = 'a8ae3dd59e6e1802c6f78e05e301bfd57c9f334f';
|
||||||
const fileSHA = '1377554ebea6f98a2c748183bc5a96852af12ac2';
|
const fileSHA = '1377554ebea6f98a2c748183bc5a96852af12ac2';
|
||||||
|
|
||||||
setUp(() async {
|
setUp(() async {
|
||||||
if (await Directory(tmpDir).exists()) {
|
tmpDir = await setupRepo(Directory('test/assets/testrepo/'));
|
||||||
await Directory(tmpDir).delete(recursive: true);
|
repo = Repository.open(tmpDir.path);
|
||||||
}
|
|
||||||
await copyRepo(
|
|
||||||
from: Directory('test/assets/testrepo/'),
|
|
||||||
to: await Directory(tmpDir).create(),
|
|
||||||
);
|
|
||||||
repo = Repository.open(tmpDir);
|
|
||||||
tree = Tree.lookup(repo, treeSHA);
|
tree = Tree.lookup(repo, treeSHA);
|
||||||
});
|
});
|
||||||
|
|
||||||
tearDown(() async {
|
tearDown(() async {
|
||||||
tree.free();
|
tree.free();
|
||||||
repo.free();
|
repo.free();
|
||||||
await Directory(tmpDir).delete(recursive: true);
|
await tmpDir.delete(recursive: true);
|
||||||
});
|
});
|
||||||
|
|
||||||
group('Tree', () {
|
group('Tree', () {
|
||||||
|
|
|
@ -7,25 +7,19 @@ import 'helpers/util.dart';
|
||||||
void main() {
|
void main() {
|
||||||
late Repository repo;
|
late Repository repo;
|
||||||
late Tree tree;
|
late Tree tree;
|
||||||
final tmpDir = '${Directory.systemTemp.path}/treebuilder_testrepo/';
|
late Directory tmpDir;
|
||||||
const treeSHA = 'a8ae3dd59e6e1802c6f78e05e301bfd57c9f334f';
|
const treeSHA = 'a8ae3dd59e6e1802c6f78e05e301bfd57c9f334f';
|
||||||
|
|
||||||
setUp(() async {
|
setUp(() async {
|
||||||
if (await Directory(tmpDir).exists()) {
|
tmpDir = await setupRepo(Directory('test/assets/testrepo/'));
|
||||||
await Directory(tmpDir).delete(recursive: true);
|
repo = Repository.open(tmpDir.path);
|
||||||
}
|
|
||||||
await copyRepo(
|
|
||||||
from: Directory('test/assets/testrepo/'),
|
|
||||||
to: await Directory(tmpDir).create(),
|
|
||||||
);
|
|
||||||
repo = Repository.open(tmpDir);
|
|
||||||
tree = Tree.lookup(repo, treeSHA);
|
tree = Tree.lookup(repo, treeSHA);
|
||||||
});
|
});
|
||||||
|
|
||||||
tearDown(() async {
|
tearDown(() async {
|
||||||
tree.free();
|
tree.free();
|
||||||
repo.free();
|
repo.free();
|
||||||
await Directory(tmpDir).delete(recursive: true);
|
await tmpDir.delete(recursive: true);
|
||||||
});
|
});
|
||||||
|
|
||||||
group('TreeBuilder', () {
|
group('TreeBuilder', () {
|
||||||
|
|
|
@ -5,30 +5,22 @@ import 'helpers/util.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
late Repository repo;
|
late Repository repo;
|
||||||
final tmpDir = '${Directory.systemTemp.path}/worktree_testrepo/';
|
late Directory tmpDir;
|
||||||
final worktreeDir = '${Directory.systemTemp.path}/worktree';
|
final worktreeDir = Directory('${Directory.systemTemp.path}/worktree');
|
||||||
|
|
||||||
setUp(() async {
|
setUp(() async {
|
||||||
if (await Directory(tmpDir).exists()) {
|
if (await worktreeDir.exists()) {
|
||||||
await Directory(tmpDir).delete(recursive: true);
|
await worktreeDir.delete(recursive: true);
|
||||||
}
|
}
|
||||||
|
tmpDir = await setupRepo(Directory('test/assets/testrepo/'));
|
||||||
if (await Directory(worktreeDir).exists()) {
|
repo = Repository.open(tmpDir.path);
|
||||||
await Directory(worktreeDir).delete(recursive: true);
|
|
||||||
}
|
|
||||||
|
|
||||||
await copyRepo(
|
|
||||||
from: Directory('test/assets/testrepo/'),
|
|
||||||
to: await Directory(tmpDir).create(),
|
|
||||||
);
|
|
||||||
repo = Repository.open(tmpDir);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
tearDown(() async {
|
tearDown(() async {
|
||||||
repo.free();
|
repo.free();
|
||||||
await Directory(tmpDir).delete(recursive: true);
|
await tmpDir.delete(recursive: true);
|
||||||
if (await Directory(worktreeDir).exists()) {
|
if (await worktreeDir.exists()) {
|
||||||
await Directory(worktreeDir).delete(recursive: true);
|
await worktreeDir.delete(recursive: true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -40,14 +32,14 @@ void main() {
|
||||||
final worktree = Worktree.create(
|
final worktree = Worktree.create(
|
||||||
repo: repo,
|
repo: repo,
|
||||||
name: worktreeName,
|
name: worktreeName,
|
||||||
path: worktreeDir,
|
path: worktreeDir.path,
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(Worktree.list(repo), [worktreeName]);
|
expect(Worktree.list(repo), [worktreeName]);
|
||||||
expect(repo.branches.list(), contains(worktreeName));
|
expect(repo.branches.list(), contains(worktreeName));
|
||||||
expect(worktree.name, worktreeName);
|
expect(worktree.name, worktreeName);
|
||||||
expect(worktree.path, worktreeDir);
|
expect(worktree.path, worktreeDir.path);
|
||||||
expect(File('$worktreeDir/.git').existsSync(), true);
|
expect(File('${worktreeDir.path}/.git').existsSync(), true);
|
||||||
|
|
||||||
worktree.free();
|
worktree.free();
|
||||||
});
|
});
|
||||||
|
@ -64,7 +56,7 @@ void main() {
|
||||||
final worktree = Worktree.create(
|
final worktree = Worktree.create(
|
||||||
repo: repo,
|
repo: repo,
|
||||||
name: worktreeName,
|
name: worktreeName,
|
||||||
path: worktreeDir,
|
path: worktreeDir.path,
|
||||||
ref: worktreeRef,
|
ref: worktreeRef,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -73,7 +65,7 @@ void main() {
|
||||||
expect(repo.branches.list(), isNot(contains(worktreeName)));
|
expect(repo.branches.list(), isNot(contains(worktreeName)));
|
||||||
expect(worktreeBranch.isCheckedOut, true);
|
expect(worktreeBranch.isCheckedOut, true);
|
||||||
|
|
||||||
Directory(worktreeDir).deleteSync(recursive: true);
|
worktreeDir.deleteSync(recursive: true);
|
||||||
worktree.prune();
|
worktree.prune();
|
||||||
|
|
||||||
expect(Worktree.list(repo), []);
|
expect(Worktree.list(repo), []);
|
||||||
|
@ -93,11 +85,11 @@ void main() {
|
||||||
final worktree = Worktree.create(
|
final worktree = Worktree.create(
|
||||||
repo: repo,
|
repo: repo,
|
||||||
name: worktreeName,
|
name: worktreeName,
|
||||||
path: worktreeDir,
|
path: worktreeDir.path,
|
||||||
);
|
);
|
||||||
expect(Worktree.list(repo), [worktreeName]);
|
expect(Worktree.list(repo), [worktreeName]);
|
||||||
|
|
||||||
Directory(worktreeDir).deleteSync(recursive: true);
|
worktreeDir.deleteSync(recursive: true);
|
||||||
worktree.prune();
|
worktree.prune();
|
||||||
expect(Worktree.list(repo), []);
|
expect(Worktree.list(repo), []);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue