mirror of
https://github.com/SkinnyMind/libgit2dart.git
synced 2025-05-05 12:49:08 -04:00
feat: add ability to compare objects
This commit is contained in:
parent
5dfedadfe6
commit
a14fe15a9c
45 changed files with 466 additions and 137 deletions
|
@ -107,5 +107,12 @@ void main() {
|
|||
final annotated = AnnotatedCommit.lookup(repo: repo, oid: tip);
|
||||
expect(() => annotated.free(), returnsNormally);
|
||||
});
|
||||
|
||||
test('supports value comparison', () {
|
||||
expect(
|
||||
AnnotatedCommit.lookup(repo: repo, oid: tip),
|
||||
equals(AnnotatedCommit.lookup(repo: repo, oid: tip)),
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -211,5 +211,12 @@ void main() {
|
|||
final blame = Blame.file(repo: repo, path: 'feature_file');
|
||||
expect(blame.toString(), contains('BlameHunk{'));
|
||||
});
|
||||
|
||||
test('supports value comparison', () {
|
||||
expect(
|
||||
Blame.file(repo: repo, path: 'feature_file'),
|
||||
equals(Blame.file(repo: repo, path: 'feature_file')),
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -153,5 +153,12 @@ void main() {
|
|||
final blob = Blob.lookup(repo: repo, oid: repo[blobSHA]);
|
||||
expect(blob.toString(), contains('Blob{'));
|
||||
});
|
||||
|
||||
test('supports value comparison', () {
|
||||
expect(
|
||||
Blob.lookup(repo: repo, oid: repo[blobSHA]),
|
||||
equals(Blob.lookup(repo: repo, oid: repo[blobSHA])),
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -327,5 +327,12 @@ void main() {
|
|||
final branch = Branch.lookup(repo: repo, name: 'master');
|
||||
expect(branch.toString(), contains('Branch{'));
|
||||
});
|
||||
|
||||
test('supports value comparison', () {
|
||||
expect(
|
||||
Branch.lookup(repo: repo, name: 'master'),
|
||||
equals(Branch.lookup(repo: repo, name: 'master')),
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -396,5 +396,12 @@ Some description.
|
|||
final commit = Commit.lookup(repo: repo, oid: tip);
|
||||
expect(commit.toString(), contains('Commit{'));
|
||||
});
|
||||
|
||||
test('supports value comparison', () {
|
||||
expect(
|
||||
Commit.lookup(repo: repo, oid: tip),
|
||||
equals(Commit.lookup(repo: repo, oid: tip)),
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -217,5 +217,9 @@ void main() {
|
|||
final entry = config.first;
|
||||
expect(entry.toString(), contains('ConfigEntry{'));
|
||||
});
|
||||
|
||||
test('supports value comparison', () {
|
||||
expect(Config.open(filePath), equals(Config.open(filePath)));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -580,5 +580,15 @@ index e69de29..c217c63 100644
|
|||
expect(patch.delta.oldFile.toString(), contains('DiffFile{'));
|
||||
expect(stats.toString(), contains('DiffStats{'));
|
||||
});
|
||||
|
||||
test('supports value comparison', () {
|
||||
expect(Diff.parse(patchText), equals(Diff.parse(patchText)));
|
||||
|
||||
final diff = Diff.parse(patchText);
|
||||
expect(diff.deltas[0], equals(diff.deltas[0]));
|
||||
|
||||
final delta = diff.deltas[0];
|
||||
expect(delta.oldFile, equals(delta.oldFile));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -509,5 +509,9 @@ void main() {
|
|||
expect(index.toString(), contains('Index{'));
|
||||
expect(index['file'].toString(), contains('IndexEntry{'));
|
||||
});
|
||||
|
||||
test('supports value comparison', () {
|
||||
expect(repo.index, equals(repo.index));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -134,5 +134,13 @@ void main() {
|
|||
final note = Note.lookup(repo: repo, annotatedOid: repo['821ed6e']);
|
||||
expect(note.toString(), contains('Note{'));
|
||||
});
|
||||
|
||||
test('supports value comparison', () {
|
||||
final oid = repo.head.target;
|
||||
expect(
|
||||
Note.lookup(repo: repo, annotatedOid: oid),
|
||||
equals(Note.lookup(repo: repo, annotatedOid: oid)),
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -50,6 +50,7 @@ void main() {
|
|||
expect(object.type, GitObject.blob);
|
||||
expect(object.data, blobContent);
|
||||
expect(object.size, 13);
|
||||
expect(object, equals(repo.odb.read(repo[blobSha])));
|
||||
});
|
||||
|
||||
test('throws when trying to read object and error occurs', () {
|
||||
|
@ -115,5 +116,9 @@ void main() {
|
|||
final object = repo.odb.read(repo[blobSha]);
|
||||
expect(object.toString(), contains('OdbObject{'));
|
||||
});
|
||||
|
||||
test('supports value comparison', () {
|
||||
expect(repo.odb, equals(repo.odb));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -230,5 +230,25 @@ index e69de29..0000000
|
|||
expect(patch.hunks[0].toString(), contains('DiffHunk{'));
|
||||
expect(patch.hunks[0].lines[0].toString(), contains('DiffLine{'));
|
||||
});
|
||||
|
||||
test('supports value comparison', () {
|
||||
final patch = Patch.fromBuffers(
|
||||
oldBuffer: oldBuffer,
|
||||
newBuffer: newBuffer,
|
||||
oldBufferPath: path,
|
||||
newBufferPath: path,
|
||||
);
|
||||
final anotherPatch = Patch.fromBuffers(
|
||||
oldBuffer: oldBuffer,
|
||||
newBuffer: newBuffer,
|
||||
oldBufferPath: path,
|
||||
newBufferPath: path,
|
||||
);
|
||||
expect(patch, equals(anotherPatch));
|
||||
expect(patch.hunks[0], equals(patch.hunks[0]));
|
||||
|
||||
final hunk = patch.hunks[0];
|
||||
expect(hunk.lines[0], equals(hunk.lines[0]));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -155,7 +155,7 @@ void main() {
|
|||
final duplicate = ref.duplicate();
|
||||
|
||||
expect(repo.references.length, 6);
|
||||
expect(duplicate.equals(ref), true);
|
||||
expect(duplicate, equals(ref));
|
||||
});
|
||||
|
||||
group('create direct', () {
|
||||
|
@ -354,25 +354,35 @@ void main() {
|
|||
|
||||
group('set target', () {
|
||||
test('sets direct reference with provided oid target', () {
|
||||
Reference.setTarget(
|
||||
repo: repo,
|
||||
name: 'refs/heads/master',
|
||||
target: repo[newCommit],
|
||||
);
|
||||
final ref = Reference.lookup(repo: repo, name: 'refs/heads/master');
|
||||
ref.setTarget(target: repo[newCommit]);
|
||||
expect(ref.target.sha, newCommit);
|
||||
});
|
||||
|
||||
test('sets symbolic target with provided reference name', () {
|
||||
Reference.setTarget(
|
||||
repo: repo,
|
||||
name: 'HEAD',
|
||||
target: 'refs/heads/feature',
|
||||
);
|
||||
final ref = Reference.lookup(repo: repo, name: 'HEAD');
|
||||
expect(ref.target.sha, lastCommit);
|
||||
|
||||
ref.setTarget(target: 'refs/heads/feature');
|
||||
expect(ref.target.sha, '5aecfa0fb97eadaac050ccb99f03c3fb65460ad4');
|
||||
});
|
||||
|
||||
test('sets target with log message', () {
|
||||
final ref = Reference.lookup(repo: repo, name: 'HEAD');
|
||||
expect(ref.target.sha, lastCommit);
|
||||
|
||||
repo.setIdentity(name: 'name', email: 'email');
|
||||
ref.setTarget(target: 'refs/heads/feature', logMessage: 'log message');
|
||||
Reference.setTarget(
|
||||
repo: repo,
|
||||
name: 'HEAD',
|
||||
target: 'refs/heads/feature',
|
||||
logMessage: 'log message',
|
||||
);
|
||||
|
||||
final ref = Reference.lookup(repo: repo, name: 'HEAD');
|
||||
expect(ref.target.sha, '5aecfa0fb97eadaac050ccb99f03c3fb65460ad4');
|
||||
final logEntry = ref.log.first;
|
||||
expect(logEntry.message, 'log message');
|
||||
|
@ -381,18 +391,28 @@ void main() {
|
|||
});
|
||||
|
||||
test('throws on invalid target', () {
|
||||
final ref = Reference.lookup(repo: repo, name: 'HEAD');
|
||||
expect(
|
||||
() => ref.setTarget(target: 'refs/heads/invalid~'),
|
||||
() => Reference.setTarget(
|
||||
repo: repo,
|
||||
name: 'HEAD',
|
||||
target: 'refs/heads/invalid~',
|
||||
),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
|
||||
expect(
|
||||
() => ref.setTarget(target: Oid(nullptr)),
|
||||
() => Reference.setTarget(
|
||||
repo: repo,
|
||||
name: 'HEAD',
|
||||
target: Oid(nullptr),
|
||||
),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
|
||||
expect(() => ref.setTarget(target: 0), throwsA(isA<ArgumentError>()));
|
||||
expect(
|
||||
() => Reference.setTarget(repo: repo, name: 'HEAD', target: 0),
|
||||
throwsA(isA<ArgumentError>()),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -458,17 +478,6 @@ void main() {
|
|||
});
|
||||
});
|
||||
|
||||
test('checks equality', () {
|
||||
final ref1 = Reference.lookup(repo: repo, name: 'refs/heads/master');
|
||||
final ref2 = Reference.lookup(repo: repo, name: 'refs/heads/master');
|
||||
final ref3 = Reference.lookup(repo: repo, name: 'refs/heads/feature');
|
||||
|
||||
expect(ref1.equals(ref2), true);
|
||||
expect(ref1.notEquals(ref2), false);
|
||||
expect(ref1.equals(ref3), false);
|
||||
expect(ref1.notEquals(ref3), true);
|
||||
});
|
||||
|
||||
test('peels to non-tag object when no type is provided', () {
|
||||
final ref = Reference.lookup(repo: repo, name: 'refs/heads/master');
|
||||
final commit = Commit.lookup(repo: repo, oid: ref.target);
|
||||
|
@ -530,5 +539,12 @@ void main() {
|
|||
final ref = Reference.lookup(repo: repo, name: 'refs/heads/master');
|
||||
expect(ref.toString(), contains('Reference{'));
|
||||
});
|
||||
|
||||
test('supports value comparison', () {
|
||||
expect(
|
||||
Reference.lookup(repo: repo, name: 'HEAD'),
|
||||
equals(Reference.lookup(repo: repo, name: 'refs/heads/master')),
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -153,5 +153,10 @@ void main() {
|
|||
test('returns string representation of RefLogEntry object', () {
|
||||
expect(reflog[0].toString(), contains('RefLogEntry{'));
|
||||
});
|
||||
|
||||
test('supports value comparison', () {
|
||||
final ref = Reference.lookup(repo: repo, name: 'refs/heads/master');
|
||||
expect(RefLog(repo.head), equals(RefLog(ref)));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ void main() {
|
|||
expect(remote.url, remoteUrl);
|
||||
expect(remote.pushUrl, '');
|
||||
expect(remote.toString(), contains('Remote{'));
|
||||
expect(remote, equals(Remote.lookup(repo: repo, name: 'origin')));
|
||||
});
|
||||
|
||||
test('throws when provided name for lookup is not found', () {
|
||||
|
@ -42,6 +43,13 @@ void main() {
|
|||
);
|
||||
});
|
||||
|
||||
test('throws when trying to create remote and name already exists', () {
|
||||
expect(
|
||||
() => Remote.create(repo: repo, name: 'origin', url: remoteUrl),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
});
|
||||
|
||||
test('creates without fetchspec', () {
|
||||
final remote = Remote.create(
|
||||
repo: repo,
|
||||
|
@ -188,6 +196,8 @@ void main() {
|
|||
refspec.rTransform('refs/remotes/origin/master'),
|
||||
'refs/heads/master',
|
||||
);
|
||||
|
||||
expect(refspec, equals(remote.getRefspec(0)));
|
||||
});
|
||||
|
||||
test('throws when trying to transform refspec with invalid reference name',
|
||||
|
@ -270,6 +280,7 @@ void main() {
|
|||
expect(refs.first.symRef, 'refs/heads/master');
|
||||
expect((refs.first.oid).sha, '49322bb17d3acc9146f98c97d078513228bbf3c0');
|
||||
expect(refs.first.toString(), contains('RemoteReference{'));
|
||||
expect(refs.first, remote.ls().first);
|
||||
});
|
||||
|
||||
test(
|
||||
|
|
|
@ -59,7 +59,7 @@ void main() {
|
|||
var headParse = RevParse.ext(repo: repo, spec: 'master');
|
||||
|
||||
expect(headParse.object.oid.sha, headSHA);
|
||||
expect(headParse.reference?.equals(masterRef), true);
|
||||
expect(headParse.reference, equals(masterRef));
|
||||
expect(headParse.toString(), contains('RevParse{'));
|
||||
|
||||
final featureRef = Reference.lookup(
|
||||
|
@ -72,7 +72,7 @@ void main() {
|
|||
headParse.object.oid.sha,
|
||||
'5aecfa0fb97eadaac050ccb99f03c3fb65460ad4',
|
||||
);
|
||||
expect(headParse.reference?.equals(featureRef), true);
|
||||
expect(headParse.reference, equals(featureRef));
|
||||
});
|
||||
|
||||
test('.ext() returns only commit when no intermidiate reference found', () {
|
||||
|
|
|
@ -47,6 +47,7 @@ void main() {
|
|||
lessThan(5),
|
||||
);
|
||||
expect(sig.offset, isA<int>());
|
||||
expect(sig.sign, isNotEmpty);
|
||||
});
|
||||
|
||||
test('returns correct values', () {
|
||||
|
@ -77,5 +78,12 @@ void main() {
|
|||
test('returns string representation of Signature object', () {
|
||||
expect(signature.toString(), contains('Signature{'));
|
||||
});
|
||||
|
||||
test('supports value comparison', () {
|
||||
expect(
|
||||
Signature.create(name: name, email: email, time: time),
|
||||
equals(Signature.create(name: name, email: email, time: time)),
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -211,5 +211,12 @@ void main() {
|
|||
|
||||
expect(repo.stashes[0].toString(), contains('Stash{'));
|
||||
});
|
||||
|
||||
test('supports value comparison', () {
|
||||
File(filePath).writeAsStringSync('edit', mode: FileMode.append);
|
||||
Stash.create(repo: repo, stasher: stasher, message: 'WIP');
|
||||
|
||||
expect(repo.stashes.first, equals(repo.stashes.first));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -243,5 +243,12 @@ void main() {
|
|||
final submodule = Submodule.lookup(repo: repo, name: testSubmodule);
|
||||
expect(() => submodule.free(), returnsNormally);
|
||||
});
|
||||
|
||||
test('supports value comparison', () {
|
||||
expect(
|
||||
Submodule.lookup(repo: repo, name: testSubmodule),
|
||||
equals(Submodule.lookup(repo: repo, name: testSubmodule)),
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -384,5 +384,12 @@ void main() {
|
|||
tag = Tag.lookup(repo: repo, oid: tagOid);
|
||||
expect(() => tag.free(), returnsNormally);
|
||||
});
|
||||
|
||||
test('supports value comparison', () {
|
||||
expect(
|
||||
Tag.lookup(repo: repo, oid: tagOid),
|
||||
equals(Tag.lookup(repo: repo, oid: tagOid)),
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -101,5 +101,14 @@ void main() {
|
|||
'looked up by path', () {
|
||||
expect(() => tree['dir/dir_file.txt'].free(), returnsNormally);
|
||||
});
|
||||
|
||||
test('supports value comparison', () {
|
||||
expect(
|
||||
Tree.lookup(repo: repo, oid: repo['a8ae3dd']),
|
||||
equals(Tree.lookup(repo: repo, oid: repo['a8ae3dd'])),
|
||||
);
|
||||
|
||||
expect(tree[0], equals(tree[0]));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -166,5 +166,14 @@ void main() {
|
|||
);
|
||||
expect(() => worktree.free(), returnsNormally);
|
||||
});
|
||||
|
||||
test('supports value comparison', () {
|
||||
final worktree = Worktree.create(
|
||||
repo: repo,
|
||||
name: worktreeName,
|
||||
path: worktreeDir.path,
|
||||
);
|
||||
expect(worktree, equals(Worktree.lookup(repo: repo, name: worktreeName)));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue