mirror of
https://github.com/SkinnyMind/libgit2dart.git
synced 2025-05-04 20:29:08 -04:00
test: add more tests for throws and their messages
This commit is contained in:
parent
d6eae1e9ed
commit
127849519d
80 changed files with 2741 additions and 1501 deletions
|
@ -57,7 +57,10 @@ void main() {
|
|||
|
||||
group('Blame', () {
|
||||
test('successfully gets the blame for provided file', () {
|
||||
final blame = repo.blame(path: 'feature_file');
|
||||
final blame = repo.blame(
|
||||
path: 'feature_file',
|
||||
oldestCommit: repo['f17d0d4'],
|
||||
);
|
||||
|
||||
expect(blame.length, 2);
|
||||
|
||||
|
@ -79,6 +82,33 @@ void main() {
|
|||
blame.free();
|
||||
});
|
||||
|
||||
test('throws when provided file path is invalid', () {
|
||||
expect(
|
||||
() => repo.blame(path: 'invalid'),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"the path 'invalid' does not exist in the given tree",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test(
|
||||
'successfully gets the blame for provided file with minMatchCharacters set',
|
||||
() {
|
||||
final blame = repo.blame(
|
||||
path: 'feature_file',
|
||||
minMatchCharacters: 1,
|
||||
flags: {GitBlameFlag.trackCopiesSameFile},
|
||||
);
|
||||
|
||||
expect(blame.length, 2);
|
||||
|
||||
blame.free();
|
||||
});
|
||||
|
||||
test('successfully gets the blame for provided line', () {
|
||||
final blame = repo.blame(path: 'feature_file');
|
||||
|
||||
|
@ -102,14 +132,32 @@ void main() {
|
|||
|
||||
test('throws when provided index for hunk is invalid', () {
|
||||
final blame = repo.blame(path: 'feature_file');
|
||||
expect(() => blame[10], throwsA(isA<RangeError>()));
|
||||
expect(
|
||||
() => blame[10],
|
||||
throwsA(
|
||||
isA<RangeError>().having(
|
||||
(e) => e.message,
|
||||
'error',
|
||||
'10 is out of bounds',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
blame.free();
|
||||
});
|
||||
|
||||
test('throws when provided line number for hunk is invalid', () {
|
||||
final blame = repo.blame(path: 'feature_file');
|
||||
expect(() => blame.forLine(10), throwsA(isA<RangeError>()));
|
||||
expect(
|
||||
() => blame.forLine(10),
|
||||
throwsA(
|
||||
isA<RangeError>().having(
|
||||
(e) => e.message,
|
||||
'error',
|
||||
'10 is out of bounds',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
blame.free();
|
||||
});
|
||||
|
@ -119,7 +167,7 @@ void main() {
|
|||
() {
|
||||
final blame = repo.blame(
|
||||
path: 'feature_file',
|
||||
newestCommit: repo['fc38877b2552ab554752d9a77e1f48f738cca79b'],
|
||||
newestCommit: repo['fc38877'],
|
||||
flags: {GitBlameFlag.ignoreWhitespace},
|
||||
);
|
||||
|
||||
|
@ -143,6 +191,35 @@ void main() {
|
|||
blame.free();
|
||||
});
|
||||
|
||||
test(
|
||||
'successfully gets the blame for provided file with minLine and maxLine set',
|
||||
() {
|
||||
final blame = repo.blame(
|
||||
path: 'feature_file',
|
||||
minLine: 1,
|
||||
maxLine: 1,
|
||||
);
|
||||
|
||||
expect(blame.length, 1);
|
||||
|
||||
for (var i = 0; i < blame.length; i++) {
|
||||
expect(blame[i].linesCount, 1);
|
||||
expect(blame[i].finalCommitOid.sha, hunks[i]['finalCommitOid']);
|
||||
expect(blame[i].finalStartLineNumber, hunks[i]['finalStartLineNumber']);
|
||||
expect(blame[i].finalCommitter, hunks[i]['finalCommitter']);
|
||||
expect(blame[i].originCommitOid.sha, hunks[i]['originCommitOid']);
|
||||
expect(
|
||||
blame[i].originStartLineNumber,
|
||||
hunks[i]['originStartLineNumber'],
|
||||
);
|
||||
expect(blame[i].originCommitter, hunks[i]['originCommitter']);
|
||||
expect(blame[i].isBoundary, hunks[i]['isBoundary']);
|
||||
expect(blame[i].originPath, 'feature_file');
|
||||
}
|
||||
|
||||
blame.free();
|
||||
});
|
||||
|
||||
test('returns string representation of BlameHunk object', () {
|
||||
final blame = repo.blame(path: 'feature_file');
|
||||
expect(blame.toString(), contains('BlameHunk{'));
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import 'dart:ffi';
|
||||
import 'dart:io';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:libgit2dart/libgit2dart.dart';
|
||||
|
@ -28,6 +29,19 @@ void main() {
|
|||
expect(blob, isA<Blob>());
|
||||
});
|
||||
|
||||
test('throws when trying to lookup with invalid oid', () {
|
||||
expect(
|
||||
() => repo.lookupBlob(repo['0' * 40]),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
'odb: cannot read object: null OID cannot exist',
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('returns correct values', () {
|
||||
expect(blob.oid.sha, blobSHA);
|
||||
expect(blob.isBinary, false);
|
||||
|
@ -47,6 +61,20 @@ void main() {
|
|||
newBlob.free();
|
||||
});
|
||||
|
||||
test('throws when trying to create new blob and error occurs', () {
|
||||
final nullRepo = Repository(nullptr);
|
||||
expect(
|
||||
() => Blob.create(repo: nullRepo, content: ''),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"invalid argument: 'repo'",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('successfully creates new blob from file at provided relative path',
|
||||
() {
|
||||
final oid = repo.createBlobFromWorkdir('feature_file');
|
||||
|
@ -66,24 +94,13 @@ void main() {
|
|||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'message',
|
||||
'error',
|
||||
"could not find '${repo.workdir}invalid/path.txt' to stat: No such file or directory",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test(
|
||||
'throws when creating new blob from path that is outside of working directory',
|
||||
() {
|
||||
final outsideFile =
|
||||
File('${Directory.current.absolute.path}/test/blob_test.dart');
|
||||
expect(
|
||||
() => repo.createBlobFromWorkdir(outsideFile.path),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
});
|
||||
|
||||
test('successfully creates new blob from file at provided path', () {
|
||||
final outsideFile =
|
||||
File('${Directory.current.absolute.path}/test/blob_test.dart');
|
||||
|
@ -96,6 +113,19 @@ void main() {
|
|||
newBlob.free();
|
||||
});
|
||||
|
||||
test('throws when trying to create from invalid path', () {
|
||||
expect(
|
||||
() => repo.createBlobFromDisk('invalid.file'),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"failed to resolve path 'invalid.file': No such file or directory",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
group('diff', () {
|
||||
const path = 'feature_file';
|
||||
const blobPatch = """
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import 'dart:ffi';
|
||||
import 'dart:io';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:libgit2dart/libgit2dart.dart';
|
||||
|
@ -46,19 +47,53 @@ void main() {
|
|||
expect(repo.branchesRemote, []);
|
||||
});
|
||||
|
||||
test('throws when trying to return list and error occurs', () {
|
||||
final nullRepo = Repository(nullptr);
|
||||
expect(
|
||||
() => Branch.list(repo: nullRepo),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"invalid argument: 'repo'",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('returns a branch with provided name', () {
|
||||
final branch = repo.lookupBranch('master');
|
||||
final branch = repo.lookupBranch(name: 'master');
|
||||
expect(branch.target.sha, lastCommit.sha);
|
||||
branch.free();
|
||||
});
|
||||
|
||||
test('throws when provided name not found', () {
|
||||
expect(() => repo.lookupBranch('invalid'), throwsA(isA<LibGit2Error>()));
|
||||
expect(
|
||||
() => repo.lookupBranch(name: 'invalid'),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"cannot locate local branch 'invalid'",
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(
|
||||
() => repo.lookupBranch(name: 'origin/invalid', type: GitBranch.remote),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"cannot locate remote-tracking branch 'origin/invalid'",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('checks if branch is current head', () {
|
||||
final masterBranch = repo.lookupBranch('master');
|
||||
final featureBranch = repo.lookupBranch('feature');
|
||||
final masterBranch = repo.lookupBranch(name: 'master');
|
||||
final featureBranch = repo.lookupBranch(name: 'feature');
|
||||
|
||||
expect(masterBranch.isHead, true);
|
||||
expect(featureBranch.isHead, false);
|
||||
|
@ -67,12 +102,65 @@ void main() {
|
|||
featureBranch.free();
|
||||
});
|
||||
|
||||
test('throws when checking if branch is current head and error occurs', () {
|
||||
final nullBranch = Branch(nullptr);
|
||||
expect(
|
||||
() => nullBranch.isHead,
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"invalid argument: 'branch'",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('checks if branch is checked out', () {
|
||||
final masterBranch = repo.lookupBranch(name: 'master');
|
||||
final featureBranch = repo.lookupBranch(name: 'feature');
|
||||
|
||||
expect(masterBranch.isCheckedOut, true);
|
||||
expect(featureBranch.isCheckedOut, false);
|
||||
|
||||
masterBranch.free();
|
||||
featureBranch.free();
|
||||
});
|
||||
|
||||
test('throws when checking if branch is checked out and error occurs', () {
|
||||
final nullBranch = Branch(nullptr);
|
||||
expect(
|
||||
() => nullBranch.isCheckedOut,
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"invalid argument: 'branch'",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('returns name', () {
|
||||
final branch = repo.lookupBranch('master');
|
||||
final branch = repo.lookupBranch(name: 'master');
|
||||
expect(branch.name, 'master');
|
||||
branch.free();
|
||||
});
|
||||
|
||||
test('throws when getting name and error occurs', () {
|
||||
final nullBranch = Branch(nullptr);
|
||||
expect(
|
||||
() => nullBranch.name,
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"invalid argument: 'ref'",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
group('create()', () {
|
||||
test('successfully creates', () {
|
||||
final commit = repo.lookupCommit(lastCommit);
|
||||
|
@ -95,7 +183,14 @@ void main() {
|
|||
|
||||
expect(
|
||||
() => repo.createBranch(name: 'feature', target: commit),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"failed to write reference 'refs/heads/feature': "
|
||||
"a reference with that name already exists.",
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
commit.free();
|
||||
|
@ -127,15 +222,27 @@ void main() {
|
|||
repo.deleteBranch('feature');
|
||||
|
||||
expect(
|
||||
() => repo.lookupBranch('feature'),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
() => repo.lookupBranch(name: 'feature'),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"cannot locate local branch 'feature'",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('throws when trying to delete current HEAD', () {
|
||||
expect(
|
||||
() => repo.deleteBranch('master'),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"cannot delete branch 'refs/heads/master' as it is the current HEAD of the repository.",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
@ -143,13 +250,19 @@ void main() {
|
|||
group('rename()', () {
|
||||
test('successfully renames', () {
|
||||
repo.renameBranch(oldName: 'feature', newName: 'renamed');
|
||||
final branch = repo.lookupBranch('renamed');
|
||||
final branch = repo.lookupBranch(name: 'renamed');
|
||||
final branches = repo.branches;
|
||||
|
||||
expect(branches.length, 2);
|
||||
expect(
|
||||
() => repo.lookupBranch('feature'),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
() => repo.lookupBranch(name: 'feature'),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"cannot locate local branch 'feature'",
|
||||
),
|
||||
),
|
||||
);
|
||||
expect(branch.target, featureCommit);
|
||||
|
||||
|
@ -162,7 +275,14 @@ void main() {
|
|||
test('throws when name already exists', () {
|
||||
expect(
|
||||
() => repo.renameBranch(oldName: 'feature', newName: 'master'),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"failed to write reference 'refs/heads/master': "
|
||||
"a reference with that name already exists.",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -172,7 +292,7 @@ void main() {
|
|||
newName: 'feature',
|
||||
force: true,
|
||||
);
|
||||
final branch = repo.lookupBranch('feature');
|
||||
final branch = repo.lookupBranch(name: 'feature');
|
||||
|
||||
expect(branch.target, lastCommit);
|
||||
|
||||
|
@ -182,13 +302,19 @@ void main() {
|
|||
test('throws when name is invalid', () {
|
||||
expect(
|
||||
() => repo.renameBranch(oldName: 'feature', newName: 'inv@{id'),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"the given reference name 'refs/heads/inv@{id' is not valid",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
test('returns string representation of Branch object', () {
|
||||
final branch = repo.lookupBranch('master');
|
||||
final branch = repo.lookupBranch(name: 'master');
|
||||
expect(branch.toString(), contains('Branch{'));
|
||||
branch.free();
|
||||
});
|
||||
|
|
|
@ -23,21 +23,61 @@ void main() {
|
|||
File('${tmpDir.path}/feature_file').writeAsStringSync('edit');
|
||||
expect(repo.status, contains('feature_file'));
|
||||
|
||||
repo.checkout(refName: 'HEAD', strategy: {GitCheckout.force});
|
||||
repo.checkout(
|
||||
refName: 'HEAD',
|
||||
strategy: {GitCheckout.force},
|
||||
paths: ['feature_file'],
|
||||
);
|
||||
expect(repo.status, isEmpty);
|
||||
});
|
||||
|
||||
test(
|
||||
'throws when trying to checkout head with invalid alternative directory',
|
||||
() {
|
||||
expect(
|
||||
() => repo.checkout(
|
||||
refName: 'HEAD',
|
||||
directory: 'not/there',
|
||||
),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"failed to make directory 'not/there': No such file or directory",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('successfully checkouts index', () {
|
||||
File('${repo.workdir}feature_file').writeAsStringSync('edit');
|
||||
expect(repo.status, contains('feature_file'));
|
||||
|
||||
repo.checkout(strategy: {
|
||||
GitCheckout.force,
|
||||
GitCheckout.conflictStyleMerge,
|
||||
});
|
||||
repo.checkout(
|
||||
strategy: {
|
||||
GitCheckout.force,
|
||||
GitCheckout.conflictStyleMerge,
|
||||
},
|
||||
paths: ['feature_file'],
|
||||
);
|
||||
expect(repo.status, isEmpty);
|
||||
});
|
||||
|
||||
test(
|
||||
'throws when trying to checkout index with invalid alternative directory',
|
||||
() {
|
||||
expect(
|
||||
() => repo.checkout(directory: 'not/there'),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"failed to make directory 'not/there': No such file or directory",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('successfully checkouts tree', () {
|
||||
final masterHead = repo.lookupCommit(
|
||||
repo['821ed6e80627b8769d170a293862f9fc60825226'],
|
||||
|
@ -68,6 +108,24 @@ void main() {
|
|||
masterHead.free();
|
||||
});
|
||||
|
||||
test(
|
||||
'throws when trying to checkout tree with invalid alternative directory',
|
||||
() {
|
||||
expect(
|
||||
() => repo.checkout(
|
||||
refName: 'refs/heads/feature',
|
||||
directory: 'not/there',
|
||||
),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"failed to make directory 'not/there': No such file or directory",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('successfully checkouts with alrenative directory', () {
|
||||
final altDir = Directory('${Directory.systemTemp.path}/alt_dir');
|
||||
// making sure there is no directory
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import 'dart:ffi';
|
||||
import 'dart:io';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:libgit2dart/libgit2dart.dart';
|
||||
|
@ -41,12 +42,44 @@ void main() {
|
|||
});
|
||||
|
||||
group('Commit', () {
|
||||
test('successfully returns when 40 char sha hex is provided', () {
|
||||
test('successfully lookups for provided oid', () {
|
||||
final commit = repo.lookupCommit(mergeCommit);
|
||||
expect(commit, isA<Commit>());
|
||||
commit.free();
|
||||
});
|
||||
|
||||
test('throws when trying to lookup with invalid oid', () {
|
||||
expect(
|
||||
() => repo.lookupCommit(repo['0' * 40]),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"odb: cannot read object: null OID cannot exist",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('successfully lookups annotated commit for provided oid', () {
|
||||
final annotated = AnnotatedCommit.lookup(repo: repo, oid: mergeCommit);
|
||||
expect(annotated, isA<AnnotatedCommit>());
|
||||
annotated.free();
|
||||
});
|
||||
|
||||
test('throws when trying to lookup annotated commit with invalid oid', () {
|
||||
expect(
|
||||
() => AnnotatedCommit.lookup(repo: repo, oid: repo['0' * 40]),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"odb: cannot read object: null OID cannot exist",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('successfully reverts commit', () {
|
||||
final to = repo.lookupCommit(
|
||||
repo['78b8bf123e3952c970ae5c1ce0a3ea1d1336f6e8'],
|
||||
|
@ -66,6 +99,23 @@ void main() {
|
|||
from.free();
|
||||
});
|
||||
|
||||
test('throws when trying to revert commit and error occurs', () {
|
||||
final nullCommit = Commit(nullptr);
|
||||
expect(
|
||||
() => repo.revertCommit(
|
||||
revertCommit: nullCommit,
|
||||
ourCommit: nullCommit,
|
||||
),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"invalid argument: 'revert_commit'",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('successfully creates commit', () {
|
||||
final parent = repo.lookupCommit(mergeCommit);
|
||||
final oid = repo.createCommit(
|
||||
|
@ -148,6 +198,30 @@ void main() {
|
|||
commit.free();
|
||||
});
|
||||
|
||||
test('throws when trying to create commit and error occurs', () {
|
||||
final parent = repo.lookupCommit(mergeCommit);
|
||||
final nullRepo = Repository(nullptr);
|
||||
|
||||
expect(
|
||||
() => nullRepo.createCommit(
|
||||
message: message,
|
||||
author: author,
|
||||
commiter: commiter,
|
||||
tree: tree,
|
||||
parents: [parent],
|
||||
),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"invalid argument: 'git_tree_owner(tree) == repo'",
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
parent.free();
|
||||
});
|
||||
|
||||
test('returns string representation of Commit object', () {
|
||||
final commit = repo.lookupCommit(mergeCommit);
|
||||
expect(commit.toString(), contains('Commit{'));
|
||||
|
|
|
@ -82,6 +82,20 @@ void main() {
|
|||
expect(credentials.toString(), contains('KeypairFromAgent{'));
|
||||
});
|
||||
|
||||
test('sucessfully clones repository with provided username', () {
|
||||
final callbacks = const Callbacks(credentials: Username('git'));
|
||||
|
||||
final repo = Repository.clone(
|
||||
url: 'https://git@github.com/libgit2/TestGitRepository',
|
||||
localPath: cloneDir.path,
|
||||
callbacks: callbacks,
|
||||
);
|
||||
|
||||
expect(repo.isEmpty, false);
|
||||
|
||||
repo.free();
|
||||
});
|
||||
|
||||
test('sucessfully clones repository with provided keypair', () {
|
||||
final keypair = const Keypair(
|
||||
username: 'git',
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import 'dart:ffi';
|
||||
import 'dart:io';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:libgit2dart/libgit2dart.dart';
|
||||
|
@ -22,6 +23,20 @@ void main() {
|
|||
expect(repo.describe(), 'v0.2');
|
||||
});
|
||||
|
||||
test('throws when trying to describe and error occurs', () {
|
||||
final nullRepo = Repository(nullptr);
|
||||
expect(
|
||||
() => nullRepo.describe(),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"invalid argument: 'repo'",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('successfully describes commit', () {
|
||||
repo.deleteTag('v0.2');
|
||||
|
||||
|
@ -33,7 +48,16 @@ void main() {
|
|||
|
||||
test('throws when trying to describe and no reference found', () {
|
||||
final commit = repo.lookupCommit(repo['f17d0d48']);
|
||||
expect(() => repo.describe(commit: commit), throwsA(isA<LibGit2Error>()));
|
||||
expect(
|
||||
() => repo.describe(commit: commit),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"cannot describe - no tags can describe 'f17d0d48eae3aa08cecf29128a35e310c97b3521'.",
|
||||
),
|
||||
),
|
||||
);
|
||||
commit.free();
|
||||
});
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import 'dart:ffi';
|
||||
import 'dart:io';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:libgit2dart/libgit2dart.dart';
|
||||
|
@ -141,6 +142,22 @@ index e69de29..c217c63 100644
|
|||
diff.free();
|
||||
});
|
||||
|
||||
test('throws when trying to diff between tree and workdir and error occurs',
|
||||
() {
|
||||
final nullRepo = Repository(nullptr);
|
||||
final nullTree = Tree(nullptr);
|
||||
expect(
|
||||
() => nullRepo.diff(a: nullTree),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"invalid argument: 'repo'",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('successfully returns diff between tree and index', () {
|
||||
final index = repo.index;
|
||||
final head = repo.head;
|
||||
|
@ -179,9 +196,34 @@ index e69de29..c217c63 100644
|
|||
diff.free();
|
||||
});
|
||||
|
||||
test('throws when trying to diff between tree and tree and error occurs',
|
||||
() {
|
||||
final nullRepo = Repository(nullptr);
|
||||
final nullTree = Tree(nullptr);
|
||||
expect(
|
||||
() => nullRepo.diff(a: nullTree, b: nullTree),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"invalid argument: 'repo'",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('throws when trying to diff between null and tree', () {
|
||||
final tree = repo.lookupTree(repo['b85d53c']);
|
||||
expect(() => repo.diff(a: null, b: tree), throwsA(isA<ArgumentError>()));
|
||||
expect(
|
||||
() => repo.diff(a: null, b: tree),
|
||||
throwsA(
|
||||
isA<ArgumentError>().having(
|
||||
(e) => e.message,
|
||||
'error',
|
||||
"Must not be null",
|
||||
),
|
||||
),
|
||||
);
|
||||
tree.free();
|
||||
});
|
||||
|
||||
|
@ -216,31 +258,51 @@ index e69de29..c217c63 100644
|
|||
expect(diff.length, 1);
|
||||
expect(stats.filesChanged, 1);
|
||||
expect(stats.insertions, 1);
|
||||
expect(diff.patchId.sha, '699556913185bc38632ae20a49d5c18b9233335e');
|
||||
expect(diff.patchOid.sha, '699556913185bc38632ae20a49d5c18b9233335e');
|
||||
|
||||
stats.free();
|
||||
diff.free();
|
||||
});
|
||||
|
||||
test(
|
||||
'checks if diff can be applied to repository and successfully applies it',
|
||||
() {
|
||||
test('checks if diff can be applied to repository', () {
|
||||
final diff1 = repo.diff();
|
||||
expect(repo.applies(diff: diff1, location: GitApplyLocation.both), false);
|
||||
|
||||
final diff2 = Diff.parse(patchText);
|
||||
repo.checkout(refName: 'HEAD', strategy: {GitCheckout.force});
|
||||
expect(repo.applies(diff: diff2, location: GitApplyLocation.both), true);
|
||||
|
||||
diff1.free();
|
||||
diff2.free();
|
||||
});
|
||||
|
||||
test('successfully applies diff to repository', () {
|
||||
final diff = Diff.parse(patchText);
|
||||
final file = File('${tmpDir.path}/subdir/modified_file');
|
||||
|
||||
repo.reset(
|
||||
oid: repo['a763aa560953e7cfb87ccbc2f536d665aa4dff22'],
|
||||
resetType: GitReset.hard,
|
||||
);
|
||||
repo.checkout(refName: 'HEAD', strategy: {GitCheckout.force});
|
||||
expect(file.readAsStringSync(), '');
|
||||
|
||||
expect(repo.applies(diff), true);
|
||||
repo.apply(diff);
|
||||
repo.apply(diff: diff);
|
||||
expect(file.readAsStringSync(), 'Modified content\n');
|
||||
|
||||
diff.free();
|
||||
});
|
||||
|
||||
test('throws when trying to apply diff and error occurs', () {
|
||||
final nullDiff = Diff(nullptr);
|
||||
expect(
|
||||
() => repo.apply(diff: nullDiff),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"invalid argument: 'diff'",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('successfully creates patch from entry index in diff', () {
|
||||
final diff = Diff.parse(patchText);
|
||||
final patch = Patch.fromDiff(diff: diff, index: 0);
|
||||
|
@ -279,6 +341,34 @@ index e69de29..c217c63 100644
|
|||
newTree.free();
|
||||
});
|
||||
|
||||
test('throws when trying to find similar entries and error occurs', () {
|
||||
final nullDiff = Diff(nullptr);
|
||||
expect(
|
||||
() => nullDiff.findSimilar(),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"invalid argument: 'diff'",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('throws when trying to get patch Oid and error occurs', () {
|
||||
final nullDiff = Diff(nullptr);
|
||||
expect(
|
||||
() => nullDiff.patchOid,
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"invalid argument: 'diff'",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('returns deltas', () {
|
||||
final index = repo.index;
|
||||
final diff = index.diffToWorkdir();
|
||||
|
@ -294,10 +384,7 @@ index e69de29..c217c63 100644
|
|||
diff.deltas[0].oldFile.oid.sha,
|
||||
'e69de29bb2d1d6434b8b29ae775ad8c2e48c5391',
|
||||
);
|
||||
expect(
|
||||
diff.deltas[0].newFile.oid.sha,
|
||||
'0000000000000000000000000000000000000000',
|
||||
);
|
||||
expect(diff.deltas[0].newFile.oid.sha, '0' * 40);
|
||||
|
||||
expect(diff.deltas[2].oldFile.size, 17);
|
||||
|
||||
|
@ -316,7 +403,26 @@ index e69de29..c217c63 100644
|
|||
index.free();
|
||||
});
|
||||
|
||||
test('returns deltas', () {
|
||||
test('throws when trying to get delta with invalid index', () {
|
||||
final index = repo.index;
|
||||
final diff = index.diffToWorkdir();
|
||||
|
||||
expect(
|
||||
() => diff.deltas[-1],
|
||||
throwsA(
|
||||
isA<RangeError>().having(
|
||||
(e) => e.message,
|
||||
'error',
|
||||
"Invalid value",
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
diff.free();
|
||||
index.free();
|
||||
});
|
||||
|
||||
test('returns patches', () {
|
||||
final index = repo.index;
|
||||
final diff = index.diffToWorkdir();
|
||||
final patches = diff.patches;
|
||||
|
@ -346,6 +452,34 @@ index e69de29..c217c63 100644
|
|||
index.free();
|
||||
});
|
||||
|
||||
test('throws when trying to get stats and error occurs', () {
|
||||
final nullDiff = Diff(nullptr);
|
||||
expect(
|
||||
() => nullDiff.stats,
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"invalid argument: 'diff'",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('throws when trying to print stats and error occurs', () {
|
||||
final nullStats = DiffStats(nullptr);
|
||||
expect(
|
||||
() => nullStats.print(format: {GitDiffStats.full}, width: 80),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"invalid argument: 'stats'",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('returns patch diff string', () {
|
||||
final diff = Diff.parse(patchText);
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import 'dart:ffi';
|
||||
import 'dart:io';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:libgit2dart/libgit2dart.dart';
|
||||
|
@ -74,6 +75,19 @@ void main() {
|
|||
expect(index.length, 0);
|
||||
});
|
||||
|
||||
test('throws when trying to clear the contents and error occurs', () {
|
||||
expect(
|
||||
() => Index(nullptr).clear(),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"invalid argument: 'index'",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
group('add()', () {
|
||||
test('successfully adds with provided IndexEntry', () {
|
||||
final entry = index['file'];
|
||||
|
@ -90,14 +104,45 @@ void main() {
|
|||
});
|
||||
|
||||
test('throws if file not found at provided path', () {
|
||||
expect(() => index.add('not_there'), throwsA(isA<LibGit2Error>()));
|
||||
expect(
|
||||
() => index.add('not_there'),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"could not find '${repo.workdir}not_there' to stat: No such file or directory",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('throws if provided IndexEntry is invalid', () {
|
||||
expect(
|
||||
() => index.add(IndexEntry(nullptr)),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"invalid argument: 'source_entry && source_entry->path'",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('throws if index of bare repository', () {
|
||||
final bare = Repository.open('test/assets/empty_bare.git');
|
||||
final bareIndex = bare.index;
|
||||
|
||||
expect(() => bareIndex.add('config'), throwsA(isA<LibGit2Error>()));
|
||||
expect(
|
||||
() => bareIndex.add('config'),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"cannot create blob from file. This operation is not allowed against bare repositories.",
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
bareIndex.free();
|
||||
bare.free();
|
||||
|
@ -126,6 +171,25 @@ void main() {
|
|||
expect(index.length, 1);
|
||||
expect(index['feature_file'].sha, featureFileSha);
|
||||
});
|
||||
|
||||
test('throws when trying to addAll in bare repository', () {
|
||||
final bare = Repository.open('test/assets/empty_bare.git');
|
||||
final bareIndex = bare.index;
|
||||
|
||||
expect(
|
||||
() => bareIndex.addAll([]),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"cannot index add all. This operation is not allowed against bare repositories.",
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
bareIndex.free();
|
||||
bare.free();
|
||||
});
|
||||
});
|
||||
|
||||
test('writes to disk', () {
|
||||
|
@ -148,6 +212,19 @@ void main() {
|
|||
expect(index.find('feature_file'), false);
|
||||
});
|
||||
|
||||
test('throws when trying to remove entry with invalid path', () {
|
||||
expect(
|
||||
() => index.remove('invalid'),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"index does not contain invalid at stage 0",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('removes all entries with matching pathspec', () {
|
||||
expect(index.find('file'), true);
|
||||
expect(index.find('feature_file'), true);
|
||||
|
@ -177,11 +254,51 @@ void main() {
|
|||
expect(oid.sha, 'a8ae3dd59e6e1802c6f78e05e301bfd57c9f334f');
|
||||
});
|
||||
|
||||
test('throws when trying to write tree to invalid repository', () {
|
||||
expect(
|
||||
() => index.writeTree(Repository(nullptr)),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"invalid argument: 'repo'",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('throws when trying to write tree while index have conflicts', () {
|
||||
final tmpDir = setupRepo(Directory('test/assets/mergerepo/'));
|
||||
final repo = Repository.open(tmpDir.path);
|
||||
|
||||
final conflictBranch = repo.lookupBranch(name: 'conflict-branch');
|
||||
final index = repo.index;
|
||||
repo.merge(conflictBranch.target);
|
||||
|
||||
expect(
|
||||
() => index.writeTree(),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"cannot create a tree from a not fully merged index.",
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
conflictBranch.free();
|
||||
index.free();
|
||||
repo.free();
|
||||
tmpDir.deleteSync(recursive: true);
|
||||
});
|
||||
|
||||
test('returns conflicts with ancestor, our and their present', () {
|
||||
final repoDir = setupRepo(Directory('test/assets/mergerepo/'));
|
||||
final conflictRepo = Repository.open(repoDir.path);
|
||||
|
||||
final conflictBranch = conflictRepo.lookupBranch('ancestor-conflict');
|
||||
final conflictBranch = conflictRepo.lookupBranch(
|
||||
name: 'ancestor-conflict',
|
||||
);
|
||||
|
||||
conflictRepo.checkout(refName: 'refs/heads/feature');
|
||||
|
||||
|
@ -204,7 +321,7 @@ void main() {
|
|||
final repoDir = setupRepo(Directory('test/assets/mergerepo/'));
|
||||
final conflictRepo = Repository.open(repoDir.path);
|
||||
|
||||
final conflictBranch = conflictRepo.lookupBranch('conflict-branch');
|
||||
final conflictBranch = conflictRepo.lookupBranch(name: 'conflict-branch');
|
||||
|
||||
conflictRepo.merge(conflictBranch.target);
|
||||
|
||||
|
@ -225,7 +342,9 @@ void main() {
|
|||
final repoDir = setupRepo(Directory('test/assets/mergerepo/'));
|
||||
final conflictRepo = Repository.open(repoDir.path);
|
||||
|
||||
final conflictBranch = conflictRepo.lookupBranch('ancestor-conflict');
|
||||
final conflictBranch = conflictRepo.lookupBranch(
|
||||
name: 'ancestor-conflict',
|
||||
);
|
||||
|
||||
conflictRepo.checkout(refName: 'refs/heads/our-conflict');
|
||||
|
||||
|
@ -248,7 +367,7 @@ void main() {
|
|||
final repoDir = setupRepo(Directory('test/assets/mergerepo/'));
|
||||
final conflictRepo = Repository.open(repoDir.path);
|
||||
|
||||
final conflictBranch = conflictRepo.lookupBranch('their-conflict');
|
||||
final conflictBranch = conflictRepo.lookupBranch(name: 'their-conflict');
|
||||
|
||||
conflictRepo.checkout(refName: 'refs/heads/feature');
|
||||
|
||||
|
@ -267,6 +386,43 @@ void main() {
|
|||
repoDir.deleteSync(recursive: true);
|
||||
});
|
||||
|
||||
test('successfully removes conflicts', () {
|
||||
final repoDir = setupRepo(Directory('test/assets/mergerepo/'));
|
||||
final conflictRepo = Repository.open(repoDir.path);
|
||||
|
||||
final conflictBranch = conflictRepo.lookupBranch(name: 'conflict-branch');
|
||||
final index = conflictRepo.index;
|
||||
|
||||
conflictRepo.merge(conflictBranch.target);
|
||||
expect(index.hasConflicts, true);
|
||||
expect(index.conflicts.length, 1);
|
||||
|
||||
final conflictedFile = index.conflicts['conflict_file']!;
|
||||
conflictedFile.remove();
|
||||
expect(index.hasConflicts, false);
|
||||
expect(index.conflicts, isEmpty);
|
||||
expect(index.conflicts['conflict_file'], null);
|
||||
|
||||
index.free();
|
||||
conflictBranch.free();
|
||||
conflictRepo.free();
|
||||
repoDir.deleteSync(recursive: true);
|
||||
});
|
||||
|
||||
test('throws when trying to remove conflict and error occurs', () {
|
||||
expect(
|
||||
() => ConflictEntry(index.pointer, 'invalid.path', null, null, null)
|
||||
.remove(),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"index does not contain invalid.path",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('returns string representation of Index and IndexEntry objects', () {
|
||||
final index = repo.index;
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import 'dart:ffi';
|
||||
import 'dart:io';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:libgit2dart/libgit2dart.dart';
|
||||
|
@ -172,6 +173,19 @@ Santa Claus <santa.claus@northpole.xx> <me@company.xx>
|
|||
mailmap.free();
|
||||
});
|
||||
|
||||
test('throws when initializing from repository and error occurs', () {
|
||||
expect(
|
||||
() => Mailmap.fromRepository(Repository(nullptr)),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"invalid argument: 'repo'",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('successfully resolves names and emails when mailmap is empty', () {
|
||||
final mailmap = Mailmap.empty();
|
||||
|
||||
|
@ -207,6 +221,25 @@ Santa Claus <santa.claus@northpole.xx> <me@company.xx>
|
|||
mailmap.free();
|
||||
});
|
||||
|
||||
test('throws when trying to add entry with empty replace email', () {
|
||||
final mailmap = Mailmap.empty();
|
||||
|
||||
expect(
|
||||
() => mailmap.addEntry(
|
||||
replaceEmail: ' ',
|
||||
),
|
||||
throwsA(
|
||||
isA<ArgumentError>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
'Invalid argument: "replaceEmail can\'t be empty"',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
mailmap.free();
|
||||
});
|
||||
|
||||
test('successfully resolves signature', () {
|
||||
final signature = Signature.create(
|
||||
name: 'nick1',
|
||||
|
@ -225,6 +258,8 @@ Santa Claus <santa.claus@northpole.xx> <me@company.xx>
|
|||
);
|
||||
|
||||
expect(mailmap.resolveSignature(signature), realSignature);
|
||||
|
||||
mailmap.free();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
// ignore_for_file: unnecessary_string_escapes
|
||||
|
||||
import 'dart:ffi';
|
||||
import 'dart:io';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:libgit2dart/libgit2dart.dart';
|
||||
|
@ -22,49 +23,32 @@ void main() {
|
|||
group('Merge', () {
|
||||
group('analysis', () {
|
||||
test('is up to date when no reference is provided', () {
|
||||
final commit = repo.lookupCommit(
|
||||
repo['c68ff54aabf660fcdd9a2838d401583fe31249e3'],
|
||||
);
|
||||
|
||||
final result = repo.mergeAnalysis(theirHead: commit.oid);
|
||||
final result = repo.mergeAnalysis(theirHead: repo['c68ff54']);
|
||||
expect(result, [
|
||||
{GitMergeAnalysis.upToDate},
|
||||
GitMergePreference.none,
|
||||
]);
|
||||
expect(repo.status, isEmpty);
|
||||
|
||||
commit.free();
|
||||
});
|
||||
|
||||
test('is up to date for provided ref', () {
|
||||
final commit = repo.lookupCommit(
|
||||
repo['c68ff54aabf660fcdd9a2838d401583fe31249e3'],
|
||||
);
|
||||
|
||||
final result = repo.mergeAnalysis(
|
||||
theirHead: commit.oid,
|
||||
theirHead: repo['c68ff54'],
|
||||
ourRef: 'refs/tags/v0.1',
|
||||
);
|
||||
expect(result[0], {GitMergeAnalysis.upToDate});
|
||||
expect(repo.status, isEmpty);
|
||||
|
||||
commit.free();
|
||||
});
|
||||
|
||||
test('is fast forward', () {
|
||||
final theirHead = repo.lookupCommit(
|
||||
repo['6cbc22e509d72758ab4c8d9f287ea846b90c448b'],
|
||||
);
|
||||
final ffCommit = repo.lookupCommit(
|
||||
repo['f17d0d48eae3aa08cecf29128a35e310c97b3521'],
|
||||
);
|
||||
final ffCommit = repo.lookupCommit(repo['f17d0d4']);
|
||||
final ffBranch = repo.createBranch(
|
||||
name: 'ff-branch',
|
||||
target: ffCommit,
|
||||
);
|
||||
|
||||
final result = repo.mergeAnalysis(
|
||||
theirHead: theirHead.oid,
|
||||
theirHead: repo['6cbc22e'],
|
||||
ourRef: 'refs/heads/${ffBranch.name}',
|
||||
);
|
||||
expect(
|
||||
|
@ -75,24 +59,17 @@ void main() {
|
|||
|
||||
ffBranch.free();
|
||||
ffCommit.free();
|
||||
theirHead.free();
|
||||
});
|
||||
|
||||
test('is not fast forward and there is no conflicts', () {
|
||||
final commit = repo.lookupCommit(
|
||||
repo['5aecfa0fb97eadaac050ccb99f03c3fb65460ad4'],
|
||||
);
|
||||
|
||||
final result = repo.mergeAnalysis(theirHead: commit.oid);
|
||||
final result = repo.mergeAnalysis(theirHead: repo['5aecfa0']);
|
||||
expect(result[0], {GitMergeAnalysis.normal});
|
||||
expect(repo.status, isEmpty);
|
||||
|
||||
commit.free();
|
||||
});
|
||||
});
|
||||
|
||||
test('writes conflicts to index', () {
|
||||
final conflictBranch = repo.lookupBranch('conflict-branch');
|
||||
final conflictBranch = repo.lookupBranch(name: 'conflict-branch');
|
||||
final index = repo.index;
|
||||
|
||||
final result = repo.mergeAnalysis(theirHead: conflictBranch.target);
|
||||
|
@ -129,24 +106,6 @@ void main() {
|
|||
conflictBranch.free();
|
||||
});
|
||||
|
||||
test('successfully removes conflicts', () {
|
||||
final conflictBranch = repo.lookupBranch('conflict-branch');
|
||||
final index = repo.index;
|
||||
|
||||
repo.merge(conflictBranch.target);
|
||||
expect(index.hasConflicts, true);
|
||||
expect(index.conflicts.length, 1);
|
||||
|
||||
final conflictedFile = index.conflicts['conflict_file']!;
|
||||
conflictedFile.remove();
|
||||
expect(index.hasConflicts, false);
|
||||
expect(index.conflicts, isEmpty);
|
||||
expect(index.conflicts['conflict_file'], null);
|
||||
|
||||
index.free();
|
||||
conflictBranch.free();
|
||||
});
|
||||
|
||||
group('merge file from index', () {
|
||||
test('successfully merges without ancestor', () {
|
||||
const diffExpected = """
|
||||
|
@ -156,7 +115,7 @@ master conflict edit
|
|||
conflict branch edit
|
||||
>>>>>>> conflict_file
|
||||
""";
|
||||
final conflictBranch = repo.lookupBranch('conflict-branch');
|
||||
final conflictBranch = repo.lookupBranch(name: 'conflict-branch');
|
||||
final index = repo.index;
|
||||
repo.merge(conflictBranch.target);
|
||||
|
||||
|
@ -184,7 +143,7 @@ Feature edit on feature branch
|
|||
Another feature edit
|
||||
>>>>>>> feature_file
|
||||
""";
|
||||
final conflictBranch = repo.lookupBranch('ancestor-conflict');
|
||||
final conflictBranch = repo.lookupBranch(name: 'ancestor-conflict');
|
||||
repo.checkout(refName: 'refs/heads/feature');
|
||||
final index = repo.index;
|
||||
repo.merge(conflictBranch.target);
|
||||
|
@ -204,16 +163,29 @@ Another feature edit
|
|||
index.free();
|
||||
conflictBranch.free();
|
||||
});
|
||||
|
||||
test('throws when error occurs', () {
|
||||
expect(
|
||||
() => repo.mergeFileFromIndex(
|
||||
ancestor: null,
|
||||
ours: IndexEntry(nullptr),
|
||||
theirs: IndexEntry(nullptr),
|
||||
),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"invalid argument: 'ours'",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
group('merge commits', () {
|
||||
test('successfully merges with default values', () {
|
||||
final theirCommit = repo.lookupCommit(
|
||||
repo['5aecfa0fb97eadaac050ccb99f03c3fb65460ad4'],
|
||||
);
|
||||
final ourCommit = repo.lookupCommit(
|
||||
repo['14905459d775f3f56a39ebc2ff081163f7da3529'],
|
||||
);
|
||||
final theirCommit = repo.lookupCommit(repo['5aecfa0']);
|
||||
final ourCommit = repo.lookupCommit(repo['1490545']);
|
||||
|
||||
final mergeIndex = repo.mergeCommits(
|
||||
ourCommit: ourCommit,
|
||||
|
@ -236,12 +208,8 @@ Another feature edit
|
|||
});
|
||||
|
||||
test('successfully merges with provided favor', () {
|
||||
final theirCommit = repo.lookupCommit(
|
||||
repo['5aecfa0fb97eadaac050ccb99f03c3fb65460ad4'],
|
||||
);
|
||||
final ourCommit = repo.lookupCommit(
|
||||
repo['14905459d775f3f56a39ebc2ff081163f7da3529'],
|
||||
);
|
||||
final theirCommit = repo.lookupCommit(repo['5aecfa0']);
|
||||
final ourCommit = repo.lookupCommit(repo['1490545']);
|
||||
|
||||
final mergeIndex = repo.mergeCommits(
|
||||
ourCommit: ourCommit,
|
||||
|
@ -256,12 +224,8 @@ Another feature edit
|
|||
});
|
||||
|
||||
test('successfully merges with provided merge and file flags', () {
|
||||
final theirCommit = repo.lookupCommit(
|
||||
repo['5aecfa0fb97eadaac050ccb99f03c3fb65460ad4'],
|
||||
);
|
||||
final ourCommit = repo.lookupCommit(
|
||||
repo['14905459d775f3f56a39ebc2ff081163f7da3529'],
|
||||
);
|
||||
final theirCommit = repo.lookupCommit(repo['5aecfa0']);
|
||||
final ourCommit = repo.lookupCommit(repo['1490545']);
|
||||
|
||||
final mergeIndex = repo.mergeCommits(
|
||||
ourCommit: ourCommit,
|
||||
|
@ -282,18 +246,54 @@ Another feature edit
|
|||
ourCommit.free();
|
||||
theirCommit.free();
|
||||
});
|
||||
|
||||
test('throws when error occurs', () {
|
||||
expect(
|
||||
() => repo.mergeCommits(
|
||||
ourCommit: Commit(nullptr),
|
||||
theirCommit: Commit(nullptr),
|
||||
),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"invalid argument: 'commit'",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
test('successfully finds merge base', () {
|
||||
var base = repo.mergeBase(a: repo['1490545'], b: repo['5aecfa0']);
|
||||
expect(base.sha, 'fc38877b2552ab554752d9a77e1f48f738cca79b');
|
||||
|
||||
base = repo.mergeBase(a: repo['f17d0d4'], b: repo['5aecfa0']);
|
||||
expect(base.sha, 'f17d0d48eae3aa08cecf29128a35e310c97b3521');
|
||||
});
|
||||
|
||||
test('throws when trying to find merge base for invalid oid', () {
|
||||
expect(
|
||||
() => repo.mergeBase(a: repo['0' * 40], b: repo['5aecfa0']),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"odb: cannot read object: null OID cannot exist",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
group('merge trees', () {
|
||||
test('successfully merges with default values', () {
|
||||
final theirCommit = repo.lookupCommit(
|
||||
repo['5aecfa0fb97eadaac050ccb99f03c3fb65460ad4'],
|
||||
);
|
||||
final ourCommit = repo.lookupCommit(
|
||||
repo['14905459d775f3f56a39ebc2ff081163f7da3529'],
|
||||
);
|
||||
final theirCommit = repo.lookupCommit(repo['5aecfa0']);
|
||||
final ourCommit = repo.lookupCommit(repo['1490545']);
|
||||
final baseCommit = repo.lookupCommit(
|
||||
repo.mergeBase(a: ourCommit.oid, b: theirCommit.oid),
|
||||
repo.mergeBase(
|
||||
a: ourCommit.oid,
|
||||
b: theirCommit.oid,
|
||||
),
|
||||
);
|
||||
final theirTree = theirCommit.tree;
|
||||
final ourTree = ourCommit.tree;
|
||||
|
@ -326,14 +326,13 @@ Another feature edit
|
|||
});
|
||||
|
||||
test('successfully merges with provided favor', () {
|
||||
final theirCommit = repo.lookupCommit(
|
||||
repo['5aecfa0fb97eadaac050ccb99f03c3fb65460ad4'],
|
||||
);
|
||||
final ourCommit = repo.lookupCommit(
|
||||
repo['14905459d775f3f56a39ebc2ff081163f7da3529'],
|
||||
);
|
||||
final theirCommit = repo.lookupCommit(repo['5aecfa0']);
|
||||
final ourCommit = repo.lookupCommit(repo['1490545']);
|
||||
final baseCommit = repo.lookupCommit(
|
||||
repo.mergeBase(a: ourCommit.oid, b: theirCommit.oid),
|
||||
repo.mergeBase(
|
||||
a: ourCommit.oid,
|
||||
b: theirCommit.oid,
|
||||
),
|
||||
);
|
||||
final theirTree = theirCommit.tree;
|
||||
final ourTree = ourCommit.tree;
|
||||
|
@ -355,22 +354,60 @@ Another feature edit
|
|||
ourCommit.free();
|
||||
theirCommit.free();
|
||||
});
|
||||
|
||||
test('throws when error occurs', () {
|
||||
expect(
|
||||
() => Repository(nullptr).mergeTrees(
|
||||
ancestorTree: Tree(nullptr),
|
||||
ourTree: Tree(nullptr),
|
||||
theirTree: Tree(nullptr),
|
||||
),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"invalid argument: 'repo'",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
test('successfully cherry-picks commit', () {
|
||||
final cherry = repo.lookupCommit(
|
||||
repo['5aecfa0fb97eadaac050ccb99f03c3fb65460ad4'],
|
||||
);
|
||||
final cherry = repo.lookupCommit(repo['5aecfa0']);
|
||||
repo.cherryPick(cherry);
|
||||
expect(repo.state, GitRepositoryState.cherrypick);
|
||||
expect(repo.message, 'add another feature file\n');
|
||||
final index = repo.index;
|
||||
expect(index.conflicts, isEmpty);
|
||||
|
||||
// pretend we've done commit
|
||||
repo.removeMessage();
|
||||
expect(() => repo.message, throwsA(isA<LibGit2Error>()));
|
||||
expect(
|
||||
() => repo.message,
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"could not access message file: No such file or directory",
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
index.free();
|
||||
});
|
||||
|
||||
test('throws when error occurs', () {
|
||||
expect(
|
||||
() => repo.cherryPick(Commit(nullptr)),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"invalid argument: 'commit'",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import 'dart:ffi';
|
||||
import 'dart:io';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:libgit2dart/libgit2dart.dart';
|
||||
|
@ -43,6 +44,20 @@ void main() {
|
|||
}
|
||||
});
|
||||
|
||||
test('throws when trying to get list of notes and error occurs', () {
|
||||
Directory('${repo.workdir}.git/refs/notes').deleteSync(recursive: true);
|
||||
expect(
|
||||
() => repo.notes,
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"reference 'refs/notes/commits' not found",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('successfully lookups note', () {
|
||||
final head = repo.head;
|
||||
final note = repo.lookupNote(annotatedOid: head.target);
|
||||
|
@ -75,7 +90,25 @@ void main() {
|
|||
signature.free();
|
||||
});
|
||||
|
||||
test('successfully removes note', () {
|
||||
test('throws when trying to create note and error occurs', () {
|
||||
expect(
|
||||
() => Repository(nullptr).createNote(
|
||||
author: Signature(nullptr),
|
||||
committer: Signature(nullptr),
|
||||
annotatedOid: repo['0' * 40],
|
||||
note: '',
|
||||
),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"invalid argument: 'repo'",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('successfully deletes note', () {
|
||||
final signature = repo.defaultSignature;
|
||||
final head = repo.head;
|
||||
|
||||
|
@ -87,13 +120,36 @@ void main() {
|
|||
|
||||
expect(
|
||||
() => repo.lookupNote(annotatedOid: head.target),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"note could not be found",
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
head.free();
|
||||
signature.free();
|
||||
});
|
||||
|
||||
test('throws when trying to delete note and error occurs', () {
|
||||
expect(
|
||||
() => Repository(nullptr).deleteNote(
|
||||
author: Signature(nullptr),
|
||||
committer: Signature(nullptr),
|
||||
annotatedOid: repo['0' * 40],
|
||||
),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"invalid argument: 'repo'",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('returns string representation of Note object', () {
|
||||
final note = repo.lookupNote(annotatedOid: repo['821ed6e']);
|
||||
expect(note.toString(), contains('Note{'));
|
||||
|
|
|
@ -27,6 +27,20 @@ void main() {
|
|||
odb.free();
|
||||
});
|
||||
|
||||
test('throws when trying to get odb and error occurs', () {
|
||||
Directory('${repo.workdir}.git/objects/').deleteSync(recursive: true);
|
||||
expect(
|
||||
() => repo.odb,
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
contains("failed to load object database"),
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('successfully creates new odb with no backends', () {
|
||||
final odb = Odb.create();
|
||||
expect(odb, isA<Odb>());
|
||||
|
@ -56,6 +70,23 @@ void main() {
|
|||
odb.free();
|
||||
});
|
||||
|
||||
test('throws when trying to read object and error occurs', () {
|
||||
final odb = repo.odb;
|
||||
|
||||
expect(
|
||||
() => odb.read(repo['0' * 40]),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"odb: cannot read object: null OID cannot exist",
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
odb.free();
|
||||
});
|
||||
|
||||
test('returns list of all objects oid\'s in database', () {
|
||||
final odb = repo.odb;
|
||||
|
||||
|
@ -65,6 +96,24 @@ void main() {
|
|||
odb.free();
|
||||
});
|
||||
|
||||
test('throws when trying to get list of all objects and error occurs', () {
|
||||
final odb = repo.odb;
|
||||
Directory('${repo.workdir}.git/objects').deleteSync(recursive: true);
|
||||
|
||||
expect(
|
||||
() => odb.objects,
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"object not found - failed to refresh packfiles",
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
odb.free();
|
||||
});
|
||||
|
||||
test('successfully writes data', () {
|
||||
final odb = repo.odb;
|
||||
final oid = odb.write(type: GitObject.blob, data: 'testing');
|
||||
|
@ -81,7 +130,31 @@ void main() {
|
|||
final odb = repo.odb;
|
||||
expect(
|
||||
() => odb.write(type: GitObject.any, data: 'testing'),
|
||||
throwsA(isA<ArgumentError>()),
|
||||
throwsA(
|
||||
isA<ArgumentError>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
'Invalid argument: "GitObject.any is invalid type"',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
odb.free();
|
||||
});
|
||||
|
||||
test('throws when trying to write to disk alternate odb', () {
|
||||
final odb = Odb.create();
|
||||
odb.addDiskAlternate('${repo.workdir}.git/objects/');
|
||||
|
||||
expect(
|
||||
() => odb.write(type: GitObject.blob, data: ''),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"cannot write object - unsupported in the loaded odb backends",
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
odb.free();
|
||||
|
|
|
@ -23,13 +23,13 @@ void main() {
|
|||
|
||||
group('Oid', () {
|
||||
group('fromSHA()', () {
|
||||
test('initializes successfully', () {
|
||||
test('successfully initializes', () {
|
||||
final oid = Oid.fromSHA(repo: repo, sha: sha);
|
||||
expect(oid, isA<Oid>());
|
||||
expect(oid.sha, sha);
|
||||
});
|
||||
|
||||
test('initializes successfully from short hex string', () {
|
||||
test('successfully initializes from short hex string', () {
|
||||
final oid = Oid.fromSHA(repo: repo, sha: sha.substring(0, 5));
|
||||
|
||||
expect(oid, isA<Oid>());
|
||||
|
@ -41,9 +41,22 @@ void main() {
|
|||
() => Oid.fromSHA(repo: repo, sha: 'sha'),
|
||||
throwsA(
|
||||
isA<ArgumentError>().having(
|
||||
(e) => e.invalidValue,
|
||||
(e) => e.toString(),
|
||||
'value',
|
||||
'sha is not a valid sha hex string',
|
||||
'Invalid argument: "sha is not a valid sha hex string"',
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('throws when sha hex string is invalid', () {
|
||||
expect(
|
||||
() => Oid.fromSHA(repo: repo, sha: '0000000'),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"object not found - no match for id prefix (0000000)",
|
||||
),
|
||||
),
|
||||
);
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import 'dart:ffi';
|
||||
import 'dart:io';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:libgit2dart/libgit2dart.dart';
|
||||
|
@ -27,6 +28,19 @@ void main() {
|
|||
packbuilder.free();
|
||||
});
|
||||
|
||||
test('throws when trying to initialize and error occurs', () {
|
||||
expect(
|
||||
() => PackBuilder(Repository(nullptr)),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"invalid argument: 'repo'",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('successfully adds objects', () {
|
||||
final packbuilder = PackBuilder(repo);
|
||||
final odb = repo.odb;
|
||||
|
@ -41,7 +55,24 @@ void main() {
|
|||
packbuilder.free();
|
||||
});
|
||||
|
||||
test('successfully adds objects recursively', () {
|
||||
test('throws when trying to add object and error occurs', () {
|
||||
final packbuilder = PackBuilder(repo);
|
||||
|
||||
expect(
|
||||
() => packbuilder.add(Oid(nullptr)),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"invalid argument: 'oid'",
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
packbuilder.free();
|
||||
});
|
||||
|
||||
test('successfully adds object recursively', () {
|
||||
final packbuilder = PackBuilder(repo);
|
||||
final oid = Oid.fromSHA(repo: repo, sha: 'f17d0d48');
|
||||
|
||||
|
@ -51,6 +82,23 @@ void main() {
|
|||
packbuilder.free();
|
||||
});
|
||||
|
||||
test('throws when trying to add object recursively and error occurs', () {
|
||||
final packbuilder = PackBuilder(repo);
|
||||
|
||||
expect(
|
||||
() => packbuilder.addRecursively(Oid(nullptr)),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"invalid argument: 'id'",
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
packbuilder.free();
|
||||
});
|
||||
|
||||
test('successfully sets number of threads', () {
|
||||
final packbuilder = PackBuilder(repo);
|
||||
|
||||
|
@ -105,6 +153,23 @@ void main() {
|
|||
expect(writtenCount, 18);
|
||||
});
|
||||
|
||||
test('throws when trying to write pack into invalid path', () {
|
||||
final packbuilder = PackBuilder(repo);
|
||||
|
||||
expect(
|
||||
() => packbuilder.write('invalid/path'),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
contains('failed to create temporary file'),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
packbuilder.free();
|
||||
});
|
||||
|
||||
test('returns string representation of PackBuilder object', () {
|
||||
final packbuilder = PackBuilder(repo);
|
||||
expect(packbuilder.toString(), contains('PackBuilder{'));
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import 'dart:ffi';
|
||||
import 'dart:io';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:libgit2dart/libgit2dart.dart';
|
||||
|
@ -8,8 +9,8 @@ void main() {
|
|||
late Directory tmpDir;
|
||||
const oldBlob = '';
|
||||
const newBlob = 'Feature edit\n';
|
||||
late Oid oldBlobID;
|
||||
late Oid newBlobID;
|
||||
late Oid oldBlobOid;
|
||||
late Oid newBlobOid;
|
||||
const path = 'feature_file';
|
||||
const blobPatch = """
|
||||
diff --git a/feature_file b/feature_file
|
||||
|
@ -41,8 +42,8 @@ index e69de29..0000000
|
|||
setUp(() {
|
||||
tmpDir = setupRepo(Directory('test/assets/testrepo/'));
|
||||
repo = Repository.open(tmpDir.path);
|
||||
oldBlobID = repo['e69de29bb2d1d6434b8b29ae775ad8c2e48c5391'];
|
||||
newBlobID = repo['9c78c21d6680a7ffebc76f7ac68cacc11d8f48bc'];
|
||||
oldBlobOid = repo['e69de29bb2d1d6434b8b29ae775ad8c2e48c5391'];
|
||||
newBlobOid = repo['9c78c21d6680a7ffebc76f7ac68cacc11d8f48bc'];
|
||||
});
|
||||
|
||||
tearDown(() {
|
||||
|
@ -92,8 +93,8 @@ index e69de29..0000000
|
|||
});
|
||||
|
||||
test('successfully creates from blobs', () {
|
||||
final a = repo.lookupBlob(oldBlobID);
|
||||
final b = repo.lookupBlob(newBlobID);
|
||||
final a = repo.lookupBlob(oldBlobOid);
|
||||
final b = repo.lookupBlob(newBlobOid);
|
||||
final patch = Patch.create(
|
||||
a: a,
|
||||
b: b,
|
||||
|
@ -107,7 +108,7 @@ index e69de29..0000000
|
|||
});
|
||||
|
||||
test('successfully creates from one blob (add)', () {
|
||||
final b = repo.lookupBlob(newBlobID);
|
||||
final b = repo.lookupBlob(newBlobOid);
|
||||
final patch = Patch.create(
|
||||
a: null,
|
||||
b: b,
|
||||
|
@ -121,7 +122,7 @@ index e69de29..0000000
|
|||
});
|
||||
|
||||
test('successfully creates from one blob (delete)', () {
|
||||
final a = repo.lookupBlob(oldBlobID);
|
||||
final a = repo.lookupBlob(oldBlobOid);
|
||||
final patch = Patch.create(
|
||||
a: a,
|
||||
b: null,
|
||||
|
@ -135,7 +136,7 @@ index e69de29..0000000
|
|||
});
|
||||
|
||||
test('successfully creates from blob and buffer', () {
|
||||
final a = repo.lookupBlob(oldBlobID);
|
||||
final a = repo.lookupBlob(oldBlobOid);
|
||||
final patch = Patch.create(
|
||||
a: a,
|
||||
b: newBlob,
|
||||
|
@ -159,7 +160,13 @@ index e69de29..0000000
|
|||
aPath: 'file',
|
||||
bPath: 'file',
|
||||
),
|
||||
throwsA(isA<ArgumentError>()),
|
||||
throwsA(
|
||||
isA<ArgumentError>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"Invalid argument(s): Provided argument(s) is not Blob or String",
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(
|
||||
|
@ -169,12 +176,44 @@ index e69de29..0000000
|
|||
aPath: 'file',
|
||||
bPath: 'file',
|
||||
),
|
||||
throwsA(isA<ArgumentError>()),
|
||||
throwsA(
|
||||
isA<ArgumentError>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"Invalid argument(s): Provided argument(s) is not Blob or String",
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
commit.free();
|
||||
});
|
||||
|
||||
test('throws when trying to create from diff and error occurs', () {
|
||||
expect(
|
||||
() => Patch.fromDiff(diff: Diff(nullptr), index: 0),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"invalid argument: 'diff'",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('throws when trying to text of patch and error occurs', () {
|
||||
expect(
|
||||
() => Patch(nullptr, nullptr, nullptr).text,
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"invalid argument: 'patch'",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('returns string representation of Patch object', () {
|
||||
final patch = Patch.create(
|
||||
a: oldBlob,
|
||||
|
|
|
@ -29,7 +29,16 @@ void main() {
|
|||
final feature = repo.lookupReference('refs/heads/feature');
|
||||
|
||||
repo.checkout(refName: feature.name);
|
||||
expect(() => repo.index['.gitignore'], throwsA(isA<ArgumentError>()));
|
||||
expect(
|
||||
() => repo.index['.gitignore'],
|
||||
throwsA(
|
||||
isA<ArgumentError>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
'Invalid argument: ".gitignore was not found"',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
final rebase = Rebase.init(
|
||||
repo: repo,
|
||||
|
@ -62,6 +71,38 @@ void main() {
|
|||
signature.free();
|
||||
});
|
||||
|
||||
test('successfully performs rebase without branch provided', () {
|
||||
final signature = repo.defaultSignature;
|
||||
final feature = repo.lookupReference('refs/heads/feature');
|
||||
|
||||
final rebase = Rebase.init(
|
||||
repo: repo,
|
||||
onto: feature.target,
|
||||
);
|
||||
|
||||
final operationsCount = rebase.operationsCount;
|
||||
expect(operationsCount, 3);
|
||||
|
||||
for (var i = 0; i < operationsCount; i++) {
|
||||
final operation = rebase.next();
|
||||
expect(operation.type, GitRebaseOperation.pick);
|
||||
expect(operation.oid.sha, shas[i]);
|
||||
expect(operation.toString(), contains('RebaseOperation{'));
|
||||
|
||||
rebase.commit(
|
||||
committer: signature,
|
||||
author: signature,
|
||||
message: 'rebase message',
|
||||
);
|
||||
}
|
||||
|
||||
rebase.finish();
|
||||
|
||||
rebase.free();
|
||||
feature.free();
|
||||
signature.free();
|
||||
});
|
||||
|
||||
test('successfully performs rebase with provided upstream', () {
|
||||
final signature = repo.defaultSignature;
|
||||
final master = repo.lookupReference('refs/heads/master');
|
||||
|
@ -71,13 +112,18 @@ void main() {
|
|||
repo.checkout(refName: feature.name);
|
||||
expect(
|
||||
() => repo.index['conflict_file'],
|
||||
throwsA(isA<ArgumentError>()),
|
||||
throwsA(
|
||||
isA<ArgumentError>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
'Invalid argument: "conflict_file was not found"',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
final rebase = Rebase.init(
|
||||
repo: repo,
|
||||
branch: master.target,
|
||||
onto: feature.target,
|
||||
upstream: startCommit.oid,
|
||||
);
|
||||
|
||||
|
@ -99,6 +145,21 @@ void main() {
|
|||
signature.free();
|
||||
});
|
||||
|
||||
test(
|
||||
'throws when trying to initialize rebase without upstream and onto provided',
|
||||
() {
|
||||
expect(
|
||||
() => Rebase.init(repo: repo),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"invalid argument: 'upstream || onto'",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('stops when there is conflicts', () {
|
||||
final signature = repo.defaultSignature;
|
||||
final master = repo.lookupReference('refs/heads/master');
|
||||
|
@ -118,7 +179,46 @@ void main() {
|
|||
expect(repo.state, GitRepositoryState.rebaseMerge);
|
||||
expect(
|
||||
() => rebase.commit(committer: signature),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
'unstaged changes exist in workdir',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
rebase.free();
|
||||
conflict.free();
|
||||
master.free();
|
||||
signature.free();
|
||||
});
|
||||
|
||||
test('throws when trying to perfrom next rebase operation and error occurs',
|
||||
() {
|
||||
final signature = repo.defaultSignature;
|
||||
final master = repo.lookupReference('refs/heads/master');
|
||||
final conflict = repo.lookupReference('refs/heads/conflict-branch');
|
||||
|
||||
repo.checkout(refName: conflict.name);
|
||||
|
||||
final rebase = Rebase.init(
|
||||
repo: repo,
|
||||
branch: master.target,
|
||||
onto: conflict.target,
|
||||
);
|
||||
expect(rebase.operationsCount, 1);
|
||||
|
||||
rebase.next(); // repo now have conflicts
|
||||
expect(
|
||||
() => rebase.next(),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"object not found - failed to find pack entry (790b86f5fb50db485586370f27c5f90bada97d83)",
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
rebase.free();
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import 'dart:ffi';
|
||||
import 'dart:io';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:libgit2dart/libgit2dart.dart';
|
||||
|
@ -33,6 +34,19 @@ void main() {
|
|||
);
|
||||
});
|
||||
|
||||
test('throws when trying to get a list of references and error occurs', () {
|
||||
expect(
|
||||
() => Repository(nullptr).references,
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"invalid argument: 'repo'",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('returns correct type of reference', () {
|
||||
final head = repo.head;
|
||||
expect(head.type, ReferenceType.direct);
|
||||
|
@ -55,6 +69,19 @@ void main() {
|
|||
ref.free();
|
||||
});
|
||||
|
||||
test('throws when trying to resolve invalid reference', () {
|
||||
expect(
|
||||
() => Reference(nullptr).target,
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"invalid reference",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('returns the full name', () {
|
||||
final head = repo.head;
|
||||
expect(head.name, 'refs/heads/master');
|
||||
|
@ -154,7 +181,13 @@ void main() {
|
|||
name: 'refs/tags/invalid',
|
||||
target: '78b',
|
||||
),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"the given reference name '78b' is not valid",
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(
|
||||
|
@ -162,7 +195,13 @@ void main() {
|
|||
name: 'refs/tags/invalid',
|
||||
target: 0,
|
||||
),
|
||||
throwsA(isA<ArgumentError>()),
|
||||
throwsA(
|
||||
isA<ArgumentError>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
'Invalid argument: "0 must be either Oid or String reference name"',
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -172,7 +211,13 @@ void main() {
|
|||
name: 'refs/tags/invalid~',
|
||||
target: repo[lastCommit],
|
||||
),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"the given reference name 'refs/tags/invalid~' is not valid",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -205,7 +250,14 @@ void main() {
|
|||
name: 'refs/tags/test',
|
||||
target: repo[lastCommit],
|
||||
),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"failed to write reference 'refs/tags/test': a reference with that "
|
||||
"name already exists.",
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
ref.free();
|
||||
|
@ -255,7 +307,14 @@ void main() {
|
|||
name: 'refs/tags/exists',
|
||||
target: 'refs/heads/master',
|
||||
),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"failed to write reference 'refs/tags/exists': a reference with that "
|
||||
"name already exists.",
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
ref.free();
|
||||
|
@ -267,7 +326,13 @@ void main() {
|
|||
name: 'refs/tags/invalid~',
|
||||
target: 'refs/heads/master',
|
||||
),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"the given reference name 'refs/tags/invalid~' is not valid",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -293,15 +358,10 @@ void main() {
|
|||
});
|
||||
|
||||
test('successfully deletes reference', () {
|
||||
final ref = repo.createReference(
|
||||
name: 'refs/tags/test',
|
||||
target: repo[lastCommit],
|
||||
);
|
||||
expect(repo.references, contains('refs/tags/test'));
|
||||
expect(repo.references, contains('refs/tags/v0.1'));
|
||||
|
||||
repo.deleteReference('refs/tags/test');
|
||||
expect(repo.references, isNot(contains('refs/tags/test')));
|
||||
ref.free();
|
||||
repo.deleteReference('refs/tags/v0.1');
|
||||
expect(repo.references, isNot(contains('refs/tags/v0.1')));
|
||||
});
|
||||
|
||||
group('finds', () {
|
||||
|
@ -314,7 +374,13 @@ void main() {
|
|||
test('throws when error occured', () {
|
||||
expect(
|
||||
() => repo.lookupReference('refs/heads/not/there'),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"reference 'refs/heads/not/there' not found",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
@ -368,11 +434,35 @@ void main() {
|
|||
final ref = repo.lookupReference('HEAD');
|
||||
expect(
|
||||
() => ref.setTarget(target: 'refs/heads/invalid~'),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"the given reference name 'refs/heads/invalid~' is not valid",
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(
|
||||
() => ref.setTarget(target: Oid(nullptr)),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"invalid argument: 'id'",
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(
|
||||
() => ref.setTarget(target: 0),
|
||||
throwsA(isA<ArgumentError>()),
|
||||
throwsA(
|
||||
isA<ArgumentError>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
'Invalid argument: "0 must be either Oid or String reference name"',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
ref.free();
|
||||
|
@ -497,6 +587,19 @@ void main() {
|
|||
ref.free();
|
||||
});
|
||||
|
||||
test('throws when trying to peel and error occurs', () {
|
||||
expect(
|
||||
() => Reference(nullptr).peel(),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"invalid argument: 'ref'",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('successfully compresses references', () {
|
||||
final packedRefsFile = File('${tmpDir.path}/.git/packed-refs');
|
||||
expect(packedRefsFile.existsSync(), false);
|
||||
|
@ -509,6 +612,19 @@ void main() {
|
|||
expect(newRefs, oldRefs);
|
||||
});
|
||||
|
||||
test('throws when trying to compress and error occurs', () {
|
||||
expect(
|
||||
() => Reference.compress(Repository(nullptr)),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"invalid argument: 'repo'",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('returns string representation of Reference object', () {
|
||||
final ref = repo.lookupReference('refs/heads/master');
|
||||
expect(ref.toString(), contains('Reference{'));
|
||||
|
|
|
@ -93,5 +93,18 @@ void main() {
|
|||
branch.free();
|
||||
}
|
||||
});
|
||||
|
||||
test('throws when trying to prune remote refs and error occurs', () {
|
||||
expect(
|
||||
() => remote.prune(),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"this remote has never connected",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -68,6 +68,24 @@ void main() {
|
|||
remote.free();
|
||||
});
|
||||
|
||||
test('throws when trying to create with fetchspec with invalid remote name',
|
||||
() {
|
||||
expect(
|
||||
() => repo.createRemote(
|
||||
name: '',
|
||||
url: '',
|
||||
fetch: '',
|
||||
),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"'' is not a valid remote name.",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('successfully deletes', () {
|
||||
final remote = repo.createRemote(name: 'upstream', url: remoteUrl);
|
||||
expect(repo.remotes.length, 2);
|
||||
|
@ -78,6 +96,19 @@ void main() {
|
|||
remote.free();
|
||||
});
|
||||
|
||||
test('throws when trying to delete non existing remote', () {
|
||||
expect(
|
||||
() => repo.deleteRemote('not/there'),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"remote 'not/there' does not exist",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('successfully renames', () {
|
||||
final remote = repo.lookupRemote(remoteName);
|
||||
|
||||
|
@ -92,10 +123,31 @@ void main() {
|
|||
remote.free();
|
||||
});
|
||||
|
||||
test('returns list of non-default refspecs that cannot be renamed', () {
|
||||
final remote = repo.createRemote(
|
||||
name: 'upstream',
|
||||
url: remoteUrl,
|
||||
fetch: '+refs/*:refs/*',
|
||||
);
|
||||
|
||||
expect(
|
||||
repo.renameRemote(oldName: remote.name, newName: 'renamed'),
|
||||
['+refs/*:refs/*'],
|
||||
);
|
||||
|
||||
remote.free();
|
||||
});
|
||||
|
||||
test('throws when renaming with invalid names', () {
|
||||
expect(
|
||||
() => repo.renameRemote(oldName: '', newName: ''),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"'' is not a valid remote name.",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -165,6 +217,36 @@ void main() {
|
|||
remote.free();
|
||||
});
|
||||
|
||||
test('throws when trying to transform refspec with invalid reference name',
|
||||
() {
|
||||
final remote = repo.lookupRemote('origin');
|
||||
final refspec = remote.getRefspec(0);
|
||||
|
||||
expect(
|
||||
() => refspec.transform('invalid/name'),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"ref 'invalid/name' doesn't match the source",
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(
|
||||
() => refspec.rTransform('invalid/name'),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"ref 'invalid/name' doesn't match the destination",
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
remote.free();
|
||||
});
|
||||
|
||||
test('successfully adds fetch refspec', () {
|
||||
Remote.addFetch(
|
||||
repo: repo,
|
||||
|
@ -184,6 +266,23 @@ void main() {
|
|||
remote.free();
|
||||
});
|
||||
|
||||
test('throws when trying to add fetch refspec for invalid remote name', () {
|
||||
expect(
|
||||
() => Remote.addFetch(
|
||||
repo: repo,
|
||||
remote: '',
|
||||
refspec: '',
|
||||
),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"'' is not a valid remote name.",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('successfully adds push refspec', () {
|
||||
Remote.addPush(
|
||||
repo: repo,
|
||||
|
@ -197,6 +296,23 @@ void main() {
|
|||
remote.free();
|
||||
});
|
||||
|
||||
test('throws when trying to add push refspec for invalid remote name', () {
|
||||
expect(
|
||||
() => Remote.addPush(
|
||||
repo: repo,
|
||||
remote: '',
|
||||
refspec: '',
|
||||
),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"'' is not a valid remote name.",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('successfully returns remote repo\'s reference list', () {
|
||||
Remote.setUrl(
|
||||
repo: repo,
|
||||
|
@ -218,15 +334,42 @@ void main() {
|
|||
remote.free();
|
||||
});
|
||||
|
||||
test(
|
||||
'throws when trying to get remote repo\'s reference list with invalid url',
|
||||
() {
|
||||
Remote.setUrl(repo: repo, remote: 'libgit2', url: 'invalid');
|
||||
final remote = repo.lookupRemote('libgit2');
|
||||
|
||||
expect(
|
||||
() => remote.ls(),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"unsupported URL protocol",
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
remote.free();
|
||||
});
|
||||
|
||||
test('successfully fetches data', () {
|
||||
Remote.setUrl(
|
||||
repo: repo,
|
||||
remote: 'libgit2',
|
||||
url: 'https://github.com/libgit2/TestGitRepository',
|
||||
);
|
||||
Remote.addFetch(
|
||||
repo: repo,
|
||||
remote: 'libgit2',
|
||||
refspec: '+refs/heads/*:refs/remotes/origin/*',
|
||||
);
|
||||
final remote = repo.lookupRemote('libgit2');
|
||||
|
||||
final stats = remote.fetch();
|
||||
final stats = remote.fetch(
|
||||
refspecs: ['+refs/heads/*:refs/remotes/origin/*'],
|
||||
);
|
||||
|
||||
expect(stats.totalObjects, 69);
|
||||
expect(stats.indexedObjects, 69);
|
||||
|
@ -240,6 +383,84 @@ void main() {
|
|||
remote.free();
|
||||
});
|
||||
|
||||
test('successfully fetches data with proxy set to auto', () {
|
||||
Remote.setUrl(
|
||||
repo: repo,
|
||||
remote: 'libgit2',
|
||||
url: 'https://github.com/libgit2/TestGitRepository',
|
||||
);
|
||||
Remote.addFetch(
|
||||
repo: repo,
|
||||
remote: 'libgit2',
|
||||
refspec: '+refs/heads/*:refs/remotes/origin/*',
|
||||
);
|
||||
final remote = repo.lookupRemote('libgit2');
|
||||
|
||||
final stats = remote.fetch(
|
||||
refspecs: ['+refs/heads/*:refs/remotes/origin/*'],
|
||||
proxy: 'auto',
|
||||
);
|
||||
|
||||
expect(stats.totalObjects, 69);
|
||||
expect(stats.indexedObjects, 69);
|
||||
expect(stats.receivedObjects, 69);
|
||||
expect(stats.localObjects, 0);
|
||||
expect(stats.totalDeltas, 3);
|
||||
expect(stats.indexedDeltas, 3);
|
||||
expect(stats.receivedBytes, 0);
|
||||
expect(stats.toString(), contains('TransferProgress{'));
|
||||
|
||||
remote.free();
|
||||
});
|
||||
|
||||
test('uses specified proxy for fetch', () {
|
||||
Remote.setUrl(
|
||||
repo: repo,
|
||||
remote: 'libgit2',
|
||||
url: 'https://github.com/libgit2/TestGitRepository',
|
||||
);
|
||||
Remote.addFetch(
|
||||
repo: repo,
|
||||
remote: 'libgit2',
|
||||
refspec: '+refs/heads/*:refs/remotes/origin/*',
|
||||
);
|
||||
final remote = repo.lookupRemote('libgit2');
|
||||
|
||||
expect(
|
||||
() => remote.fetch(
|
||||
refspecs: ['+refs/heads/*:refs/remotes/origin/*'],
|
||||
proxy: 'https://1.1.1.1',
|
||||
),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"proxy returned unexpected status: 400",
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
remote.free();
|
||||
});
|
||||
|
||||
test('throws when trying to fetch data with invalid url', () {
|
||||
Remote.setUrl(repo: repo, remote: 'libgit2', url: 'https://wrong.url');
|
||||
final remote = repo.lookupRemote('libgit2');
|
||||
|
||||
expect(
|
||||
() => remote.fetch(),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"failed to resolve address for wrong.url: Name or service not known",
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
remote.free();
|
||||
});
|
||||
|
||||
test('successfully fetches data with provided transfer progress callback',
|
||||
() {
|
||||
Remote.setUrl(
|
||||
|
@ -300,20 +521,20 @@ Total 69 (delta 0), reused 1 (delta 0), pack-reused 68
|
|||
url: 'https://github.com/libgit2/TestGitRepository',
|
||||
);
|
||||
final remote = repo.lookupRemote('libgit2');
|
||||
const tipsExpected = [
|
||||
final tipsExpected = [
|
||||
{
|
||||
'refname': 'refs/tags/annotated_tag',
|
||||
'oldSha': '0000000000000000000000000000000000000000',
|
||||
'oldSha': '0' * 40,
|
||||
'newSha': 'd96c4e80345534eccee5ac7b07fc7603b56124cb',
|
||||
},
|
||||
{
|
||||
'refname': 'refs/tags/blob',
|
||||
'oldSha': '0000000000000000000000000000000000000000',
|
||||
'oldSha': '0' * 40,
|
||||
'newSha': '55a1a760df4b86a02094a904dfa511deb5655905'
|
||||
},
|
||||
{
|
||||
'refname': 'refs/tags/commit_tree',
|
||||
'oldSha': '0000000000000000000000000000000000000000',
|
||||
'oldSha': '0' * 40,
|
||||
'newSha': '8f50ba15d49353813cc6e20298002c0d17b0a9ee',
|
||||
},
|
||||
];
|
||||
|
@ -370,5 +591,23 @@ Total 69 (delta 0), reused 1 (delta 0), pack-reused 68
|
|||
originRepo.free();
|
||||
originDir.delete(recursive: true);
|
||||
});
|
||||
|
||||
test('throws when trying to push to invalid url', () {
|
||||
Remote.setUrl(repo: repo, remote: 'libgit2', url: 'https://wrong.url');
|
||||
final remote = repo.lookupRemote('libgit2');
|
||||
|
||||
expect(
|
||||
() => remote.push(refspecs: ['refs/heads/master']),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"failed to resolve address for wrong.url: Name or service not known",
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
remote.free();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import 'dart:ffi';
|
||||
import 'dart:io';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:libgit2dart/libgit2dart.dart';
|
||||
|
@ -80,6 +81,19 @@ void main() {
|
|||
expect(repo.isEmpty, true);
|
||||
});
|
||||
|
||||
test('throws when checking if it is empty and error occurs', () {
|
||||
expect(
|
||||
() => Repository(nullptr).isEmpty,
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"invalid argument: 'repo'",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('checks if head is detached', () {
|
||||
expect(repo.isHeadDetached, false);
|
||||
});
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import 'dart:ffi';
|
||||
import 'dart:io';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:libgit2dart/libgit2dart.dart';
|
||||
|
@ -93,6 +94,58 @@ void main() {
|
|||
tmpWorkDir.deleteSync();
|
||||
});
|
||||
|
||||
test('throws when trying to set working directory to invalid', () {
|
||||
expect(
|
||||
() => repo.setWorkdir(path: 'invalid/path'),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"failed to resolve path 'invalid/path': No such file or directory",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('throws when trying to get head and error occurs', () {
|
||||
File('${repo.workdir}.git/HEAD').deleteSync();
|
||||
expect(
|
||||
() => repo.head,
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"reference 'HEAD' not found",
|
||||
),
|
||||
),
|
||||
);
|
||||
expect(
|
||||
() => repo.isHeadDetached,
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"reference 'HEAD' not found",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('throws when trying to check if branch is unborn and error occurs',
|
||||
() {
|
||||
File('${repo.workdir}.git/HEAD').deleteSync();
|
||||
expect(
|
||||
() => repo.isBranchUnborn,
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"reference 'HEAD' not found",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
group('setHead', () {
|
||||
late Reference head;
|
||||
|
||||
|
@ -122,7 +175,39 @@ void main() {
|
|||
});
|
||||
|
||||
test('throws when target is invalid', () {
|
||||
expect(() => repo.setHead(0), throwsA(isA<ArgumentError>()));
|
||||
expect(
|
||||
() => repo.setHead(0),
|
||||
throwsA(
|
||||
isA<ArgumentError>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
'Invalid argument: "0 must be either Oid or String reference name"',
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('throws when error occurs', () {
|
||||
expect(
|
||||
() => Repository(nullptr).setHead('refs/heads/feature'),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"invalid argument: 'repo'",
|
||||
),
|
||||
),
|
||||
);
|
||||
expect(
|
||||
() => Repository(nullptr).setHead(repo['0' * 40]),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"invalid argument: 'repo'",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -209,6 +294,23 @@ void main() {
|
|||
index.free();
|
||||
});
|
||||
|
||||
test('throws when trying to get status of bare repository', () {
|
||||
final bare = Repository.open('test/assets/empty_bare.git');
|
||||
|
||||
expect(
|
||||
() => bare.status,
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"cannot status. This operation is not allowed against bare repositories.",
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
bare.free();
|
||||
});
|
||||
|
||||
test('cleans up state', () {
|
||||
expect(repo.state, GitRepositoryState.none);
|
||||
final commit = repo.lookupCommit(repo['5aecfa0']);
|
||||
|
@ -221,6 +323,19 @@ void main() {
|
|||
commit.free();
|
||||
});
|
||||
|
||||
test('throws when trying to clean up state and error occurs', () {
|
||||
expect(
|
||||
() => Repository(nullptr).stateCleanup(),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"invalid argument: 'repo'",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('returns status of a single file for provided path', () {
|
||||
final index = repo.index;
|
||||
index.remove('file');
|
||||
|
@ -236,7 +351,13 @@ void main() {
|
|||
test('throws when checking status of a single file for invalid path', () {
|
||||
expect(
|
||||
() => repo.statusFile('not-there'),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"attempt to get status of nonexistent file 'not-there'",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -269,24 +390,38 @@ void main() {
|
|||
});
|
||||
|
||||
test('checks if commit is a descendant of another commit', () {
|
||||
final commit1 = repo.lookupCommit(repo['821ed6e8']);
|
||||
final commit2 = repo.lookupCommit(repo['78b8bf12']);
|
||||
final commit1 = repo['821ed6e8'];
|
||||
final commit2 = repo['78b8bf12'];
|
||||
|
||||
expect(
|
||||
repo.descendantOf(commit: commit1.oid, ancestor: commit2.oid),
|
||||
repo.descendantOf(commit: commit1, ancestor: commit2),
|
||||
true,
|
||||
);
|
||||
expect(
|
||||
repo.descendantOf(commit: commit1.oid, ancestor: commit1.oid),
|
||||
repo.descendantOf(commit: commit1, ancestor: commit1),
|
||||
false,
|
||||
);
|
||||
expect(
|
||||
repo.descendantOf(commit: commit2.oid, ancestor: commit1.oid),
|
||||
repo.descendantOf(commit: commit2, ancestor: commit1),
|
||||
false,
|
||||
);
|
||||
});
|
||||
|
||||
commit1.free();
|
||||
commit2.free();
|
||||
test('throws when trying to check if commit is descendant and error occurs',
|
||||
() {
|
||||
final commit1 = repo['821ed6e8'];
|
||||
final commit2 = repo['78b8bf12'];
|
||||
final nullRepo = Repository(nullptr);
|
||||
expect(
|
||||
() => nullRepo.descendantOf(commit: commit1, ancestor: commit2),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"invalid argument: 'repo'",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('returns number of ahead behind commits', () {
|
||||
|
|
|
@ -35,6 +35,29 @@ void main() {
|
|||
initCommit.free();
|
||||
});
|
||||
|
||||
test('.single() throws when spec string not found or invalid', () {
|
||||
expect(
|
||||
() => repo.revParseSingle('invalid'),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"revspec 'invalid' not found",
|
||||
),
|
||||
),
|
||||
);
|
||||
expect(
|
||||
() => repo.revParseSingle(''),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"failed to parse revision specifier - Invalid pattern ''",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('.ext() returns commit and reference', () {
|
||||
final masterRef = repo.lookupReference('refs/heads/master');
|
||||
var headParse = repo.revParseExt('master');
|
||||
|
@ -70,6 +93,29 @@ void main() {
|
|||
headParse.object.free();
|
||||
});
|
||||
|
||||
test('.ext() throws when spec string not found or invalid', () {
|
||||
expect(
|
||||
() => repo.revParseExt('invalid'),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"revspec 'invalid' not found",
|
||||
),
|
||||
),
|
||||
);
|
||||
expect(
|
||||
() => repo.revParseExt(''),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"failed to parse revision specifier - Invalid pattern ''",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test(
|
||||
'.range returns revspec with correct fields values based on provided spec',
|
||||
() {
|
||||
|
@ -108,12 +154,23 @@ void main() {
|
|||
test('throws on invalid range spec', () {
|
||||
expect(
|
||||
() => repo.revParse('invalid..5aecfa'),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"revspec 'invalid' not found",
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(
|
||||
() => repo.revParse('master........5aecfa'),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"failed to parse revision specifier - Invalid pattern '.....5aecfa'",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import 'dart:ffi';
|
||||
import 'dart:io';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:libgit2dart/libgit2dart.dart';
|
||||
|
@ -25,6 +26,25 @@ void main() {
|
|||
});
|
||||
|
||||
group('RevWalk', () {
|
||||
test('successfully initializes', () {
|
||||
final walker = RevWalk(repo);
|
||||
expect(walker, isA<RevWalk>());
|
||||
walker.free();
|
||||
});
|
||||
|
||||
test('throws when trying to initialize and error occurs', () {
|
||||
expect(
|
||||
() => RevWalk(Repository(nullptr)),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"invalid argument: 'repo'",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('returns list of commits with default sorting', () {
|
||||
final walker = RevWalk(repo);
|
||||
final start = Oid.fromSHA(repo: repo, sha: log.first);
|
||||
|
@ -88,11 +108,9 @@ void main() {
|
|||
|
||||
test('successfully hides commit and its ancestors', () {
|
||||
final walker = RevWalk(repo);
|
||||
final start = Oid.fromSHA(repo: repo, sha: log.first);
|
||||
final oidToHide = Oid.fromSHA(repo: repo, sha: log[2]);
|
||||
|
||||
walker.push(start);
|
||||
walker.hide(oidToHide);
|
||||
walker.push(repo[log.first]);
|
||||
walker.hide(repo[log[2]]);
|
||||
final commits = walker.walk();
|
||||
|
||||
expect(commits.length, 2);
|
||||
|
@ -103,6 +121,23 @@ void main() {
|
|||
walker.free();
|
||||
});
|
||||
|
||||
test('throws when trying to hide commit oid and error occurs', () {
|
||||
final walker = RevWalk(repo);
|
||||
|
||||
expect(
|
||||
() => walker.hide(repo['0' * 40]),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"odb: cannot read object: null OID cannot exist",
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
walker.free();
|
||||
});
|
||||
|
||||
test('successfully resets walker', () {
|
||||
final walker = RevWalk(repo);
|
||||
final start = Oid.fromSHA(repo: repo, sha: log.first);
|
||||
|
@ -134,5 +169,23 @@ void main() {
|
|||
}
|
||||
walker.free();
|
||||
});
|
||||
|
||||
test('throws when trying to add new root for traversal and error occurs',
|
||||
() {
|
||||
final walker = RevWalk(repo);
|
||||
|
||||
expect(
|
||||
() => walker.push(repo['0' * 40]),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"odb: cannot read object: null OID cannot exist",
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
walker.free();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -25,6 +25,34 @@ void main() {
|
|||
expect(signature, isA<Signature>());
|
||||
});
|
||||
|
||||
test('throws when trying to create with empty name and email', () {
|
||||
expect(
|
||||
() => Signature.create(name: '', email: '', time: 0),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"failed to parse signature - Signature cannot have an empty name or email",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test(
|
||||
'throws when trying to create with empty name and email and default time',
|
||||
() {
|
||||
expect(
|
||||
() => Signature.create(name: '', email: ''),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"failed to parse signature - Signature cannot have an empty name or email",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('successfully creates without provided time and offset', () {
|
||||
final sig = Signature.create(name: 'Name', email: 'email@example.com');
|
||||
expect(sig, isA<Signature>());
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import 'dart:ffi';
|
||||
import 'dart:io';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:libgit2dart/libgit2dart.dart';
|
||||
|
@ -34,6 +35,19 @@ void main() {
|
|||
expect(repo.status.isEmpty, true);
|
||||
});
|
||||
|
||||
test('throws when trying to save and error occurs', () {
|
||||
expect(
|
||||
() => Repository(nullptr).createStash(stasher: stasher),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"invalid argument: 'repo'",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('successfully saves changes to stash including ignored', () {
|
||||
final swpPath = File('${tmpDir.path}/some.swp');
|
||||
swpPath.writeAsStringSync('ignored');
|
||||
|
@ -78,6 +92,19 @@ void main() {
|
|||
expect(repo.status, contains('file'));
|
||||
});
|
||||
|
||||
test('successfully applies changes from stash with paths provided', () {
|
||||
File('${tmpDir.path}/file').writeAsStringSync(
|
||||
'edit',
|
||||
mode: FileMode.append,
|
||||
);
|
||||
|
||||
repo.createStash(stasher: stasher);
|
||||
expect(repo.status.isEmpty, true);
|
||||
|
||||
repo.applyStash(paths: ['file']);
|
||||
expect(repo.status, contains('file'));
|
||||
});
|
||||
|
||||
test('successfully applies changes from stash including index changes', () {
|
||||
File('${tmpDir.path}/stash.this').writeAsStringSync('stash');
|
||||
final index = repo.index;
|
||||
|
@ -95,6 +122,26 @@ void main() {
|
|||
index.free();
|
||||
});
|
||||
|
||||
test('throws when trying to apply with wrong index', () {
|
||||
File('${tmpDir.path}/file').writeAsStringSync(
|
||||
'edit',
|
||||
mode: FileMode.append,
|
||||
);
|
||||
|
||||
repo.createStash(stasher: stasher);
|
||||
|
||||
expect(
|
||||
() => repo.applyStash(index: 10),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"no stashed state at position 10",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('successfully drops stash', () {
|
||||
File('${tmpDir.path}/file').writeAsStringSync(
|
||||
'edit',
|
||||
|
@ -103,10 +150,30 @@ void main() {
|
|||
|
||||
repo.createStash(stasher: stasher);
|
||||
final stash = repo.stashes.first;
|
||||
repo.dropStash(stash.index);
|
||||
repo.dropStash(index: stash.index);
|
||||
expect(() => repo.applyStash(), throwsA(isA<LibGit2Error>()));
|
||||
});
|
||||
|
||||
test('throws when trying to drop with wrong index', () {
|
||||
File('${tmpDir.path}/file').writeAsStringSync(
|
||||
'edit',
|
||||
mode: FileMode.append,
|
||||
);
|
||||
|
||||
repo.createStash(stasher: stasher);
|
||||
|
||||
expect(
|
||||
() => repo.dropStash(index: 10),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"no stashed state at position 10",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('successfully pops from stash', () {
|
||||
File('${tmpDir.path}/file').writeAsStringSync(
|
||||
'edit',
|
||||
|
@ -119,6 +186,18 @@ void main() {
|
|||
expect(() => repo.applyStash(), throwsA(isA<LibGit2Error>()));
|
||||
});
|
||||
|
||||
test('successfully pops from stash with provided path', () {
|
||||
File('${tmpDir.path}/file').writeAsStringSync(
|
||||
'edit',
|
||||
mode: FileMode.append,
|
||||
);
|
||||
|
||||
repo.createStash(stasher: stasher);
|
||||
repo.popStash(paths: ['file']);
|
||||
expect(repo.status, contains('file'));
|
||||
expect(() => repo.applyStash(), throwsA(isA<LibGit2Error>()));
|
||||
});
|
||||
|
||||
test('successfully pops from stash including index changes', () {
|
||||
File('${tmpDir.path}/stash.this').writeAsStringSync('stash');
|
||||
final index = repo.index;
|
||||
|
@ -136,6 +215,26 @@ void main() {
|
|||
index.free();
|
||||
});
|
||||
|
||||
test('throws when trying to pop with wrong index', () {
|
||||
File('${tmpDir.path}/file').writeAsStringSync(
|
||||
'edit',
|
||||
mode: FileMode.append,
|
||||
);
|
||||
|
||||
repo.createStash(stasher: stasher);
|
||||
|
||||
expect(
|
||||
() => repo.popStash(index: 10),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"no stashed state at position 10",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('returns list of stashes', () {
|
||||
File('${tmpDir.path}/file').writeAsStringSync(
|
||||
'edit',
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import 'dart:ffi';
|
||||
import 'dart:io';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:libgit2dart/libgit2dart.dart';
|
||||
|
@ -43,6 +44,19 @@ void main() {
|
|||
submodule.free();
|
||||
});
|
||||
|
||||
test('throws when trying to lookup and submodule not found', () {
|
||||
expect(
|
||||
() => repo.lookupSubmodule('not/there'),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"no submodule named 'not/there'",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('successfully inits and updates', () {
|
||||
final submoduleFilePath = '${repo.workdir}$testSubmodule/master.txt';
|
||||
expect(File(submoduleFilePath).existsSync(), false);
|
||||
|
@ -62,6 +76,19 @@ void main() {
|
|||
expect(File(submoduleFilePath).existsSync(), true);
|
||||
});
|
||||
|
||||
test('throws when trying to update not initialized submodule', () {
|
||||
expect(
|
||||
() => repo.updateSubmodule(submodule: testSubmodule),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"submodule is not initialized",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('successfully opens repository for a submodule', () {
|
||||
final submodule = repo.lookupSubmodule(testSubmodule);
|
||||
repo.initSubmodule(submodule: testSubmodule);
|
||||
|
@ -81,6 +108,24 @@ void main() {
|
|||
submodule.free();
|
||||
});
|
||||
|
||||
test('throws when trying to open repository for not initialized submodule',
|
||||
() {
|
||||
final submodule = repo.lookupSubmodule(testSubmodule);
|
||||
|
||||
expect(
|
||||
() => submodule.open(),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
contains("failed to resolve path"),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
submodule.free();
|
||||
});
|
||||
|
||||
test('successfully adds submodule', () {
|
||||
final submodule = repo.addSubmodule(
|
||||
url: submoduleUrl,
|
||||
|
@ -96,6 +141,38 @@ void main() {
|
|||
submodule.free();
|
||||
});
|
||||
|
||||
test('throws when trying to add submodule with wrong url', () {
|
||||
expect(
|
||||
() => repo.addSubmodule(
|
||||
url: 'https://wrong.url/',
|
||||
path: 'test',
|
||||
),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
'failed to resolve address for wrong.url: Name or service not known',
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('throws when trying to add submodule and error occurs', () {
|
||||
expect(
|
||||
() => Repository(nullptr).addSubmodule(
|
||||
url: 'https://wrong.url/',
|
||||
path: 'test',
|
||||
),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"invalid argument: 'repo'",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('successfully sets configuration values', () {
|
||||
final submodule = repo.lookupSubmodule(testSubmodule);
|
||||
expect(submodule.url, submoduleUrl);
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import 'dart:ffi';
|
||||
import 'dart:io';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:libgit2dart/libgit2dart.dart';
|
||||
|
@ -27,6 +28,32 @@ void main() {
|
|||
expect(tag, isA<Tag>());
|
||||
});
|
||||
|
||||
test('throws when trying to lookup tag for invalid oid', () {
|
||||
expect(
|
||||
() => repo.lookupTag(repo['0' * 40]),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"odb: cannot read object: null OID cannot exist",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('throws when trying to get target of a tag and error occurs', () {
|
||||
expect(
|
||||
() => Tag(nullptr).target,
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"invalid argument: 't'",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('returns correct values', () {
|
||||
final signature = Signature.create(
|
||||
name: 'Aleksey Kulikov',
|
||||
|
@ -179,15 +206,79 @@ void main() {
|
|||
signature.free();
|
||||
});
|
||||
|
||||
test('throws when trying to create tag with invalid name', () {
|
||||
expect(
|
||||
() => repo.createTag(
|
||||
tagName: '',
|
||||
target: repo['9c78c21'],
|
||||
targetType: GitObject.any,
|
||||
tagger: Signature(nullptr),
|
||||
message: '',
|
||||
),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"invalid argument: '!create_tag_annotation || (tagger && message)'",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('throws when trying to create tag with invalid target', () {
|
||||
expect(
|
||||
() => repo.createTag(
|
||||
tagName: '',
|
||||
target: repo['0' * 40],
|
||||
targetType: GitObject.any,
|
||||
tagger: Signature(nullptr),
|
||||
message: '',
|
||||
),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"odb: cannot read object: null OID cannot exist",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('returns list of tags in repository', () {
|
||||
expect(Tag.list(repo), ['v0.1', 'v0.2']);
|
||||
});
|
||||
|
||||
test('throws when trying to get list of tags and error occurs', () {
|
||||
expect(
|
||||
() => Repository(nullptr).tags,
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"invalid argument: 'repo'",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('successfully deletes tag', () {
|
||||
expect(repo.tags, ['v0.1', 'v0.2']);
|
||||
|
||||
repo.deleteTag('v0.2');
|
||||
expect(repo.tags, ['v0.1']);
|
||||
});
|
||||
|
||||
test('throws when trying to delete non existing tag', () {
|
||||
expect(
|
||||
() => repo.deleteTag('not.there'),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"reference 'refs/tags/not.there' not found",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -29,6 +29,19 @@ void main() {
|
|||
expect(tree.toString(), contains('Tree{'));
|
||||
});
|
||||
|
||||
test('throws when looking up tree for invalid oid', () {
|
||||
expect(
|
||||
() => repo.lookupTree(repo['0' * 40]),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"odb: cannot read object: null OID cannot exist",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('returns correct values', () {
|
||||
expect(tree.length, 4);
|
||||
expect(tree.entries.first.oid.sha, fileSHA);
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import 'dart:ffi';
|
||||
import 'dart:io';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:libgit2dart/libgit2dart.dart';
|
||||
|
@ -39,6 +40,19 @@ void main() {
|
|||
builder.free();
|
||||
});
|
||||
|
||||
test('throws when trying to initialize and error occurs', () {
|
||||
expect(
|
||||
() => TreeBuilder(repo: Repository(nullptr)),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"invalid argument: 'repo'",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('clears all the entries in the builder', () {
|
||||
final builder = TreeBuilder(repo: repo, tree: tree);
|
||||
|
||||
|
@ -65,6 +79,42 @@ void main() {
|
|||
builder.free();
|
||||
});
|
||||
|
||||
test('throws when trying to add entry with invalid name or invalid oid',
|
||||
() {
|
||||
final builder = TreeBuilder(repo: repo);
|
||||
|
||||
expect(
|
||||
() => builder.add(
|
||||
filename: '',
|
||||
oid: repo['0' * 40],
|
||||
filemode: GitFilemode.blob,
|
||||
),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"failed to insert entry: invalid name for a tree entry - ",
|
||||
),
|
||||
),
|
||||
);
|
||||
expect(
|
||||
() => builder.add(
|
||||
filename: 'some.file',
|
||||
oid: repo['0' * 40],
|
||||
filemode: GitFilemode.blob,
|
||||
),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"failed to insert entry: invalid null OID - some.file",
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
builder.free();
|
||||
});
|
||||
|
||||
test('successfully removes an entry', () {
|
||||
final builder = TreeBuilder(repo: repo, tree: tree);
|
||||
|
||||
|
@ -76,5 +126,22 @@ void main() {
|
|||
|
||||
builder.free();
|
||||
});
|
||||
|
||||
test('throws when trying to remove entry that is not in the tree', () {
|
||||
final builder = TreeBuilder(repo: repo);
|
||||
|
||||
expect(
|
||||
() => builder.remove('not.there'),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"failed to remove entry: file isn't in the tree - not.there",
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
builder.free();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import 'dart:ffi';
|
||||
import 'dart:io';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:libgit2dart/libgit2dart.dart';
|
||||
|
@ -85,6 +86,35 @@ void main() {
|
|||
worktree.free();
|
||||
});
|
||||
|
||||
test('throws when trying to create worktree with invalid name or path', () {
|
||||
expect(
|
||||
() => repo.createWorktree(
|
||||
name: '',
|
||||
path: worktreeDir.path,
|
||||
),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
contains('failed to make directory'),
|
||||
),
|
||||
),
|
||||
);
|
||||
expect(
|
||||
() => repo.createWorktree(
|
||||
name: 'name',
|
||||
path: '',
|
||||
),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
'attempt to create empty path: Invalid argument',
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('successfully lookups worktree', () {
|
||||
final worktree = repo.createWorktree(
|
||||
name: worktreeName,
|
||||
|
@ -100,6 +130,19 @@ void main() {
|
|||
worktree.free();
|
||||
});
|
||||
|
||||
test('throws when trying to lookup and error occurs', () {
|
||||
expect(
|
||||
() => Worktree.lookup(repo: Repository(nullptr), name: 'name'),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"invalid argument: 'repo'",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('successfully locks and unlocks worktree', () {
|
||||
final worktree = repo.createWorktree(
|
||||
name: worktreeName,
|
||||
|
@ -136,5 +179,18 @@ void main() {
|
|||
|
||||
worktree.free();
|
||||
});
|
||||
|
||||
test('throws when trying get list of worktrees and error occurs', () {
|
||||
expect(
|
||||
() => Worktree.list(Repository(nullptr)),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"invalid argument: 'repo'",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue