test: improve coverage

This commit is contained in:
Aleksey Kulikov 2021-10-15 17:37:38 +03:00
parent d75acbfdd3
commit d6eae1e9ed
71 changed files with 710 additions and 229 deletions

View file

@ -1 +1 @@
master conflict commit
delete their for conflict

Binary file not shown.

View file

@ -13,3 +13,14 @@ fc38877b2552ab554752d9a77e1f48f738cca79b 5aecfa0fb97eadaac050ccb99f03c3fb65460ad
821ed6e80627b8769d170a293862f9fc60825226 47af50e6a799d7d0dde6630d2644f9484fb670f7 Aleksey Kulikov <skinny.mind@gmail.com> 1631172155 +0300 commit: conflict branch commit
47af50e6a799d7d0dde6630d2644f9484fb670f7 821ed6e80627b8769d170a293862f9fc60825226 Aleksey Kulikov <skinny.mind@gmail.com> 1631172159 +0300 checkout: moving from conflict-branch to master
821ed6e80627b8769d170a293862f9fc60825226 14905459d775f3f56a39ebc2ff081163f7da3529 Aleksey Kulikov <skinny.mind@gmail.com> 1631172175 +0300 commit: master conflict commit
14905459d775f3f56a39ebc2ff081163f7da3529 5aecfa0fb97eadaac050ccb99f03c3fb65460ad4 Aleksey Kulikov <skinny.mind@gmail.com> 1634223805 +0300 checkout: moving from master to ancestor-conflict
5aecfa0fb97eadaac050ccb99f03c3fb65460ad4 7606a0d606a74ee5f0761c6e358c2f90405c94ad Aleksey Kulikov <skinny.mind@gmail.com> 1634223835 +0300 commit: conflict with ancestor
7606a0d606a74ee5f0761c6e358c2f90405c94ad 5aecfa0fb97eadaac050ccb99f03c3fb65460ad4 Aleksey Kulikov <skinny.mind@gmail.com> 1634223845 +0300 checkout: moving from ancestor-conflict to feature
5aecfa0fb97eadaac050ccb99f03c3fb65460ad4 2ee89b2f7124b8e4632bc6a20774a90b795245e4 Aleksey Kulikov <skinny.mind@gmail.com> 1634223881 +0300 commit: conflict with ancestor
2ee89b2f7124b8e4632bc6a20774a90b795245e4 14905459d775f3f56a39ebc2ff081163f7da3529 Aleksey Kulikov <skinny.mind@gmail.com> 1634225232 +0300 checkout: moving from feature to master
14905459d775f3f56a39ebc2ff081163f7da3529 2ee89b2f7124b8e4632bc6a20774a90b795245e4 Aleksey Kulikov <skinny.mind@gmail.com> 1634303915 +0300 checkout: moving from master to our-conflict
2ee89b2f7124b8e4632bc6a20774a90b795245e4 0db17b23a1acd67d5e44650d61aac7d4d83ec193 Aleksey Kulikov <skinny.mind@gmail.com> 1634303926 +0300 commit: delete our for conflict
0db17b23a1acd67d5e44650d61aac7d4d83ec193 14905459d775f3f56a39ebc2ff081163f7da3529 Aleksey Kulikov <skinny.mind@gmail.com> 1634303933 +0300 checkout: moving from our-conflict to master
14905459d775f3f56a39ebc2ff081163f7da3529 7606a0d606a74ee5f0761c6e358c2f90405c94ad Aleksey Kulikov <skinny.mind@gmail.com> 1634304003 +0300 checkout: moving from master to their-conflict
7606a0d606a74ee5f0761c6e358c2f90405c94ad 0e409d66f701eea5038fe508ead4c098da699d2c Aleksey Kulikov <skinny.mind@gmail.com> 1634304018 +0300 commit: delete their for conflict
0e409d66f701eea5038fe508ead4c098da699d2c 14905459d775f3f56a39ebc2ff081163f7da3529 Aleksey Kulikov <skinny.mind@gmail.com> 1634304023 +0300 checkout: moving from their-conflict to master

View file

@ -0,0 +1,2 @@
0000000000000000000000000000000000000000 5aecfa0fb97eadaac050ccb99f03c3fb65460ad4 Aleksey Kulikov <skinny.mind@gmail.com> 1634223805 +0300 branch: Created from 5aecfa0
5aecfa0fb97eadaac050ccb99f03c3fb65460ad4 7606a0d606a74ee5f0761c6e358c2f90405c94ad Aleksey Kulikov <skinny.mind@gmail.com> 1634223835 +0300 commit: conflict with ancestor

View file

@ -2,3 +2,4 @@
f17d0d48eae3aa08cecf29128a35e310c97b3521 6cbc22e509d72758ab4c8d9f287ea846b90c448b Aleksey Kulikov <skinny.mind@gmail.com> 1626091020 +0300 commit: add feature file
6cbc22e509d72758ab4c8d9f287ea846b90c448b fc38877b2552ab554752d9a77e1f48f738cca79b Aleksey Kulikov <skinny.mind@gmail.com> 1626091054 +0300 commit: edit feature file
fc38877b2552ab554752d9a77e1f48f738cca79b 5aecfa0fb97eadaac050ccb99f03c3fb65460ad4 Aleksey Kulikov <skinny.mind@gmail.com> 1626091274 +0300 commit: add another feature file
5aecfa0fb97eadaac050ccb99f03c3fb65460ad4 2ee89b2f7124b8e4632bc6a20774a90b795245e4 Aleksey Kulikov <skinny.mind@gmail.com> 1634223881 +0300 commit: conflict with ancestor

View file

@ -0,0 +1,2 @@
0000000000000000000000000000000000000000 2ee89b2f7124b8e4632bc6a20774a90b795245e4 Aleksey Kulikov <skinny.mind@gmail.com> 1634303915 +0300 branch: Created from 2ee89b2
2ee89b2f7124b8e4632bc6a20774a90b795245e4 0db17b23a1acd67d5e44650d61aac7d4d83ec193 Aleksey Kulikov <skinny.mind@gmail.com> 1634303926 +0300 commit: delete our for conflict

View file

@ -0,0 +1,2 @@
0000000000000000000000000000000000000000 7606a0d606a74ee5f0761c6e358c2f90405c94ad Aleksey Kulikov <skinny.mind@gmail.com> 1634304003 +0300 branch: Created from 7606a0d
7606a0d606a74ee5f0761c6e358c2f90405c94ad 0e409d66f701eea5038fe508ead4c098da699d2c Aleksey Kulikov <skinny.mind@gmail.com> 1634304018 +0300 commit: delete their for conflict

View file

@ -0,0 +1,2 @@
xĄŽKj1łÖ)z0úKĆ$ëśBęî‰ĹčcĆrŔ·Ďř ŢÔâA=
GkevúcîĚ@¬˛ÖŮť<>Í6ć@hbÎʸÄZ¦Ś~!˘(niç>!x铤<17>ev« ^ˇgă"ęuV:\l"ó:vř®ĽÝů ?ŹZ¶ńçűVzžZéôőŰR©'íĘk[Eř”FJq¬Gčä7.qĺÉ0Ż\vXŹ}­§ř˛

View file

@ -0,0 +1 @@
7606a0d606a74ee5f0761c6e358c2f90405c94ad

View file

@ -1 +1 @@
5aecfa0fb97eadaac050ccb99f03c3fb65460ad4
2ee89b2f7124b8e4632bc6a20774a90b795245e4

View file

@ -0,0 +1 @@
0db17b23a1acd67d5e44650d61aac7d4d83ec193

View file

@ -0,0 +1 @@
0e409d66f701eea5038fe508ead4c098da699d2c

View file

@ -142,5 +142,11 @@ void main() {
blame.free();
});
test('returns string representation of BlameHunk object', () {
final blame = repo.blame(path: 'feature_file');
expect(blame.toString(), contains('BlameHunk{'));
blame.free();
});
});
}

View file

@ -63,7 +63,13 @@ void main() {
test('throws when creating new blob from invalid path', () {
expect(
() => repo.createBlobFromWorkdir('invalid/path.txt'),
throwsA(isA<LibGit2Error>()),
throwsA(
isA<LibGit2Error>().having(
(e) => e.toString(),
'message',
"could not find '${repo.workdir}invalid/path.txt' to stat: No such file or directory",
),
),
);
});
@ -128,10 +134,10 @@ index e69de29..0000000
});
test('successfully creates from one blob (delete)', () {
final a = repo.lookupBlob(
final _blob = repo.lookupBlob(
repo['e69de29bb2d1d6434b8b29ae775ad8c2e48c5391'],
);
final patch = a.diff(
final patch = _blob.diff(
newBlob: null,
oldAsPath: path,
newAsPath: path,
@ -143,16 +149,14 @@ index e69de29..0000000
});
test('successfully creates from blob and buffer', () {
final a = repo.lookupBlob(
final _blob = repo.lookupBlob(
repo['e69de29bb2d1d6434b8b29ae775ad8c2e48c5391'],
);
final patch = Patch.create(
a: a,
b: 'Feature edit\n',
aPath: path,
bPath: path,
);
final patch = _blob.diffToBuffer(
buffer: 'Feature edit\n',
oldAsPath: path,
);
expect(patch.text, blobPatch);
patch.free();
@ -174,5 +178,9 @@ index e69de29..0000000
patch.free();
});
});
test('returns string representation of Blob object', () {
expect(blob.toString(), contains('Blob{'));
});
});
}

View file

@ -186,5 +186,11 @@ void main() {
);
});
});
test('returns string representation of Branch object', () {
final branch = repo.lookupBranch('master');
expect(branch.toString(), contains('Branch{'));
branch.free();
});
});
}

View file

@ -147,5 +147,11 @@ void main() {
parent2.free();
commit.free();
});
test('returns string representation of Commit object', () {
final commit = repo.lookupCommit(mergeCommit);
expect(commit.toString(), contains('Commit{'));
commit.free();
});
});
}

View file

@ -23,6 +23,7 @@ void main() {
expect(credentials, isA<Credentials>());
expect(credentials.username, 'user');
expect(credentials.credentialType, GitCredential.username);
expect(credentials.toString(), contains('Username{'));
});
test('successfully initializes username/password credentials', () {
@ -35,6 +36,7 @@ void main() {
expect(credentials.username, 'user');
expect(credentials.password, 'password');
expect(credentials.credentialType, GitCredential.userPassPlainText);
expect(credentials.toString(), contains('UserPass{'));
});
test('successfully initializes keypair credentials', () {
@ -51,6 +53,7 @@ void main() {
expect(credentials.privateKey, 'id_rsa');
expect(credentials.passPhrase, 'passphrase');
expect(credentials.credentialType, GitCredential.sshKey);
expect(credentials.toString(), contains('Keypair{'));
});
test('successfully initializes keypair from memory credentials', () {
@ -67,6 +70,7 @@ void main() {
expect(credentials.privateKey, 'private key data');
expect(credentials.passPhrase, 'passphrase');
expect(credentials.credentialType, GitCredential.sshMemory);
expect(credentials.toString(), contains('KeypairFromMemory{'));
});
test('successfully initializes keypair from agent credentials', () {
@ -75,6 +79,7 @@ void main() {
expect(credentials, isA<Credentials>());
expect(credentials.username, 'user');
expect(credentials.credentialType, GitCredential.sshKey);
expect(credentials.toString(), contains('KeypairFromAgent{'));
});
test('sucessfully clones repository with provided keypair', () {

View file

@ -131,5 +131,14 @@ void main() {
index.free();
});
test('successfully describes with max candidates tags flag set', () {
final index = repo.index;
index.clear();
expect(repo.describe(maxCandidatesTags: 0), 'v0.2');
index.free();
});
});
}

View file

@ -103,17 +103,24 @@ index e69de29..c217c63 100644
final head = repo.head;
final commit = repo.lookupCommit(head.target);
final tree = commit.tree;
final diff = index.diffToTree(tree: tree);
final diff1 = index.diffToTree(tree: tree);
final diff2 = tree.diffToIndex(index: index);
expect(diff.length, 8);
for (var i = 0; i < diff.deltas.length; i++) {
expect(diff.deltas[i].newFile.path, indexToTree[i]);
expect(diff1.length, 8);
for (var i = 0; i < diff1.deltas.length; i++) {
expect(diff1.deltas[i].newFile.path, indexToTree[i]);
}
expect(diff2.length, 8);
for (var i = 0; i < diff2.deltas.length; i++) {
expect(diff2.deltas[i].newFile.path, indexToTree[i]);
}
commit.free();
head.free();
tree.free();
diff.free();
diff1.free();
diff2.free();
index.free();
});
@ -157,9 +164,7 @@ index e69de29..c217c63 100644
final head = repo.head;
final commit = repo.lookupCommit(head.target);
final tree1 = commit.tree;
final tree2 = repo.lookupTree(
repo['b85d53c9236e89aff2b62558adaa885fd1d6ff1c'],
);
final tree2 = repo.lookupTree(repo['b85d53c']);
final diff = repo.diff(a: tree1, b: tree2);
expect(diff.length, 10);
@ -174,6 +179,12 @@ index e69de29..c217c63 100644
diff.free();
});
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>()));
tree.free();
});
test('successfully merges diffs', () {
final head = repo.head;
final commit = repo.lookupCommit(head.target);
@ -377,5 +388,24 @@ index e69de29..c217c63 100644
patch.free();
diff.free();
});
test(
'returns string representation of Diff, DiffDelta, DiffFile, '
'DiffHunk, DiffLine and DiffStats objects', () {
final diff = Diff.parse(patchText);
final patch = Patch.fromDiff(diff: diff, index: 0);
final stats = diff.stats;
expect(diff.toString(), contains('Diff{'));
expect(patch.delta.toString(), contains('DiffDelta{'));
expect(patch.delta.oldFile.toString(), contains('DiffFile{'));
expect(patch.hunks[0].toString(), contains('DiffHunk{'));
expect(patch.hunks[0].lines[0].toString(), contains('DiffLine{'));
expect(stats.toString(), contains('DiffStats{'));
stats.free();
patch.free();
diff.free();
});
});
}

View file

@ -1,9 +1,8 @@
import 'dart:io';
import 'package:path/path.dart' as p;
final tmpDir = Directory.systemTemp.createTempSync('testrepo');
Directory setupRepo(Directory repoDir) {
final tmpDir = Directory.systemTemp.createTempSync('testrepo');
if (tmpDir.existsSync()) {
tmpDir.deleteSync(recursive: true);
}

View file

@ -29,7 +29,9 @@ void main() {
});
test('returns mode of index entry', () {
expect(index['file'].mode, GitFilemode.blob);
for (final entry in index) {
expect(entry.mode, GitFilemode.blob);
}
});
test('returns index entry at provided position', () {
@ -174,5 +176,104 @@ void main() {
final oid = index.writeTree();
expect(oid.sha, 'a8ae3dd59e6e1802c6f78e05e301bfd57c9f334f');
});
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');
conflictRepo.checkout(refName: 'refs/heads/feature');
conflictRepo.merge(conflictBranch.target);
final index = conflictRepo.index;
final conflictedFile = index.conflicts['feature_file']!;
expect(conflictedFile.ancestor?.path, 'feature_file');
expect(conflictedFile.our?.path, 'feature_file');
expect(conflictedFile.their?.path, 'feature_file');
expect(conflictedFile.toString(), contains('ConflictEntry{'));
index.free();
conflictBranch.free();
conflictRepo.free();
repoDir.deleteSync(recursive: true);
});
test('returns conflicts with our and their present and null ancestor', () {
final repoDir = setupRepo(Directory('test/assets/mergerepo/'));
final conflictRepo = Repository.open(repoDir.path);
final conflictBranch = conflictRepo.lookupBranch('conflict-branch');
conflictRepo.merge(conflictBranch.target);
final index = conflictRepo.index;
final conflictedFile = index.conflicts['conflict_file']!;
expect(conflictedFile.ancestor?.path, null);
expect(conflictedFile.our?.path, 'conflict_file');
expect(conflictedFile.their?.path, 'conflict_file');
expect(conflictedFile.toString(), contains('ConflictEntry{'));
index.free();
conflictBranch.free();
conflictRepo.free();
repoDir.deleteSync(recursive: true);
});
test('returns conflicts with ancestor and their present and null our', () {
final repoDir = setupRepo(Directory('test/assets/mergerepo/'));
final conflictRepo = Repository.open(repoDir.path);
final conflictBranch = conflictRepo.lookupBranch('ancestor-conflict');
conflictRepo.checkout(refName: 'refs/heads/our-conflict');
conflictRepo.merge(conflictBranch.target);
final index = conflictRepo.index;
final conflictedFile = index.conflicts['feature_file']!;
expect(conflictedFile.ancestor?.path, 'feature_file');
expect(conflictedFile.our?.path, null);
expect(conflictedFile.their?.path, 'feature_file');
expect(conflictedFile.toString(), contains('ConflictEntry{'));
index.free();
conflictBranch.free();
conflictRepo.free();
repoDir.deleteSync(recursive: true);
});
test('returns conflicts with ancestor and our present and null their', () {
final repoDir = setupRepo(Directory('test/assets/mergerepo/'));
final conflictRepo = Repository.open(repoDir.path);
final conflictBranch = conflictRepo.lookupBranch('their-conflict');
conflictRepo.checkout(refName: 'refs/heads/feature');
conflictRepo.merge(conflictBranch.target);
final index = conflictRepo.index;
final conflictedFile = index.conflicts['feature_file']!;
expect(conflictedFile.ancestor?.path, 'feature_file');
expect(conflictedFile.our?.path, 'feature_file');
expect(conflictedFile.their?.path, null);
expect(conflictedFile.toString(), contains('ConflictEntry{'));
index.free();
conflictBranch.free();
conflictRepo.free();
repoDir.deleteSync(recursive: true);
});
test('returns string representation of Index and IndexEntry objects', () {
final index = repo.index;
expect(index.toString(), contains('Index{'));
expect(index['file'].toString(), contains('IndexEntry{'));
index.free();
});
});
}

View file

@ -206,5 +206,25 @@ Santa Claus <santa.claus@northpole.xx> <me@company.xx>
mailmap.free();
});
test('successfully resolves signature', () {
final signature = Signature.create(
name: 'nick1',
email: 'bugs@company.xx',
);
final realSignature = Signature.create(
name: 'Some Dude',
email: 'some@dude.xx',
);
final mailmap = Mailmap.empty();
mailmap.addEntry(
realName: 'Some Dude',
realEmail: 'some@dude.xx',
replaceName: 'nick1',
replaceEmail: 'bugs@company.xx',
);
expect(mailmap.resolveSignature(signature), realSignature);
});
});
}

View file

@ -148,7 +148,7 @@ void main() {
});
group('merge file from index', () {
test('successfully merges', () {
test('successfully merges without ancestor', () {
const diffExpected = """
\<<<<<<< conflict_file
master conflict edit
@ -160,10 +160,40 @@ conflict branch edit
final index = repo.index;
repo.merge(conflictBranch.target);
final conflictedFile = index.conflicts['conflict_file']!;
final diff = repo.mergeFileFromIndex(
ancestor: index.conflicts['conflict_file']!.ancestor,
ours: index.conflicts['conflict_file']!.our,
theirs: index.conflicts['conflict_file']!.their,
ancestor: null,
ours: conflictedFile.our!,
theirs: conflictedFile.their!,
);
expect(
diff,
diffExpected,
);
index.free();
conflictBranch.free();
});
test('successfully merges with ancestor', () {
const diffExpected = """
\<<<<<<< feature_file
Feature edit on feature branch
=======
Another feature edit
>>>>>>> feature_file
""";
final conflictBranch = repo.lookupBranch('ancestor-conflict');
repo.checkout(refName: 'refs/heads/feature');
final index = repo.index;
repo.merge(conflictBranch.target);
final conflictedFile = index.conflicts['feature_file']!;
final diff = repo.mergeFileFromIndex(
ancestor: conflictedFile.ancestor,
ours: conflictedFile.our!,
theirs: conflictedFile.their!,
);
expect(

View file

@ -93,5 +93,11 @@ void main() {
head.free();
signature.free();
});
test('returns string representation of Note object', () {
final note = repo.lookupNote(annotatedOid: repo['821ed6e']);
expect(note.toString(), contains('Note{'));
note.free();
});
});
}

View file

@ -34,17 +34,16 @@ void main() {
});
test('successfully adds disk alternate', () {
final oid = Oid.fromSHA(repo: repo, sha: blobSha);
final odb = Odb.create();
odb.addDiskAlternate('${repo.workdir}.git/objects/');
expect(odb.contains(oid), true);
expect(odb.contains(repo[blobSha]), true);
odb.free();
});
test('successfully reads object', () {
final oid = Oid.fromSHA(repo: repo, sha: blobSha);
final oid = repo[blobSha];
final odb = repo.odb;
final object = odb.read(oid);
@ -58,23 +57,14 @@ void main() {
});
test('returns list of all objects oid\'s in database', () {
final oid = Oid.fromSHA(repo: repo, sha: commitSha);
final odb = repo.odb;
expect(odb.objects, isNot(isEmpty));
expect(odb.objects.contains(oid), true);
expect(odb.objects.contains(repo[commitSha]), true);
odb.free();
});
test('finds object by short oid', () {
final oid = Oid.fromSHA(
repo: repo,
sha: commitSha.substring(0, 5),
);
expect(oid.sha, commitSha);
});
test('successfully writes data', () {
final odb = repo.odb;
final oid = odb.write(type: GitObject.blob, data: 'testing');
@ -96,5 +86,12 @@ void main() {
odb.free();
});
test('returns string representation of OdbObject object', () {
final odb = repo.odb;
final object = odb.read(repo[blobSha]);
expect(object.toString(), contains('OdbObject{'));
odb.free();
});
});
}

View file

@ -35,6 +35,19 @@ void main() {
expect(oid, isA<Oid>());
expect(oid.sha, sha);
});
test('throws when sha hex string is too short', () {
expect(
() => Oid.fromSHA(repo: repo, sha: 'sha'),
throwsA(
isA<ArgumentError>().having(
(e) => e.invalidValue,
'value',
'sha is not a valid sha hex string',
),
),
);
});
});
group('fromRaw()', () {
@ -72,5 +85,9 @@ void main() {
expect(oid1 >= oid2, true);
});
});
test('returns string representation of Oid object', () {
expect(repo[sha].toString(), contains('Oid{'));
});
});
}

View file

@ -69,12 +69,15 @@ void main() {
odb.free();
});
test('successfully packs into provided path', () {
test('successfully packs into provided path with threads set', () {
final odb = repo.odb;
final objectsCount = odb.objects.length;
Directory('${repo.workdir}test-pack').createSync();
final writtenCount = repo.pack(path: '${repo.workdir}test-pack');
final writtenCount = repo.pack(
path: '${repo.workdir}test-pack',
threads: 1,
);
expect(writtenCount, objectsCount);
expect(
Directory('${repo.workdir}test-pack').listSync().isNotEmpty,
@ -101,5 +104,11 @@ void main() {
final writtenCount = repo.pack(packDelegate: packDelegate);
expect(writtenCount, 18);
});
test('returns string representation of PackBuilder object', () {
final packbuilder = PackBuilder(repo);
expect(packbuilder.toString(), contains('PackBuilder{'));
packbuilder.free();
});
});
}

View file

@ -174,5 +174,18 @@ index e69de29..0000000
commit.free();
});
test('returns string representation of Patch object', () {
final patch = Patch.create(
a: oldBlob,
b: newBlob,
aPath: path,
bPath: path,
);
expect(patch.toString(), contains('Patch{'));
patch.free();
});
});
}

View file

@ -44,9 +44,13 @@ void main() {
final operation = rebase.next();
expect(operation.type, GitRebaseOperation.pick);
expect(operation.oid.sha, shas[i]);
expect(operation.exec, '');
expect(operation.toString(), contains('RebaseOperation{'));
rebase.commit(committer: signature);
rebase.commit(
committer: signature,
author: signature,
message: 'rebase message',
);
}
rebase.finish();

View file

@ -64,7 +64,7 @@ void main() {
test('returns the short name', () {
final ref = repo.createReference(
name: 'refs/remotes/origin/master',
target: lastCommit,
target: repo[lastCommit],
);
final head = repo.head;
@ -91,7 +91,7 @@ void main() {
test('checks if reference is a remote branch', () {
final ref = repo.createReference(
name: 'refs/remotes/origin/master',
target: lastCommit,
target: repo[lastCommit],
);
expect(ref.isRemote, true);
@ -129,33 +129,11 @@ void main() {
ref.free();
});
test('successfully creates with SHA hash as target', () {
final refFromHash = repo.createReference(
name: 'refs/tags/from.hash',
target: lastCommit,
);
expect(repo.references, contains('refs/tags/from.hash'));
refFromHash.free();
});
test('successfully creates with short SHA hash as target', () {
final refFromHash = repo.createReference(
name: 'refs/tags/from.short.hash',
target: '78b8bf',
);
expect(repo.references, contains('refs/tags/from.short.hash'));
refFromHash.free();
});
test('successfully creates with log message', () {
repo.setIdentity(name: 'name', email: 'email');
final ref = repo.createReference(
name: 'refs/heads/log.message',
target: lastCommit,
target: repo[lastCommit],
logMessage: 'log message',
);
@ -178,13 +156,21 @@ void main() {
),
throwsA(isA<LibGit2Error>()),
);
expect(
() => repo.createReference(
name: 'refs/tags/invalid',
target: 0,
),
throwsA(isA<ArgumentError>()),
);
});
test('throws if name is not valid', () {
expect(
() => repo.createReference(
name: 'refs/tags/invalid~',
target: lastCommit,
target: repo[lastCommit],
),
throwsA(isA<LibGit2Error>()),
);
@ -193,12 +179,12 @@ void main() {
test('successfully creates with force flag if name already exists', () {
final ref = repo.createReference(
name: 'refs/tags/test',
target: lastCommit,
target: repo[lastCommit],
);
final forceRef = repo.createReference(
name: 'refs/tags/test',
target: lastCommit,
target: repo[lastCommit],
force: true,
);
@ -211,13 +197,13 @@ void main() {
test('throws if name already exists', () {
final ref = repo.createReference(
name: 'refs/tags/test',
target: lastCommit,
target: repo[lastCommit],
);
expect(
() => repo.createReference(
name: 'refs/tags/test',
target: lastCommit,
target: repo[lastCommit],
),
throwsA(isA<LibGit2Error>()),
);
@ -309,7 +295,7 @@ void main() {
test('successfully deletes reference', () {
final ref = repo.createReference(
name: 'refs/tags/test',
target: lastCommit,
target: repo[lastCommit],
);
expect(repo.references, contains('refs/tags/test'));
@ -384,6 +370,10 @@ void main() {
() => ref.setTarget(target: 'refs/heads/invalid~'),
throwsA(isA<LibGit2Error>()),
);
expect(
() => ref.setTarget(target: 0),
throwsA(isA<ArgumentError>()),
);
ref.free();
});
@ -476,15 +466,32 @@ void main() {
test('successfully peels to object of provided type', () {
final ref = repo.lookupReference('refs/heads/master');
final blob = repo.lookupBlob(repo['9c78c21']);
final blobRef = repo.createReference(
name: 'refs/tags/blob',
target: blob.oid,
);
final tagRef = repo.lookupReference('refs/tags/v0.2');
final commit = repo.lookupCommit(ref.target);
final tree = commit.tree;
final peeledCommit = ref.peel(GitObject.commit) as Commit;
final peeledTree = ref.peel(GitObject.tree) as Tree;
final peeledBlob = blobRef.peel(GitObject.blob) as Blob;
final peeledTag = tagRef.peel(GitObject.tag) as Tag;
expect(peeledCommit.oid, commit.oid);
expect(peeledTree.oid, tree.oid);
expect(peeledBlob.content, 'Feature edit\n');
expect(peeledTag.name, 'v0.2');
peeledTag.free();
peeledBlob.free();
peeledTree.free();
peeledCommit.free();
tagRef.free();
blobRef.free();
blob.free();
commit.free();
tree.free();
ref.free();
@ -501,5 +508,11 @@ void main() {
final newRefs = repo.references;
expect(newRefs, oldRefs);
});
test('returns string representation of Reference object', () {
final ref = repo.lookupReference('refs/heads/master');
expect(ref.toString(), contains('Reference{'));
ref.free();
});
});
}

View file

@ -41,5 +41,9 @@ void main() {
expect(reflog[0].committer.email, 'skinny.mind@gmail.com');
expect(reflog[0].committer.time, 1630568461);
});
test('returns string representation of RefLogEntry object', () {
expect(reflog[0].toString(), contains('RefLogEntry{'));
});
});
}

View file

@ -1,4 +1,5 @@
import 'dart:io';
import 'package:libgit2dart/src/git_types.dart';
import 'package:test/test.dart';
import 'package:libgit2dart/libgit2dart.dart';
import 'helpers/util.dart';
@ -30,6 +31,7 @@ void main() {
expect(remote.name, remoteName);
expect(remote.url, remoteUrl);
expect(remote.pushUrl, '');
expect(remote.toString(), contains('Remote{'));
remote.free();
});
@ -143,7 +145,9 @@ void main() {
expect(refspec.source, 'refs/heads/*');
expect(refspec.destination, 'refs/remotes/origin/*');
expect(refspec.force, true);
expect(refspec.direction, GitDirection.fetch);
expect(refspec.string, '+refs/heads/*:refs/remotes/origin/*');
expect(refspec.toString(), contains('Refspec{'));
expect(remote.fetchRefspecs, ['+refs/heads/*:refs/remotes/origin/*']);
expect(refspec.matchesSource('refs/heads/master'), true);
@ -231,6 +235,7 @@ void main() {
expect(stats.totalDeltas, 3);
expect(stats.indexedDeltas, 3);
expect(stats.receivedBytes, 0);
expect(stats.toString(), contains('TransferProgress{'));
remote.free();
});

View file

@ -30,6 +30,15 @@ void main() {
config.free();
});
test('returns snapshot of repository config', () {
final snapshot = repo.configSnapshot;
expect(
snapshot['remote.origin.url'].value,
'git://github.com/SkinnyMind/libgit2dart.git',
);
snapshot.free();
});
test('returns list of commits by walking from provided starting oid', () {
const log = [
'821ed6e80627b8769d170a293862f9fc60825226',
@ -111,6 +120,10 @@ void main() {
repo.setHead('refs/heads/not.there');
expect(repo.isBranchUnborn, true);
});
test('throws when target is invalid', () {
expect(() => repo.setHead(0), throwsA(isA<ArgumentError>()));
});
});
group('createBlob', () {
@ -196,6 +209,18 @@ void main() {
index.free();
});
test('cleans up state', () {
expect(repo.state, GitRepositoryState.none);
final commit = repo.lookupCommit(repo['5aecfa0']);
repo.cherryPick(commit);
expect(repo.state, GitRepositoryState.cherrypick);
repo.stateCleanup();
expect(repo.state, GitRepositoryState.none);
commit.free();
});
test('returns status of a single file for provided path', () {
final index = repo.index;
index.remove('file');
@ -284,5 +309,9 @@ void main() {
commit1.free();
commit2.free();
});
test('returns string representation of Repository object', () {
expect(repo.toString(), contains('Repository{'));
});
});
}

View file

@ -41,6 +41,7 @@ void main() {
expect(headParse.object.oid.sha, headSHA);
expect(headParse.reference, masterRef);
expect(headParse.toString(), contains('RevParse{'));
masterRef.free();
headParse.object.free();
@ -77,6 +78,7 @@ void main() {
expect(revspec.from.oid.sha, headSHA);
expect(revspec.to, isNull);
expect(revspec.flags, {GitRevSpec.single});
expect(revspec.toString(), contains('RevSpec{'));
revspec.from.free();

View file

@ -56,5 +56,9 @@ void main() {
otherSignature.free();
});
test('returns string representation of Signature object', () {
expect(signature.toString(), contains('Signature{'));
});
});
}

View file

@ -30,10 +30,41 @@ void main() {
mode: FileMode.append,
);
repo.createStash(stasher: stasher, includeUntracked: true);
repo.createStash(stasher: stasher);
expect(repo.status.isEmpty, true);
});
test('successfully saves changes to stash including ignored', () {
final swpPath = File('${tmpDir.path}/some.swp');
swpPath.writeAsStringSync('ignored');
repo.createStash(
stasher: stasher,
includeUntracked: true,
includeIgnored: true,
);
expect(repo.status.isEmpty, true);
expect(swpPath.existsSync(), false);
repo.applyStash();
expect(swpPath.existsSync(), true);
});
test('leaves changes added to index intact', () {
File('${tmpDir.path}/file').writeAsStringSync(
'edit',
mode: FileMode.append,
);
final index = repo.index;
index.add('file');
repo.createStash(stasher: stasher, keepIndex: true);
expect(repo.status.isEmpty, false);
expect(repo.stashes.length, 1);
index.free();
});
test('successfully applies changes from stash', () {
File('${tmpDir.path}/file').writeAsStringSync(
'edit',
@ -47,6 +78,23 @@ void main() {
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;
index.add('stash.this');
expect(index.find('stash.this'), true);
repo.createStash(stasher: stasher, includeUntracked: true);
expect(repo.status.isEmpty, true);
expect(index.find('stash.this'), false);
repo.applyStash(reinstateIndex: true);
expect(repo.status, contains('stash.this'));
expect(index.find('stash.this'), true);
index.free();
});
test('successfully drops stash', () {
File('${tmpDir.path}/file').writeAsStringSync(
'edit',
@ -71,6 +119,23 @@ void main() {
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;
index.add('stash.this');
expect(index.find('stash.this'), true);
repo.createStash(stasher: stasher, includeUntracked: true);
expect(repo.status.isEmpty, true);
expect(index.find('stash.this'), false);
repo.popStash(reinstateIndex: true);
expect(repo.status, contains('stash.this'));
expect(index.find('stash.this'), true);
index.free();
});
test('returns list of stashes', () {
File('${tmpDir.path}/file').writeAsStringSync(
'edit',
@ -85,5 +150,11 @@ void main() {
expect(stash.index, 0);
expect(stash.message, 'On master: WIP');
});
test('returns string representation of Stash object', () {
File('${tmpDir.path}/stash.this').writeAsStringSync('stash');
repo.createStash(stasher: stasher, includeUntracked: true);
expect(repo.stashes[0].toString(), contains('Stash{'));
});
});
}

View file

@ -38,6 +38,7 @@ void main() {
expect(submodule.workdirOid?.sha, null);
expect(submodule.ignore, GitSubmoduleIgnore.none);
expect(submodule.updateRule, GitSubmoduleUpdate.checkout);
expect(submodule.toString(), contains('Submodule{'));
submodule.free();
});
@ -70,6 +71,10 @@ void main() {
final subHead = submoduleRepo.head;
expect(submoduleRepo, isA<Repository>());
expect(subHead.target.sha, submoduleHeadSha);
expect(
submodule.workdirOid?.sha,
'49322bb17d3acc9146f98c97d078513228bbf3c0',
);
subHead.free();
submoduleRepo.free();

View file

@ -42,12 +42,13 @@ void main() {
expect(tag.message, 'annotated tag\n');
expect(target.message, 'add subdirectory file\n');
expect(tagger, signature);
expect(tag.toString(), contains('Tag{'));
signature.free();
target.free();
});
test('successfully creates new tag', () {
test('successfully creates new tag with commit as target', () {
final signature = Signature.create(
name: 'Author',
email: 'author@email.com',
@ -80,6 +81,104 @@ void main() {
signature.free();
});
test('successfully creates new tag with tree as target', () {
final signature = Signature.create(
name: 'Author',
email: 'author@email.com',
time: 1234,
);
const tagName = 'tag';
final target = repo['a8ae3dd59e6e1802c6f78e05e301bfd57c9f334f'];
const message = 'init tag\n';
final oid = repo.createTag(
tagName: tagName,
target: target,
targetType: GitObject.tree,
tagger: signature,
message: message,
);
final newTag = repo.lookupTag(oid);
final tagger = newTag.tagger;
final newTagTarget = newTag.target as Tree;
expect(newTag.oid.sha, 'ca715c0bafad5d39d568675aad69f71a82178416');
expect(newTag.name, tagName);
expect(newTag.message, message);
expect(tagger, signature);
expect(newTagTarget.oid, target);
newTag.free();
newTagTarget.free();
signature.free();
});
test('successfully creates new tag with blob as target', () {
final signature = Signature.create(
name: 'Author',
email: 'author@email.com',
time: 1234,
);
const tagName = 'tag';
final target = repo['9c78c21d6680a7ffebc76f7ac68cacc11d8f48bc'];
const message = 'init tag\n';
final oid = repo.createTag(
tagName: tagName,
target: target,
targetType: GitObject.blob,
tagger: signature,
message: message,
);
final newTag = repo.lookupTag(oid);
final tagger = newTag.tagger;
final newTagTarget = newTag.target as Blob;
expect(newTag.oid.sha, '8b1edabda95e934d2252e563219315b08e38dce5');
expect(newTag.name, tagName);
expect(newTag.message, message);
expect(tagger, signature);
expect(newTagTarget.oid, target);
newTag.free();
newTagTarget.free();
signature.free();
});
test('successfully creates new tag with tag as target', () {
final signature = Signature.create(
name: 'Author',
email: 'author@email.com',
time: 1234,
);
const tagName = 'tag';
const message = 'init tag\n';
final oid = repo.createTag(
tagName: tagName,
target: tag.oid,
targetType: GitObject.tag,
tagger: signature,
message: message,
);
final newTag = repo.lookupTag(oid);
final tagger = newTag.tagger;
final newTagTarget = newTag.target as Tag;
expect(newTag.oid.sha, '20286cf6c3b150b58b6c419814b0931d9b17c2ba');
expect(newTag.name, tagName);
expect(newTag.message, message);
expect(tagger, signature);
expect(newTagTarget.oid, tag.oid);
newTag.free();
newTagTarget.free();
signature.free();
});
test('returns list of tags in repository', () {
expect(Tag.list(repo), ['v0.1', 'v0.2']);
});

View file

@ -26,6 +26,7 @@ void main() {
group('Tree', () {
test('successfully initializes tree from provided Oid', () {
expect(tree, isA<Tree>());
expect(tree.toString(), contains('Tree{'));
});
test('returns correct values', () {
@ -55,6 +56,7 @@ void main() {
test('returns tree entry with provided path to file', () {
final entry = tree['dir/dir_file.txt'];
expect(entry.oid.sha, 'e69de29bb2d1d6434b8b29ae775ad8c2e48c5391');
expect(entry.toString(), contains('TreeEntry{'));
entry.free();
});
@ -62,6 +64,10 @@ void main() {
expect(() => tree['invalid/path'], throwsA(isA<LibGit2Error>()));
});
test('throws when looking up with invalid argument type', () {
expect(() => tree[true], throwsA(isA<ArgumentError>()));
});
test('successfully creates tree', () {
final fileOid = repo.createBlob('blob content');
final builder = TreeBuilder(repo: repo);

View file

@ -24,6 +24,7 @@ void main() {
test('successfully initializes tree builder when no tree is provided', () {
final builder = TreeBuilder(repo: repo);
expect(builder, isA<TreeBuilder>());
expect(builder.toString(), contains('TreeBuilder{'));
builder.free();
});

View file

@ -40,6 +40,7 @@ void main() {
expect(worktree.name, worktreeName);
expect(worktree.path, worktreeDir.path);
expect(worktree.isLocked, false);
expect(worktree.toString(), contains('Worktree{'));
expect(File('${worktreeDir.path}/.git').existsSync(), true);
for (final branch in branches) {