mirror of
https://github.com/SkinnyMind/libgit2dart.git
synced 2025-05-05 04:39:07 -04:00
refactor!: use Finalizer
to automatically free allocated memory for objects (#48)
BREAKING CHANGE: signature change for remote and repository callbacks during repository clone operation.
This commit is contained in:
parent
94c40f9a94
commit
a3213a88a2
103 changed files with 2278 additions and 2595 deletions
|
@ -29,8 +29,6 @@ void main() {
|
|||
|
||||
expect(annotated.oid, tip);
|
||||
expect(annotated.refName, '');
|
||||
|
||||
annotated.free();
|
||||
});
|
||||
|
||||
test('throws when trying to lookup annotated commit with invalid oid', () {
|
||||
|
@ -41,33 +39,27 @@ void main() {
|
|||
});
|
||||
|
||||
test('creates annotated commit from provided reference', () {
|
||||
final reference = Reference.lookup(repo: repo, name: 'refs/heads/master');
|
||||
const refName = 'refs/heads/master';
|
||||
final reference = Reference.lookup(repo: repo, name: refName);
|
||||
final annotated = AnnotatedCommit.fromReference(
|
||||
repo: repo,
|
||||
reference: reference,
|
||||
);
|
||||
|
||||
expect(annotated.oid, reference.target);
|
||||
expect(annotated.refName, 'refs/heads/master');
|
||||
|
||||
annotated.free();
|
||||
reference.free();
|
||||
expect(annotated.refName, refName);
|
||||
});
|
||||
|
||||
test(
|
||||
'throws when trying to create annotated commit from provided '
|
||||
'reference and error occurs', () {
|
||||
final reference = Reference.lookup(repo: repo, name: 'refs/heads/master');
|
||||
|
||||
expect(
|
||||
() => AnnotatedCommit.fromReference(
|
||||
repo: Repository(nullptr),
|
||||
reference: reference,
|
||||
reference: Reference.lookup(repo: repo, name: 'refs/heads/master'),
|
||||
),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
|
||||
reference.free();
|
||||
});
|
||||
|
||||
test('creates annotated commit from provided revspec', () {
|
||||
|
@ -75,8 +67,6 @@ void main() {
|
|||
|
||||
expect(annotated.oid.sha, '5aecfa0fb97eadaac050ccb99f03c3fb65460ad4');
|
||||
expect(annotated.refName, '');
|
||||
|
||||
annotated.free();
|
||||
});
|
||||
|
||||
test('throws when trying to create annotated commit from invalid revspec',
|
||||
|
@ -98,8 +88,6 @@ void main() {
|
|||
|
||||
expect(annotated.oid, oid);
|
||||
expect(annotated.refName, 'master');
|
||||
|
||||
annotated.free();
|
||||
});
|
||||
|
||||
test(
|
||||
|
@ -115,5 +103,10 @@ void main() {
|
|||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
});
|
||||
|
||||
test('manually releases allocated memory', () {
|
||||
final annotated = AnnotatedCommit.lookup(repo: repo, oid: tip);
|
||||
expect(() => annotated.free(), returnsNormally);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -52,8 +52,6 @@ void main() {
|
|||
});
|
||||
|
||||
tearDown(() {
|
||||
sig1.free();
|
||||
sig2.free();
|
||||
repo.free();
|
||||
tmpDir.deleteSync(recursive: true);
|
||||
});
|
||||
|
@ -82,8 +80,6 @@ void main() {
|
|||
expect(blame[i].isBoundary, hunks[i]['isBoundary']);
|
||||
expect(blame[i].originPath, 'feature_file');
|
||||
}
|
||||
|
||||
blame.free();
|
||||
});
|
||||
|
||||
test('throws when provided file path is invalid', () {
|
||||
|
@ -104,9 +100,6 @@ void main() {
|
|||
expect(blameHunk.originCommitter, null);
|
||||
expect(blameHunk.finalCommitOid.sha, '0' * 40);
|
||||
expect(blameHunk.finalCommitter, null);
|
||||
|
||||
bufferBlame.free();
|
||||
blame.free();
|
||||
});
|
||||
|
||||
test('throws when trying to get blame for empty buffer', () {
|
||||
|
@ -115,7 +108,6 @@ void main() {
|
|||
() => Blame.buffer(reference: blame, buffer: ''),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
blame.free();
|
||||
});
|
||||
|
||||
test('returns the blame for provided file with minMatchCharacters set', () {
|
||||
|
@ -127,8 +119,6 @@ void main() {
|
|||
);
|
||||
|
||||
expect(blame.length, 2);
|
||||
|
||||
blame.free();
|
||||
});
|
||||
|
||||
test('returns the blame for provided line', () {
|
||||
|
@ -148,22 +138,16 @@ void main() {
|
|||
expect(hunk.originCommitter, hunks[0]['originCommitter']);
|
||||
expect(hunk.isBoundary, hunks[0]['isBoundary']);
|
||||
expect(hunk.originPath, 'feature_file');
|
||||
|
||||
blame.free();
|
||||
});
|
||||
|
||||
test('throws when provided index for hunk is invalid', () {
|
||||
final blame = Blame.file(repo: repo, path: 'feature_file');
|
||||
expect(() => blame[10], throwsA(isA<RangeError>()));
|
||||
|
||||
blame.free();
|
||||
});
|
||||
|
||||
test('throws when provided line number for hunk is invalid', () {
|
||||
final blame = Blame.file(repo: repo, path: 'feature_file');
|
||||
expect(() => blame.forLine(10), throwsA(isA<RangeError>()));
|
||||
|
||||
blame.free();
|
||||
});
|
||||
|
||||
test('returns the blame for provided file with newestCommit argument', () {
|
||||
|
@ -190,8 +174,6 @@ void main() {
|
|||
expect(hunk.originCommitter, hunks[0]['originCommitter']);
|
||||
expect(hunk.isBoundary, hunks[0]['isBoundary']);
|
||||
expect(hunk.originPath, 'feature_file');
|
||||
|
||||
blame.free();
|
||||
});
|
||||
|
||||
test('returns the blame for provided file with minLine and maxLine set',
|
||||
|
@ -219,14 +201,16 @@ void main() {
|
|||
expect(blame[i].isBoundary, hunks[i]['isBoundary']);
|
||||
expect(blame[i].originPath, 'feature_file');
|
||||
}
|
||||
});
|
||||
|
||||
blame.free();
|
||||
test('manually releases allocated memory', () {
|
||||
final blame = Blame.file(repo: repo, path: 'feature_file');
|
||||
expect(() => blame.free(), returnsNormally);
|
||||
});
|
||||
|
||||
test('returns string representation of BlameHunk object', () {
|
||||
final blame = Blame.file(repo: repo, path: 'feature_file');
|
||||
expect(blame.toString(), contains('BlameHunk{'));
|
||||
blame.free();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -26,9 +26,7 @@ void main() {
|
|||
|
||||
group('Blob', () {
|
||||
test('lookups blob with provided oid', () {
|
||||
final blob = Blob.lookup(repo: repo, oid: repo[blobSHA]);
|
||||
expect(blob, isA<Blob>());
|
||||
blob.free();
|
||||
expect(Blob.lookup(repo: repo, oid: repo[blobSHA]), isA<Blob>());
|
||||
});
|
||||
|
||||
test('throws when trying to lookup with invalid oid', () {
|
||||
|
@ -45,8 +43,6 @@ void main() {
|
|||
expect(blob.isBinary, false);
|
||||
expect(blob.size, 13);
|
||||
expect(blob.content, blobContent);
|
||||
|
||||
blob.free();
|
||||
});
|
||||
|
||||
test('creates new blob with provided content', () {
|
||||
|
@ -57,14 +53,11 @@ void main() {
|
|||
expect(newBlob.isBinary, false);
|
||||
expect(newBlob.size, 9);
|
||||
expect(newBlob.content, newBlobContent);
|
||||
|
||||
newBlob.free();
|
||||
});
|
||||
|
||||
test('throws when trying to create new blob and error occurs', () {
|
||||
final nullRepo = Repository(nullptr);
|
||||
expect(
|
||||
() => Blob.create(repo: nullRepo, content: ''),
|
||||
() => Blob.create(repo: Repository(nullptr), content: ''),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
});
|
||||
|
@ -80,8 +73,6 @@ void main() {
|
|||
expect(newBlob.isBinary, false);
|
||||
expect(newBlob.size, 13);
|
||||
expect(newBlob.content, blobContent);
|
||||
|
||||
newBlob.free();
|
||||
});
|
||||
|
||||
test('throws when creating new blob from invalid path', () {
|
||||
|
@ -103,8 +94,6 @@ void main() {
|
|||
|
||||
expect(newBlob, isA<Blob>());
|
||||
expect(newBlob.isBinary, false);
|
||||
|
||||
newBlob.free();
|
||||
});
|
||||
|
||||
test('throws when trying to create from invalid path', () {
|
||||
|
@ -119,9 +108,6 @@ void main() {
|
|||
final dupBlob = blob.duplicate();
|
||||
|
||||
expect(blob.oid.sha, dupBlob.oid.sha);
|
||||
|
||||
dupBlob.free();
|
||||
blob.free();
|
||||
});
|
||||
|
||||
test('filters content of a blob', () {
|
||||
|
@ -129,8 +115,6 @@ void main() {
|
|||
final blob = Blob.lookup(repo: repo, oid: blobOid);
|
||||
|
||||
expect(blob.filterContent(asPath: 'file.crlf'), 'clrf\r\nclrf\r\n');
|
||||
|
||||
blob.free();
|
||||
});
|
||||
|
||||
test('filters content of a blob with provided commit for attributes', () {
|
||||
|
@ -152,9 +136,6 @@ void main() {
|
|||
),
|
||||
'clrf\r\nclrf\r\n',
|
||||
);
|
||||
|
||||
commit.free();
|
||||
blob.free();
|
||||
});
|
||||
|
||||
test('throws when trying to filter content of a blob and error occurs', () {
|
||||
|
@ -164,10 +145,14 @@ void main() {
|
|||
);
|
||||
});
|
||||
|
||||
test('manually releases allocated memory', () {
|
||||
final blob = Blob.lookup(repo: repo, oid: repo[blobSHA]);
|
||||
expect(() => blob.free(), returnsNormally);
|
||||
});
|
||||
|
||||
test('returns string representation of Blob object', () {
|
||||
final blob = Blob.lookup(repo: repo, oid: repo[blobSHA]);
|
||||
expect(blob.toString(), contains('Blob{'));
|
||||
blob.free();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -34,8 +34,6 @@ void main() {
|
|||
for (var i = 0; i < branches.length; i++) {
|
||||
expect(branches[i].name, branchesExpected[i]);
|
||||
expect(aliasBranches[i].name, branchesExpected[i]);
|
||||
branches[i].free();
|
||||
aliasBranches[i].free();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -47,8 +45,6 @@ void main() {
|
|||
for (var i = 0; i < branches.length; i++) {
|
||||
expect(branches[i].name, branchesExpected[i]);
|
||||
expect(aliasBranches[i].name, branchesExpected[i]);
|
||||
branches[i].free();
|
||||
aliasBranches[i].free();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -60,8 +56,6 @@ void main() {
|
|||
for (var i = 0; i < branches.length; i++) {
|
||||
expect(branches[i].name, branchesExpected[i]);
|
||||
expect(aliasBranches[i].name, branchesExpected[i]);
|
||||
branches[i].free();
|
||||
aliasBranches[i].free();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -75,7 +69,6 @@ void main() {
|
|||
test('returns a branch with provided name', () {
|
||||
final branch = Branch.lookup(repo: repo, name: 'master');
|
||||
expect(branch.target.sha, lastCommit.sha);
|
||||
branch.free();
|
||||
});
|
||||
|
||||
test('throws when provided name not found', () {
|
||||
|
@ -95,88 +88,66 @@ void main() {
|
|||
});
|
||||
|
||||
test('checks if branch is current head', () {
|
||||
final masterBranch = Branch.lookup(repo: repo, name: 'master');
|
||||
final featureBranch = Branch.lookup(repo: repo, name: 'feature');
|
||||
|
||||
expect(masterBranch.isHead, true);
|
||||
expect(featureBranch.isHead, false);
|
||||
|
||||
masterBranch.free();
|
||||
featureBranch.free();
|
||||
expect(Branch.lookup(repo: repo, name: 'master').isHead, true);
|
||||
expect(Branch.lookup(repo: repo, name: 'feature').isHead, false);
|
||||
});
|
||||
|
||||
test('throws when checking if branch is current head and error occurs', () {
|
||||
final nullBranch = Branch(nullptr);
|
||||
expect(
|
||||
() => nullBranch.isHead,
|
||||
() => Branch(nullptr).isHead,
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
});
|
||||
|
||||
test('checks if branch is checked out', () {
|
||||
final masterBranch = Branch.lookup(repo: repo, name: 'master');
|
||||
final featureBranch = Branch.lookup(repo: repo, name: 'feature');
|
||||
|
||||
expect(masterBranch.isCheckedOut, true);
|
||||
expect(featureBranch.isCheckedOut, false);
|
||||
|
||||
masterBranch.free();
|
||||
featureBranch.free();
|
||||
expect(Branch.lookup(repo: repo, name: 'master').isCheckedOut, true);
|
||||
expect(Branch.lookup(repo: repo, name: 'feature').isCheckedOut, false);
|
||||
});
|
||||
|
||||
test('throws when checking if branch is checked out and error occurs', () {
|
||||
final nullBranch = Branch(nullptr);
|
||||
expect(
|
||||
() => nullBranch.isCheckedOut,
|
||||
() => Branch(nullptr).isCheckedOut,
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
});
|
||||
|
||||
test('returns name', () {
|
||||
final branch = Branch.lookup(repo: repo, name: 'master');
|
||||
expect(branch.name, 'master');
|
||||
branch.free();
|
||||
expect(Branch.lookup(repo: repo, name: 'master').name, 'master');
|
||||
});
|
||||
|
||||
test('throws when getting name and error occurs', () {
|
||||
final nullBranch = Branch(nullptr);
|
||||
expect(() => nullBranch.name, throwsA(isA<LibGit2Error>()));
|
||||
expect(() => Branch(nullptr).name, throwsA(isA<LibGit2Error>()));
|
||||
});
|
||||
|
||||
test('returns remote name of a remote-tracking branch', () {
|
||||
final branch = Branch.list(repo: repo, type: GitBranch.remote).first;
|
||||
expect(branch.remoteName, 'origin');
|
||||
branch.free();
|
||||
});
|
||||
|
||||
test(
|
||||
'throws when getting remote name of a remote-tracking branch and '
|
||||
'error occurs', () {
|
||||
final branch = Branch.lookup(repo: repo, name: 'master');
|
||||
expect(() => branch.remoteName, throwsA(isA<LibGit2Error>()));
|
||||
expect(
|
||||
() => Branch.lookup(repo: repo, name: 'master').remoteName,
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
});
|
||||
|
||||
test('returns upstream of a local branch', () {
|
||||
final branch = Branch.lookup(repo: repo, name: 'master');
|
||||
final upstream = branch.upstream;
|
||||
final upstream = Branch.lookup(repo: repo, name: 'master').upstream;
|
||||
|
||||
expect(upstream.isRemote, true);
|
||||
expect(upstream.name, 'refs/remotes/origin/master');
|
||||
|
||||
upstream.free();
|
||||
branch.free();
|
||||
});
|
||||
|
||||
test('throws when trying to get upstream of a remote branch', () {
|
||||
final branch = Branch.list(repo: repo, type: GitBranch.remote).first;
|
||||
expect(() => branch.upstream, throwsA(isA<LibGit2Error>()));
|
||||
branch.free();
|
||||
});
|
||||
|
||||
test('sets upstream of a branch', () {
|
||||
final branch = Branch.lookup(repo: repo, name: 'master');
|
||||
var upstream = branch.upstream;
|
||||
expect(upstream.name, 'refs/remotes/origin/master');
|
||||
expect(branch.upstream.name, 'refs/remotes/origin/master');
|
||||
|
||||
final ref = Reference.create(
|
||||
repo: repo,
|
||||
|
@ -185,24 +156,15 @@ void main() {
|
|||
);
|
||||
branch.setUpstream(ref.shorthand);
|
||||
|
||||
upstream = branch.upstream;
|
||||
expect(upstream.name, 'refs/remotes/origin/new');
|
||||
|
||||
ref.free();
|
||||
upstream.free();
|
||||
branch.free();
|
||||
expect(branch.upstream.name, 'refs/remotes/origin/new');
|
||||
});
|
||||
|
||||
test('unsets upstream of a branch', () {
|
||||
final branch = Branch.lookup(repo: repo, name: 'master');
|
||||
final upstream = branch.upstream;
|
||||
expect(upstream.name, 'refs/remotes/origin/master');
|
||||
expect(branch.upstream.name, 'refs/remotes/origin/master');
|
||||
|
||||
branch.setUpstream(null);
|
||||
expect(() => branch.upstream, throwsA(isA<LibGit2Error>()));
|
||||
|
||||
upstream.free();
|
||||
branch.free();
|
||||
});
|
||||
|
||||
test('throws when trying to set upstream of a branch and error occurs', () {
|
||||
|
@ -211,64 +173,61 @@ void main() {
|
|||
() => branch.setUpstream('some/upstream'),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
branch.free();
|
||||
});
|
||||
|
||||
test('returns upstream name of a local branch', () {
|
||||
final branch = Branch.lookup(repo: repo, name: 'master');
|
||||
expect(branch.upstreamName, 'refs/remotes/origin/master');
|
||||
branch.free();
|
||||
expect(
|
||||
Branch.lookup(repo: repo, name: 'master').upstreamName,
|
||||
'refs/remotes/origin/master',
|
||||
);
|
||||
});
|
||||
|
||||
test('throws when trying to get upstream name of a branch and error occurs',
|
||||
() {
|
||||
final branch = Branch.lookup(repo: repo, name: 'feature');
|
||||
expect(() => branch.upstreamName, throwsA(isA<LibGit2Error>()));
|
||||
branch.free();
|
||||
expect(
|
||||
() => Branch.lookup(repo: repo, name: 'feature').upstreamName,
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
});
|
||||
|
||||
test('returns upstream remote of a local branch', () {
|
||||
final branch = Branch.lookup(repo: repo, name: 'master');
|
||||
expect(branch.upstreamRemote, 'origin');
|
||||
branch.free();
|
||||
expect(
|
||||
Branch.lookup(repo: repo, name: 'master').upstreamRemote,
|
||||
'origin',
|
||||
);
|
||||
});
|
||||
|
||||
test('throws when trying to get upstream remote of a remote branch', () {
|
||||
final branch = Branch.list(repo: repo, type: GitBranch.remote).first;
|
||||
expect(() => branch.upstreamRemote, throwsA(isA<LibGit2Error>()));
|
||||
branch.free();
|
||||
expect(
|
||||
() => Branch.list(repo: repo, type: GitBranch.remote)
|
||||
.first
|
||||
.upstreamRemote,
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
});
|
||||
|
||||
test('returns upstream merge of a local branch', () {
|
||||
final branch = Branch.lookup(repo: repo, name: 'master');
|
||||
expect(branch.upstreamMerge, 'refs/heads/master');
|
||||
branch.free();
|
||||
expect(
|
||||
Branch.lookup(repo: repo, name: 'master').upstreamMerge,
|
||||
'refs/heads/master',
|
||||
);
|
||||
});
|
||||
|
||||
test('throws when trying to get upstream merge of a remote branch', () {
|
||||
final branch = Branch.list(repo: repo, type: GitBranch.remote).first;
|
||||
expect(() => branch.upstreamMerge, throwsA(isA<LibGit2Error>()));
|
||||
branch.free();
|
||||
});
|
||||
|
||||
group('create()', () {
|
||||
test('creates branch', () {
|
||||
final commit = Commit.lookup(repo: repo, oid: lastCommit);
|
||||
final branch = Branch.create(
|
||||
repo: repo,
|
||||
name: 'testing',
|
||||
target: commit,
|
||||
target: Commit.lookup(repo: repo, oid: lastCommit),
|
||||
);
|
||||
final branches = Branch.list(repo: repo);
|
||||
|
||||
expect(branches.length, 4);
|
||||
expect(Branch.list(repo: repo).length, 4);
|
||||
expect(branch.target, lastCommit);
|
||||
|
||||
for (final branch in branches) {
|
||||
branch.free();
|
||||
}
|
||||
branch.free();
|
||||
commit.free();
|
||||
});
|
||||
|
||||
test('throws when name already exists', () {
|
||||
|
@ -278,28 +237,18 @@ void main() {
|
|||
() => Branch.create(repo: repo, name: 'feature', target: commit),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
|
||||
commit.free();
|
||||
});
|
||||
|
||||
test('creates branch with force flag when name already exists', () {
|
||||
final commit = Commit.lookup(repo: repo, oid: lastCommit);
|
||||
final branch = Branch.create(
|
||||
repo: repo,
|
||||
name: 'feature',
|
||||
target: commit,
|
||||
target: Commit.lookup(repo: repo, oid: lastCommit),
|
||||
force: true,
|
||||
);
|
||||
final localBranches = Branch.list(repo: repo, type: GitBranch.local);
|
||||
|
||||
expect(localBranches.length, 2);
|
||||
expect(Branch.list(repo: repo, type: GitBranch.local).length, 2);
|
||||
expect(branch.target, lastCommit);
|
||||
|
||||
for (final branch in localBranches) {
|
||||
branch.free();
|
||||
}
|
||||
branch.free();
|
||||
commit.free();
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -324,20 +273,16 @@ void main() {
|
|||
group('rename()', () {
|
||||
test('renames branch', () {
|
||||
Branch.rename(repo: repo, oldName: 'feature', newName: 'renamed');
|
||||
final branch = Branch.lookup(repo: repo, name: 'renamed');
|
||||
final branches = Branch.list(repo: repo);
|
||||
|
||||
expect(branches.length, 3);
|
||||
expect(Branch.list(repo: repo).length, 3);
|
||||
expect(
|
||||
() => Branch.lookup(repo: repo, name: 'feature'),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
expect(branch.target, featureCommit);
|
||||
|
||||
for (final branch in branches) {
|
||||
branch.free();
|
||||
}
|
||||
branch.free();
|
||||
expect(
|
||||
Branch.lookup(repo: repo, name: 'renamed').target,
|
||||
featureCommit,
|
||||
);
|
||||
});
|
||||
|
||||
test('throws when name already exists', () {
|
||||
|
@ -358,11 +303,8 @@ void main() {
|
|||
newName: 'feature',
|
||||
force: true,
|
||||
);
|
||||
final branch = Branch.lookup(repo: repo, name: 'feature');
|
||||
|
||||
expect(branch.target, lastCommit);
|
||||
|
||||
branch.free();
|
||||
expect(Branch.lookup(repo: repo, name: 'feature').target, lastCommit);
|
||||
});
|
||||
|
||||
test('throws when name is invalid', () {
|
||||
|
@ -377,10 +319,14 @@ void main() {
|
|||
});
|
||||
});
|
||||
|
||||
test('manually releases allocated memory', () {
|
||||
final branch = Branch.lookup(repo: repo, name: 'master');
|
||||
expect(() => branch.free(), returnsNormally);
|
||||
});
|
||||
|
||||
test('returns string representation of Branch object', () {
|
||||
final branch = Branch.lookup(repo: repo, name: 'master');
|
||||
expect(branch.toString(), contains('Branch{'));
|
||||
branch.free();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -72,8 +72,7 @@ void main() {
|
|||
});
|
||||
|
||||
test('checkouts reference', () {
|
||||
final masterHead = Commit.lookup(repo: repo, oid: repo['821ed6e']);
|
||||
final masterTree = masterHead.tree;
|
||||
final masterTree = Commit.lookup(repo: repo, oid: repo['821ed6e']).tree;
|
||||
expect(
|
||||
masterTree.entries.any((e) => e.name == 'another_feature_file'),
|
||||
false,
|
||||
|
@ -82,19 +81,12 @@ void main() {
|
|||
Checkout.reference(repo: repo, name: 'refs/heads/feature');
|
||||
final featureHead = Commit.lookup(repo: repo, oid: repo['5aecfa0']);
|
||||
final featureTree = featureHead.tree;
|
||||
final repoHead = repo.head;
|
||||
// does not change HEAD
|
||||
expect(repoHead.target, isNot(featureHead.oid));
|
||||
expect(repo.head.target, isNot(featureHead.oid));
|
||||
expect(
|
||||
featureTree.entries.any((e) => e.name == 'another_feature_file'),
|
||||
true,
|
||||
);
|
||||
|
||||
repoHead.free();
|
||||
featureTree.free();
|
||||
featureHead.free();
|
||||
masterTree.free();
|
||||
masterHead.free();
|
||||
});
|
||||
|
||||
test(
|
||||
|
@ -111,20 +103,14 @@ void main() {
|
|||
});
|
||||
|
||||
test('checkouts commit', () {
|
||||
final index = repo.index;
|
||||
expect(index.find('another_feature_file'), equals(false));
|
||||
expect(repo.index.find('another_feature_file'), equals(false));
|
||||
|
||||
final featureHead = Commit.lookup(repo: repo, oid: repo['5aecfa0']);
|
||||
Checkout.commit(repo: repo, commit: featureHead);
|
||||
|
||||
final repoHead = repo.head;
|
||||
// does not change HEAD
|
||||
expect(repoHead.target, isNot(featureHead.oid));
|
||||
expect(index.find('another_feature_file'), equals(true));
|
||||
|
||||
repoHead.free();
|
||||
featureHead.free();
|
||||
index.free();
|
||||
expect(repo.head.target, isNot(featureHead.oid));
|
||||
expect(repo.index.find('another_feature_file'), equals(true));
|
||||
});
|
||||
|
||||
test('checkouts commit with provided path', () {
|
||||
|
@ -135,35 +121,27 @@ void main() {
|
|||
paths: ['another_feature_file'],
|
||||
);
|
||||
|
||||
final repoHead = repo.head;
|
||||
// does not change HEAD
|
||||
expect(repoHead.target, isNot(featureHead.oid));
|
||||
expect(repo.head.target, isNot(featureHead.oid));
|
||||
expect(
|
||||
repo.status,
|
||||
{
|
||||
'another_feature_file': {GitStatus.indexNew}
|
||||
},
|
||||
);
|
||||
|
||||
repoHead.free();
|
||||
featureHead.free();
|
||||
});
|
||||
|
||||
test(
|
||||
'throws when trying to checkout commit with invalid alternative '
|
||||
'directory', () {
|
||||
final commit = Commit.lookup(repo: repo, oid: repo['5aecfa0']);
|
||||
|
||||
expect(
|
||||
() => Checkout.commit(
|
||||
repo: repo,
|
||||
commit: commit,
|
||||
commit: Commit.lookup(repo: repo, oid: repo['5aecfa0']),
|
||||
directory: 'not/there',
|
||||
),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
|
||||
commit.free();
|
||||
});
|
||||
|
||||
test('checkouts with alrenative directory', () {
|
||||
|
@ -208,8 +186,7 @@ void main() {
|
|||
});
|
||||
|
||||
test('performs dry run checkout', () {
|
||||
final index = repo.index;
|
||||
expect(index.length, 4);
|
||||
expect(repo.index.length, 4);
|
||||
final file = File(p.join(repo.workdir, 'another_feature_file'));
|
||||
expect(file.existsSync(), false);
|
||||
|
||||
|
@ -218,10 +195,8 @@ void main() {
|
|||
name: 'refs/heads/feature',
|
||||
strategy: {GitCheckout.dryRun},
|
||||
);
|
||||
expect(index.length, 4);
|
||||
expect(repo.index.length, 4);
|
||||
expect(file.existsSync(), false);
|
||||
|
||||
index.free();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -34,18 +34,13 @@ void main() {
|
|||
});
|
||||
|
||||
tearDown(() {
|
||||
author.free();
|
||||
committer.free();
|
||||
tree.free();
|
||||
repo.free();
|
||||
tmpDir.deleteSync(recursive: true);
|
||||
});
|
||||
|
||||
group('Commit', () {
|
||||
test('lookups commit for provided oid', () {
|
||||
final commit = Commit.lookup(repo: repo, oid: tip);
|
||||
expect(commit, isA<Commit>());
|
||||
commit.free();
|
||||
expect(Commit.lookup(repo: repo, oid: tip), isA<Commit>());
|
||||
});
|
||||
|
||||
test('throws when trying to lookup with invalid oid', () {
|
||||
|
@ -63,18 +58,14 @@ void main() {
|
|||
|
||||
test('reverts commit affecting index and workdir', () {
|
||||
final commit = Commit.lookup(repo: repo, oid: repo['821ed6e']);
|
||||
final index = repo.index;
|
||||
final file = File(p.join(repo.workdir, 'dir', 'dir_file.txt'));
|
||||
expect(index.find('dir/dir_file.txt'), true);
|
||||
expect(repo.index.find('dir/dir_file.txt'), true);
|
||||
expect(file.existsSync(), true);
|
||||
|
||||
commit.revert();
|
||||
|
||||
expect(index.find('dir/dir_file.txt'), false);
|
||||
expect(repo.index.find('dir/dir_file.txt'), false);
|
||||
expect(file.existsSync(), false);
|
||||
|
||||
index.free();
|
||||
commit.free();
|
||||
});
|
||||
|
||||
test('throws when trying to revert and error occurs', () {
|
||||
|
@ -82,21 +73,16 @@ void main() {
|
|||
});
|
||||
|
||||
test('reverts commit to provided commit', () {
|
||||
final to = Commit.lookup(repo: repo, oid: repo['78b8bf1']);
|
||||
final from = Commit.lookup(repo: repo, oid: repo['821ed6e']);
|
||||
final index = repo.index;
|
||||
final file = File(p.join(repo.workdir, 'dir', 'dir_file.txt'));
|
||||
expect(index.find('dir/dir_file.txt'), true);
|
||||
expect(repo.index.find('dir/dir_file.txt'), true);
|
||||
expect(file.existsSync(), true);
|
||||
|
||||
final revertIndex = from.revertTo(commit: to);
|
||||
final from = Commit.lookup(repo: repo, oid: repo['821ed6e']);
|
||||
final revertIndex = from.revertTo(
|
||||
commit: Commit.lookup(repo: repo, oid: repo['78b8bf1']),
|
||||
);
|
||||
expect(revertIndex.find('dir/dir_file.txt'), false);
|
||||
expect(file.existsSync(), true);
|
||||
|
||||
revertIndex.free();
|
||||
index.free();
|
||||
to.free();
|
||||
from.free();
|
||||
});
|
||||
|
||||
test('throws when trying to revert commit and error occurs', () {
|
||||
|
@ -114,13 +100,9 @@ void main() {
|
|||
expect(commit1.descendantOf(commit2.oid), true);
|
||||
expect(commit1.descendantOf(commit1.oid), false);
|
||||
expect(commit2.descendantOf(commit1.oid), false);
|
||||
|
||||
commit1.free();
|
||||
commit2.free();
|
||||
});
|
||||
|
||||
test('creates commit', () {
|
||||
final parent = Commit.lookup(repo: repo, oid: tip);
|
||||
final oid = Commit.create(
|
||||
repo: repo,
|
||||
updateRef: 'HEAD',
|
||||
|
@ -128,7 +110,7 @@ void main() {
|
|||
author: author,
|
||||
committer: committer,
|
||||
tree: tree,
|
||||
parents: [parent],
|
||||
parents: [Commit.lookup(repo: repo, oid: tip)],
|
||||
);
|
||||
|
||||
final commit = Commit.lookup(repo: repo, oid: oid);
|
||||
|
@ -146,13 +128,9 @@ void main() {
|
|||
expect(commit.treeOid, tree.oid);
|
||||
expect(commit.parents.length, 1);
|
||||
expect(commit.parents[0], tip);
|
||||
|
||||
commit.free();
|
||||
parent.free();
|
||||
});
|
||||
|
||||
test('writes commit without parents into the buffer', () {
|
||||
final parent = Commit.lookup(repo: repo, oid: tip);
|
||||
final commit = Commit.createBuffer(
|
||||
repo: repo,
|
||||
updateRef: 'HEAD',
|
||||
|
@ -174,12 +152,9 @@ Some description.
|
|||
""";
|
||||
|
||||
expect(commit, expected);
|
||||
|
||||
parent.free();
|
||||
});
|
||||
|
||||
test('writes commit into the buffer', () {
|
||||
final parent = Commit.lookup(repo: repo, oid: tip);
|
||||
final commit = Commit.createBuffer(
|
||||
repo: repo,
|
||||
updateRef: 'HEAD',
|
||||
|
@ -187,7 +162,7 @@ Some description.
|
|||
author: author,
|
||||
committer: committer,
|
||||
tree: tree,
|
||||
parents: [parent],
|
||||
parents: [Commit.lookup(repo: repo, oid: tip)],
|
||||
);
|
||||
|
||||
const expected = """
|
||||
|
@ -202,8 +177,6 @@ Some description.
|
|||
""";
|
||||
|
||||
expect(commit, expected);
|
||||
|
||||
parent.free();
|
||||
});
|
||||
|
||||
test('creates commit without parents', () {
|
||||
|
@ -227,8 +200,6 @@ Some description.
|
|||
expect(commit.time, 124);
|
||||
expect(commit.treeOid, tree.oid);
|
||||
expect(commit.parents.length, 0);
|
||||
|
||||
commit.free();
|
||||
});
|
||||
|
||||
test('creates commit with 2 parents', () {
|
||||
|
@ -255,59 +226,44 @@ Some description.
|
|||
expect(commit.time, 124);
|
||||
expect(commit.treeOid, tree.oid);
|
||||
expect(commit.parents.length, 2);
|
||||
expect(commit.parents[0], tip);
|
||||
expect(commit.parents[0], parent1.oid);
|
||||
expect(commit.parents[1], parent2.oid);
|
||||
|
||||
parent1.free();
|
||||
parent2.free();
|
||||
commit.free();
|
||||
});
|
||||
|
||||
test('throws when trying to create commit and error occurs', () {
|
||||
final parent = Commit.lookup(repo: repo, oid: tip);
|
||||
final nullRepo = Repository(nullptr);
|
||||
|
||||
expect(
|
||||
() => Commit.create(
|
||||
repo: nullRepo,
|
||||
repo: Repository(nullptr),
|
||||
updateRef: 'HEAD',
|
||||
message: message,
|
||||
author: author,
|
||||
committer: committer,
|
||||
tree: tree,
|
||||
parents: [parent],
|
||||
parents: [Commit.lookup(repo: repo, oid: tip)],
|
||||
),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
|
||||
parent.free();
|
||||
});
|
||||
|
||||
test('throws when trying to write commit into a buffer and error occurs',
|
||||
() {
|
||||
final parent = Commit.lookup(repo: repo, oid: tip);
|
||||
final nullRepo = Repository(nullptr);
|
||||
|
||||
expect(
|
||||
() => Commit.createBuffer(
|
||||
repo: nullRepo,
|
||||
repo: Repository(nullptr),
|
||||
updateRef: 'HEAD',
|
||||
message: message,
|
||||
author: author,
|
||||
committer: committer,
|
||||
tree: tree,
|
||||
parents: [parent],
|
||||
parents: [Commit.lookup(repo: repo, oid: tip)],
|
||||
),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
|
||||
parent.free();
|
||||
});
|
||||
|
||||
test('amends commit with default arguments', () {
|
||||
final oldHead = repo.head;
|
||||
final commit = Commit.lookup(repo: repo, oid: repo['821ed6e']);
|
||||
expect(commit.oid, oldHead.target);
|
||||
expect(commit.oid, repo.head.target);
|
||||
|
||||
final amendedOid = Commit.amend(
|
||||
repo: repo,
|
||||
|
@ -316,25 +272,18 @@ Some description.
|
|||
updateRef: 'HEAD',
|
||||
);
|
||||
final amendedCommit = Commit.lookup(repo: repo, oid: amendedOid);
|
||||
final newHead = repo.head;
|
||||
|
||||
expect(amendedCommit.oid, newHead.target);
|
||||
expect(amendedCommit.oid, repo.head.target);
|
||||
expect(amendedCommit.message, 'amended commit\n');
|
||||
expect(amendedCommit.author, commit.author);
|
||||
expect(amendedCommit.committer, commit.committer);
|
||||
expect(amendedCommit.treeOid, commit.treeOid);
|
||||
expect(amendedCommit.parents, commit.parents);
|
||||
|
||||
amendedCommit.free();
|
||||
commit.free();
|
||||
newHead.free();
|
||||
oldHead.free();
|
||||
});
|
||||
|
||||
test('amends commit with provided arguments', () {
|
||||
final oldHead = repo.head;
|
||||
final commit = Commit.lookup(repo: repo, oid: repo['821ed6e']);
|
||||
expect(commit.oid, oldHead.target);
|
||||
expect(commit.oid, repo.head.target);
|
||||
|
||||
final amendedOid = Commit.amend(
|
||||
repo: repo,
|
||||
|
@ -346,25 +295,18 @@ Some description.
|
|||
tree: tree,
|
||||
);
|
||||
final amendedCommit = Commit.lookup(repo: repo, oid: amendedOid);
|
||||
final newHead = repo.head;
|
||||
|
||||
expect(amendedCommit.oid, newHead.target);
|
||||
expect(amendedCommit.oid, repo.head.target);
|
||||
expect(amendedCommit.message, 'amended commit\n');
|
||||
expect(amendedCommit.author, author);
|
||||
expect(amendedCommit.committer, committer);
|
||||
expect(amendedCommit.treeOid, tree.oid);
|
||||
expect(amendedCommit.parents, commit.parents);
|
||||
|
||||
amendedCommit.free();
|
||||
commit.free();
|
||||
newHead.free();
|
||||
oldHead.free();
|
||||
});
|
||||
|
||||
test('amends commit that is not the tip of the branch', () {
|
||||
final head = repo.head;
|
||||
final commit = Commit.lookup(repo: repo, oid: repo['78b8bf1']);
|
||||
expect(commit.oid, isNot(head.target));
|
||||
expect(commit.oid, isNot(repo.head.target));
|
||||
|
||||
expect(
|
||||
() => Commit.amend(
|
||||
|
@ -375,17 +317,13 @@ Some description.
|
|||
),
|
||||
returnsNormally,
|
||||
);
|
||||
|
||||
commit.free();
|
||||
head.free();
|
||||
});
|
||||
|
||||
test(
|
||||
'throws when trying to amend commit that is not the tip of the branch '
|
||||
'with HEAD provided as update reference', () {
|
||||
final head = repo.head;
|
||||
final commit = Commit.lookup(repo: repo, oid: repo['78b8bf1']);
|
||||
expect(commit.oid, isNot(head.target));
|
||||
expect(commit.oid, isNot(repo.head.target));
|
||||
|
||||
expect(
|
||||
() => Commit.amend(
|
||||
|
@ -396,9 +334,6 @@ Some description.
|
|||
),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
|
||||
commit.free();
|
||||
head.free();
|
||||
});
|
||||
|
||||
test('creates an in-memory copy of a commit', () {
|
||||
|
@ -406,9 +341,6 @@ Some description.
|
|||
final dupCommit = commit.duplicate();
|
||||
|
||||
expect(dupCommit.oid, commit.oid);
|
||||
|
||||
dupCommit.free();
|
||||
commit.free();
|
||||
});
|
||||
|
||||
test('returns header field', () {
|
||||
|
@ -417,7 +349,6 @@ Some description.
|
|||
commit.headerField('parent'),
|
||||
'78b8bf123e3952c970ae5c1ce0a3ea1d1336f6e8',
|
||||
);
|
||||
commit.free();
|
||||
});
|
||||
|
||||
test('throws when header field not found', () {
|
||||
|
@ -426,24 +357,19 @@ Some description.
|
|||
() => commit.headerField('not-there'),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
commit.free();
|
||||
});
|
||||
|
||||
test('returns nth generation ancestor commit', () {
|
||||
final commit = Commit.lookup(repo: repo, oid: tip);
|
||||
final ancestor = commit.nthGenAncestor(3);
|
||||
|
||||
final ancestor = Commit.lookup(repo: repo, oid: tip).nthGenAncestor(3);
|
||||
expect(ancestor.oid.sha, 'f17d0d48eae3aa08cecf29128a35e310c97b3521');
|
||||
|
||||
ancestor.free();
|
||||
commit.free();
|
||||
});
|
||||
|
||||
test('throws when trying to get nth generation ancestor and none exists',
|
||||
() {
|
||||
final commit = Commit.lookup(repo: repo, oid: tip);
|
||||
expect(() => commit.nthGenAncestor(10), throwsA(isA<LibGit2Error>()));
|
||||
commit.free();
|
||||
expect(
|
||||
() => Commit.lookup(repo: repo, oid: tip).nthGenAncestor(10),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
});
|
||||
|
||||
test('returns parent at specified position', () {
|
||||
|
@ -453,22 +379,23 @@ Some description.
|
|||
|
||||
expect(firstParent.oid.sha, 'c68ff54aabf660fcdd9a2838d401583fe31249e3');
|
||||
expect(secondParent.oid.sha, 'fc38877b2552ab554752d9a77e1f48f738cca79b');
|
||||
|
||||
secondParent.free();
|
||||
firstParent.free();
|
||||
commit.free();
|
||||
});
|
||||
|
||||
test('throws when trying to get the parent at invalid position', () {
|
||||
expect(
|
||||
() => Commit.lookup(repo: repo, oid: tip).parent(10),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
});
|
||||
|
||||
test('manually releases allocated memory', () {
|
||||
final commit = Commit.lookup(repo: repo, oid: tip);
|
||||
expect(() => commit.parent(10), throwsA(isA<LibGit2Error>()));
|
||||
commit.free();
|
||||
expect(() => commit.free(), returnsNormally);
|
||||
});
|
||||
|
||||
test('returns string representation of Commit object', () {
|
||||
final commit = Commit.lookup(repo: repo, oid: tip);
|
||||
expect(commit.toString(), contains('Commit{'));
|
||||
commit.free();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -32,7 +32,6 @@ void main() {
|
|||
});
|
||||
|
||||
tearDown(() {
|
||||
config.free();
|
||||
File(filePath).deleteSync();
|
||||
});
|
||||
|
||||
|
@ -45,9 +44,7 @@ void main() {
|
|||
'opens the global, XDG and system configuration files '
|
||||
'(if they are present) if no path provided', () {
|
||||
try {
|
||||
final config = Config.open();
|
||||
expect(config, isA<Config>());
|
||||
config.free();
|
||||
expect(Config.open(), isA<Config>());
|
||||
} catch (e) {
|
||||
expect(() => Config.open(), throwsA(isA<LibGit2Error>()));
|
||||
}
|
||||
|
@ -59,9 +56,7 @@ void main() {
|
|||
|
||||
test('opens system file or throws is there is none', () {
|
||||
try {
|
||||
final config = Config.system();
|
||||
expect(config, isA<Config>());
|
||||
config.free();
|
||||
expect(Config.system(), isA<Config>());
|
||||
} catch (e) {
|
||||
expect(() => Config.system(), throwsA(isA<LibGit2Error>()));
|
||||
}
|
||||
|
@ -69,9 +64,7 @@ void main() {
|
|||
|
||||
test('opens global file or throws is there is none', () {
|
||||
try {
|
||||
final config = Config.global();
|
||||
expect(config, isA<Config>());
|
||||
config.free();
|
||||
expect(Config.global(), isA<Config>());
|
||||
} catch (e) {
|
||||
expect(() => Config.global(), throwsA(isA<LibGit2Error>()));
|
||||
}
|
||||
|
@ -79,18 +72,14 @@ void main() {
|
|||
|
||||
test('opens xdg file or throws is there is none', () {
|
||||
try {
|
||||
final config = Config.xdg();
|
||||
expect(config, isA<Config>());
|
||||
config.free();
|
||||
expect(Config.xdg(), isA<Config>());
|
||||
} catch (e) {
|
||||
expect(() => Config.xdg(), throwsA(isA<LibGit2Error>()));
|
||||
}
|
||||
});
|
||||
|
||||
test('returns config snapshot', () {
|
||||
final snapshot = config.snapshot;
|
||||
expect(snapshot, isA<Config>());
|
||||
snapshot.free();
|
||||
expect(config.snapshot, isA<Config>());
|
||||
});
|
||||
|
||||
test('returns config entries and their values', () {
|
||||
|
@ -219,6 +208,11 @@ void main() {
|
|||
});
|
||||
});
|
||||
|
||||
test('manually releases allocated memory', () {
|
||||
final config = Config.open(filePath);
|
||||
expect(() => config.free(), returnsNormally);
|
||||
});
|
||||
|
||||
test('returns string representation of ConfigEntry object', () {
|
||||
final entry = config.first;
|
||||
expect(entry.toString(), contains('ConfigEntry{'));
|
||||
|
|
|
@ -27,8 +27,10 @@ void main() {
|
|||
});
|
||||
|
||||
test('throws when trying to describe and error occurs', () {
|
||||
final nullRepo = Repository(nullptr);
|
||||
expect(() => nullRepo.describe(), throwsA(isA<LibGit2Error>()));
|
||||
expect(
|
||||
() => Repository(nullptr).describe(),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
});
|
||||
|
||||
test('describes commit', () {
|
||||
|
@ -41,30 +43,32 @@ void main() {
|
|||
});
|
||||
|
||||
test('throws when trying to describe and no reference found', () {
|
||||
final commit = Commit.lookup(repo: repo, oid: repo['f17d0d4']);
|
||||
expect(() => repo.describe(commit: commit), throwsA(isA<LibGit2Error>()));
|
||||
commit.free();
|
||||
expect(
|
||||
() => repo.describe(
|
||||
commit: Commit.lookup(repo: repo, oid: repo['f17d0d4']),
|
||||
),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
});
|
||||
|
||||
test('returns oid when fallback argument is provided', () {
|
||||
final commit = Commit.lookup(repo: repo, oid: repo['f17d0d4']);
|
||||
expect(
|
||||
repo.describe(commit: commit, showCommitOidAsFallback: true),
|
||||
repo.describe(
|
||||
commit: Commit.lookup(repo: repo, oid: repo['f17d0d4']),
|
||||
showCommitOidAsFallback: true,
|
||||
),
|
||||
'f17d0d4',
|
||||
);
|
||||
commit.free();
|
||||
});
|
||||
|
||||
test('describes with provided strategy', () {
|
||||
final commit = Commit.lookup(repo: repo, oid: repo['5aecfa0']);
|
||||
expect(
|
||||
repo.describe(
|
||||
commit: commit,
|
||||
commit: Commit.lookup(repo: repo, oid: repo['5aecfa0']),
|
||||
describeStrategy: GitDescribeStrategy.all,
|
||||
),
|
||||
'heads/feature',
|
||||
);
|
||||
commit.free();
|
||||
});
|
||||
|
||||
test('describes with provided pattern', () {
|
||||
|
@ -73,7 +77,6 @@ void main() {
|
|||
email: 'author@email.com',
|
||||
time: 1234,
|
||||
);
|
||||
final commit = Commit.lookup(repo: repo, oid: repo['fc38877']);
|
||||
Tag.createAnnotated(
|
||||
repo: repo,
|
||||
tagName: 'test/tag1',
|
||||
|
@ -84,28 +87,25 @@ void main() {
|
|||
);
|
||||
|
||||
expect(
|
||||
repo.describe(commit: commit, pattern: 'test/*'),
|
||||
repo.describe(
|
||||
commit: Commit.lookup(repo: repo, oid: repo['fc38877']),
|
||||
pattern: 'test/*',
|
||||
),
|
||||
'test/tag1-2-gfc38877',
|
||||
);
|
||||
|
||||
commit.free();
|
||||
signature.free();
|
||||
});
|
||||
|
||||
test('describes and follows first parent only', () {
|
||||
final commit = Commit.lookup(repo: repo, oid: repo['821ed6e']);
|
||||
Tag.delete(repo: repo, name: 'v0.2');
|
||||
|
||||
expect(
|
||||
repo.describe(
|
||||
commit: commit,
|
||||
commit: Commit.lookup(repo: repo, oid: repo['821ed6e']),
|
||||
onlyFollowFirstParent: true,
|
||||
describeStrategy: GitDescribeStrategy.tags,
|
||||
),
|
||||
'v0.1-1-g821ed6e',
|
||||
);
|
||||
|
||||
commit.free();
|
||||
});
|
||||
|
||||
test('describes with provided abbreviated size', () {
|
||||
|
@ -129,8 +129,6 @@ void main() {
|
|||
),
|
||||
'v0.1',
|
||||
);
|
||||
|
||||
commit.free();
|
||||
});
|
||||
|
||||
test('describes with long format', () {
|
||||
|
@ -138,21 +136,13 @@ void main() {
|
|||
});
|
||||
|
||||
test('describes and appends dirty suffix', () {
|
||||
final index = repo.index;
|
||||
index.clear();
|
||||
|
||||
repo.index.clear();
|
||||
expect(repo.describe(dirtySuffix: '-dirty'), 'v0.2-dirty');
|
||||
|
||||
index.free();
|
||||
});
|
||||
|
||||
test('describes with max candidates tags flag set', () {
|
||||
final index = repo.index;
|
||||
index.clear();
|
||||
|
||||
repo.index.clear();
|
||||
expect(repo.describe(maxCandidatesTags: 0), 'v0.2');
|
||||
|
||||
index.free();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -128,76 +128,53 @@ index e69de29..c217c63 100644
|
|||
|
||||
tearDown(() {
|
||||
repo.free();
|
||||
tmpDir.deleteSync(recursive: true);
|
||||
if (Platform.isLinux || Platform.isMacOS) {
|
||||
tmpDir.deleteSync(recursive: true);
|
||||
}
|
||||
});
|
||||
|
||||
group('Diff', () {
|
||||
test('returns diff between index and workdir', () {
|
||||
final index = repo.index;
|
||||
final diff = Diff.indexToWorkdir(repo: repo, index: index);
|
||||
final diff = Diff.indexToWorkdir(repo: repo, index: repo.index);
|
||||
|
||||
expect(diff.length, 8);
|
||||
for (var i = 0; i < diff.deltas.length; i++) {
|
||||
expect(diff.deltas[i].newFile.path, indexToWorkdir[i]);
|
||||
}
|
||||
|
||||
diff.free();
|
||||
index.free();
|
||||
});
|
||||
|
||||
test('returns diff between index and tree', () {
|
||||
final index = repo.index;
|
||||
final head = repo.head;
|
||||
final commit = Commit.lookup(repo: repo, oid: head.target);
|
||||
final tree = commit.tree;
|
||||
final diff = Diff.treeToIndex(repo: repo, tree: tree, index: index);
|
||||
final diff = Diff.treeToIndex(
|
||||
repo: repo,
|
||||
tree: Commit.lookup(repo: repo, oid: repo.head.target).tree,
|
||||
index: repo.index,
|
||||
);
|
||||
|
||||
expect(diff.length, 8);
|
||||
for (var i = 0; i < diff.deltas.length; i++) {
|
||||
expect(diff.deltas[i].newFile.path, indexToTree[i]);
|
||||
}
|
||||
|
||||
commit.free();
|
||||
head.free();
|
||||
tree.free();
|
||||
diff.free();
|
||||
index.free();
|
||||
});
|
||||
|
||||
test('returns diff between index and empty tree', () {
|
||||
final index = repo.index;
|
||||
final head = repo.head;
|
||||
final commit = Commit.lookup(repo: repo, oid: head.target);
|
||||
final tree = commit.tree;
|
||||
final diff = Diff.treeToIndex(repo: repo, tree: null, index: index);
|
||||
final diff = Diff.treeToIndex(repo: repo, tree: null, index: repo.index);
|
||||
|
||||
expect(diff.length, 12);
|
||||
for (var i = 0; i < diff.deltas.length; i++) {
|
||||
expect(diff.deltas[i].newFile.path, indexToIndex[i]);
|
||||
}
|
||||
|
||||
commit.free();
|
||||
head.free();
|
||||
tree.free();
|
||||
diff.free();
|
||||
index.free();
|
||||
});
|
||||
|
||||
test('returns diff between tree and workdir', () {
|
||||
final head = repo.head;
|
||||
final commit = Commit.lookup(repo: repo, oid: head.target);
|
||||
final tree = commit.tree;
|
||||
final diff = Diff.treeToWorkdir(repo: repo, tree: tree);
|
||||
final diff = Diff.treeToWorkdir(
|
||||
repo: repo,
|
||||
tree: Commit.lookup(repo: repo, oid: repo.head.target).tree,
|
||||
);
|
||||
|
||||
expect(diff.length, 9);
|
||||
for (var i = 0; i < diff.deltas.length; i++) {
|
||||
expect(diff.deltas[i].newFile.path, treeToWorkdir[i]);
|
||||
}
|
||||
|
||||
commit.free();
|
||||
head.free();
|
||||
tree.free();
|
||||
diff.free();
|
||||
});
|
||||
|
||||
test('throws when trying to diff between tree and workdir and error occurs',
|
||||
|
@ -209,20 +186,15 @@ index e69de29..c217c63 100644
|
|||
});
|
||||
|
||||
test('returns diff between tree and workdir with index', () {
|
||||
final head = repo.head;
|
||||
final commit = Commit.lookup(repo: repo, oid: head.target);
|
||||
final tree = commit.tree;
|
||||
final diff = Diff.treeToWorkdirWithIndex(
|
||||
repo: repo,
|
||||
tree: Commit.lookup(repo: repo, oid: repo.head.target).tree,
|
||||
);
|
||||
|
||||
final diff = Diff.treeToWorkdirWithIndex(repo: repo, tree: tree);
|
||||
expect(diff.length, 11);
|
||||
for (var i = 0; i < diff.deltas.length; i++) {
|
||||
expect(diff.deltas[i].newFile.path, treeToWorkdirWithIndex[i]);
|
||||
}
|
||||
|
||||
diff.free();
|
||||
tree.free();
|
||||
commit.free();
|
||||
head.free();
|
||||
});
|
||||
|
||||
test(
|
||||
|
@ -238,68 +210,51 @@ index e69de29..c217c63 100644
|
|||
});
|
||||
|
||||
test('returns diff between tree and tree', () {
|
||||
final head = repo.head;
|
||||
final commit = Commit.lookup(repo: repo, oid: head.target);
|
||||
final tree1 = commit.tree;
|
||||
final tree2 = Tree.lookup(repo: repo, oid: repo['b85d53c']);
|
||||
final diff = Diff.treeToTree(repo: repo, oldTree: tree1, newTree: tree2);
|
||||
final diff = Diff.treeToTree(
|
||||
repo: repo,
|
||||
oldTree: Commit.lookup(repo: repo, oid: repo.head.target).tree,
|
||||
newTree: Tree.lookup(repo: repo, oid: repo['b85d53c']),
|
||||
);
|
||||
|
||||
expect(diff.length, 10);
|
||||
for (var i = 0; i < diff.deltas.length; i++) {
|
||||
expect(diff.deltas[i].newFile.path, treeToTree[i]);
|
||||
}
|
||||
|
||||
commit.free();
|
||||
head.free();
|
||||
tree1.free();
|
||||
tree2.free();
|
||||
diff.free();
|
||||
});
|
||||
|
||||
test('returns diff between tree and empty tree', () {
|
||||
final head = repo.head;
|
||||
final commit = Commit.lookup(repo: repo, oid: head.target);
|
||||
final tree = commit.tree;
|
||||
|
||||
final diff = Diff.treeToTree(repo: repo, oldTree: tree, newTree: null);
|
||||
final diff = Diff.treeToTree(
|
||||
repo: repo,
|
||||
oldTree: Commit.lookup(repo: repo, oid: repo.head.target).tree,
|
||||
newTree: null,
|
||||
);
|
||||
|
||||
expect(diff.length, 11);
|
||||
for (var i = 0; i < diff.deltas.length; i++) {
|
||||
expect(diff.deltas[i].newFile.path, treeToEmptyTree[i]);
|
||||
}
|
||||
|
||||
commit.free();
|
||||
head.free();
|
||||
tree.free();
|
||||
diff.free();
|
||||
});
|
||||
|
||||
test('returns diff between empty tree and tree', () {
|
||||
final head = repo.head;
|
||||
final commit = Commit.lookup(repo: repo, oid: head.target);
|
||||
final tree = commit.tree;
|
||||
|
||||
final diff = Diff.treeToTree(repo: repo, oldTree: null, newTree: tree);
|
||||
final diff = Diff.treeToTree(
|
||||
repo: repo,
|
||||
oldTree: null,
|
||||
newTree: Commit.lookup(repo: repo, oid: repo.head.target).tree,
|
||||
);
|
||||
|
||||
expect(diff.length, 11);
|
||||
for (var i = 0; i < diff.deltas.length; i++) {
|
||||
expect(diff.deltas[i].newFile.path, treeToEmptyTree[i]);
|
||||
}
|
||||
|
||||
commit.free();
|
||||
head.free();
|
||||
tree.free();
|
||||
diff.free();
|
||||
});
|
||||
|
||||
test('throws when trying to diff between tree and tree and error occurs',
|
||||
() {
|
||||
final nullTree = Tree(nullptr);
|
||||
expect(
|
||||
() => Diff.treeToTree(
|
||||
repo: Repository(nullptr),
|
||||
oldTree: nullTree,
|
||||
newTree: nullTree,
|
||||
oldTree: Tree(nullptr),
|
||||
newTree: Tree(nullptr),
|
||||
),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
|
@ -313,60 +268,44 @@ index e69de29..c217c63 100644
|
|||
});
|
||||
|
||||
test('returns diff between index and index', () {
|
||||
final index = repo.index;
|
||||
final emptyIndex = Index.newInMemory();
|
||||
|
||||
final diff = Diff.indexToIndex(
|
||||
repo: repo,
|
||||
oldIndex: index,
|
||||
newIndex: emptyIndex,
|
||||
oldIndex: repo.index,
|
||||
newIndex: Index.newInMemory(),
|
||||
);
|
||||
|
||||
expect(diff.length, 12);
|
||||
for (var i = 0; i < diff.deltas.length; i++) {
|
||||
expect(diff.deltas[i].newFile.path, indexToIndex[i]);
|
||||
}
|
||||
|
||||
index.free();
|
||||
emptyIndex.free();
|
||||
});
|
||||
|
||||
test('throws when trying to diff between index and index and error occurs',
|
||||
() {
|
||||
final index = repo.index;
|
||||
|
||||
expect(
|
||||
() => Diff.indexToIndex(
|
||||
repo: repo,
|
||||
oldIndex: index,
|
||||
oldIndex: repo.index,
|
||||
newIndex: Index(nullptr),
|
||||
),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
|
||||
index.free();
|
||||
});
|
||||
|
||||
test('merges diffs', () {
|
||||
final head = repo.head;
|
||||
final commit = Commit.lookup(repo: repo, oid: head.target);
|
||||
final tree1 = commit.tree;
|
||||
final tree2 = Tree.lookup(repo: repo, oid: repo['b85d53c']);
|
||||
final diff1 = Diff.treeToTree(repo: repo, oldTree: tree1, newTree: tree2);
|
||||
final diff2 = Diff.treeToWorkdir(repo: repo, tree: tree1);
|
||||
final commit = Commit.lookup(repo: repo, oid: repo.head.target);
|
||||
final diff1 = Diff.treeToTree(
|
||||
repo: repo,
|
||||
oldTree: commit.tree,
|
||||
newTree: Tree.lookup(repo: repo, oid: repo['b85d53c']),
|
||||
);
|
||||
final diff2 = Diff.treeToWorkdir(repo: repo, tree: commit.tree);
|
||||
|
||||
expect(diff1.length, 10);
|
||||
expect(diff2.length, 9);
|
||||
|
||||
diff1.merge(diff2);
|
||||
expect(diff1.length, 11);
|
||||
|
||||
commit.free();
|
||||
head.free();
|
||||
tree1.free();
|
||||
tree2.free();
|
||||
diff1.free();
|
||||
diff2.free();
|
||||
});
|
||||
|
||||
test('parses provided diff', () {
|
||||
|
@ -377,15 +316,11 @@ index e69de29..c217c63 100644
|
|||
expect(stats.filesChanged, 1);
|
||||
expect(stats.insertions, 1);
|
||||
expect(diff.patchOid.sha, '699556913185bc38632ae20a49d5c18b9233335e');
|
||||
|
||||
stats.free();
|
||||
diff.free();
|
||||
});
|
||||
|
||||
group('apply', () {
|
||||
test('checks if diff can be applied to repository', () {
|
||||
final index = repo.index;
|
||||
final diff1 = Diff.indexToWorkdir(repo: repo, index: index);
|
||||
final diff1 = Diff.indexToWorkdir(repo: repo, index: repo.index);
|
||||
expect(
|
||||
diff1.applies(repo: repo, location: GitApplyLocation.both),
|
||||
false,
|
||||
|
@ -397,16 +332,11 @@ index e69de29..c217c63 100644
|
|||
diff2.applies(repo: repo, location: GitApplyLocation.both),
|
||||
true,
|
||||
);
|
||||
|
||||
diff1.free();
|
||||
diff2.free();
|
||||
index.free();
|
||||
});
|
||||
|
||||
test('checks if hunk with provided index can be applied to repository',
|
||||
() {
|
||||
final index = repo.index;
|
||||
final diff1 = Diff.indexToWorkdir(repo: repo, index: index);
|
||||
final diff1 = Diff.indexToWorkdir(repo: repo, index: repo.index);
|
||||
expect(
|
||||
diff1.applies(repo: repo, location: GitApplyLocation.both),
|
||||
false,
|
||||
|
@ -423,23 +353,16 @@ index e69de29..c217c63 100644
|
|||
),
|
||||
true,
|
||||
);
|
||||
|
||||
diff1.free();
|
||||
diff2.free();
|
||||
index.free();
|
||||
});
|
||||
|
||||
test('applies diff to repository', () {
|
||||
final diff = Diff.parse(patchText);
|
||||
final file = File(p.join(tmpDir.path, 'subdir', 'modified_file'));
|
||||
|
||||
Checkout.head(repo: repo, strategy: {GitCheckout.force});
|
||||
expect(file.readAsStringSync(), '');
|
||||
|
||||
diff.apply(repo: repo);
|
||||
Diff.parse(patchText).apply(repo: repo);
|
||||
expect(file.readAsStringSync(), 'Modified content\n');
|
||||
|
||||
diff.free();
|
||||
});
|
||||
|
||||
test('throws when trying to apply diff and error occurs', () {
|
||||
|
@ -455,9 +378,6 @@ index e69de29..c217c63 100644
|
|||
|
||||
expect(diff.length, 1);
|
||||
expect(patch.text, patchText);
|
||||
|
||||
patch.free();
|
||||
diff.free();
|
||||
});
|
||||
|
||||
test('applies hunk with provided index to repository', () {
|
||||
|
@ -470,112 +390,86 @@ index e69de29..c217c63 100644
|
|||
|
||||
diff.apply(repo: repo, hunkIndex: hunk.index);
|
||||
expect(file.readAsStringSync(), 'Modified content\n');
|
||||
|
||||
diff.free();
|
||||
});
|
||||
|
||||
test('does not apply hunk with non existing index', () {
|
||||
final diff = Diff.parse(patchText);
|
||||
final file = File(p.join(tmpDir.path, 'subdir', 'modified_file'));
|
||||
|
||||
Checkout.head(repo: repo, strategy: {GitCheckout.force});
|
||||
expect(file.readAsStringSync(), '');
|
||||
|
||||
diff.apply(repo: repo, hunkIndex: 10);
|
||||
Diff.parse(patchText).apply(repo: repo, hunkIndex: 10);
|
||||
expect(file.readAsStringSync(), '');
|
||||
|
||||
diff.free();
|
||||
});
|
||||
|
||||
test('applies diff to tree', () {
|
||||
final diff = Diff.parse(patchText);
|
||||
|
||||
Checkout.head(repo: repo, strategy: {GitCheckout.force});
|
||||
final head = repo.head;
|
||||
final commit = Commit.lookup(repo: repo, oid: head.target);
|
||||
final tree = commit.tree;
|
||||
|
||||
final oldIndex = repo.index;
|
||||
final oldBlob = Blob.lookup(
|
||||
repo: repo,
|
||||
oid: oldIndex['subdir/modified_file'].oid,
|
||||
expect(
|
||||
Blob.lookup(
|
||||
repo: repo,
|
||||
oid: repo.index['subdir/modified_file'].oid,
|
||||
).content,
|
||||
'',
|
||||
);
|
||||
expect(oldBlob.content, '');
|
||||
|
||||
final newIndex = diff.applyToTree(repo: repo, tree: tree);
|
||||
final newBlob = Blob.lookup(
|
||||
final newIndex = Diff.parse(patchText).applyToTree(
|
||||
repo: repo,
|
||||
oid: newIndex['subdir/modified_file'].oid,
|
||||
tree: Commit.lookup(repo: repo, oid: repo.head.target).tree,
|
||||
);
|
||||
expect(
|
||||
Blob.lookup(
|
||||
repo: repo,
|
||||
oid: newIndex['subdir/modified_file'].oid,
|
||||
).content,
|
||||
'Modified content\n',
|
||||
);
|
||||
expect(newBlob.content, 'Modified content\n');
|
||||
|
||||
oldBlob.free();
|
||||
newBlob.free();
|
||||
oldIndex.free();
|
||||
newIndex.free();
|
||||
tree.free();
|
||||
commit.free();
|
||||
head.free();
|
||||
diff.free();
|
||||
});
|
||||
|
||||
test('applies hunk with provided index to tree', () {
|
||||
Checkout.head(repo: repo, strategy: {GitCheckout.force});
|
||||
|
||||
expect(
|
||||
Blob.lookup(
|
||||
repo: repo,
|
||||
oid: repo.index['subdir/modified_file'].oid,
|
||||
).content,
|
||||
'',
|
||||
);
|
||||
|
||||
final diff = Diff.parse(patchText);
|
||||
final hunk = diff.patches.first.hunks.first;
|
||||
|
||||
Checkout.head(repo: repo, strategy: {GitCheckout.force});
|
||||
final head = repo.head;
|
||||
final commit = Commit.lookup(repo: repo, oid: head.target);
|
||||
final tree = commit.tree;
|
||||
|
||||
final oldIndex = repo.index;
|
||||
final oldBlob = Blob.lookup(
|
||||
repo: repo,
|
||||
oid: oldIndex['subdir/modified_file'].oid,
|
||||
);
|
||||
expect(oldBlob.content, '');
|
||||
|
||||
final newIndex = diff.applyToTree(
|
||||
repo: repo,
|
||||
tree: tree,
|
||||
tree: Commit.lookup(repo: repo, oid: repo.head.target).tree,
|
||||
hunkIndex: hunk.index,
|
||||
);
|
||||
final newBlob = Blob.lookup(
|
||||
repo: repo,
|
||||
oid: newIndex['subdir/modified_file'].oid,
|
||||
expect(
|
||||
Blob.lookup(
|
||||
repo: repo,
|
||||
oid: newIndex['subdir/modified_file'].oid,
|
||||
).content,
|
||||
'Modified content\n',
|
||||
);
|
||||
expect(newBlob.content, 'Modified content\n');
|
||||
|
||||
oldBlob.free();
|
||||
newBlob.free();
|
||||
oldIndex.free();
|
||||
newIndex.free();
|
||||
tree.free();
|
||||
commit.free();
|
||||
head.free();
|
||||
diff.free();
|
||||
});
|
||||
|
||||
test('throws when trying to apply diff to tree and error occurs', () {
|
||||
final diff = Diff.parse(patchText);
|
||||
expect(
|
||||
() => diff.applyToTree(repo: repo, tree: Tree(nullptr)),
|
||||
() => Diff.parse(patchText).applyToTree(
|
||||
repo: repo,
|
||||
tree: Tree(nullptr),
|
||||
),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
test('finds similar entries', () {
|
||||
final index = repo.index;
|
||||
final head = repo.head;
|
||||
final commit = Commit.lookup(repo: repo, oid: head.target);
|
||||
final oldTree = commit.tree;
|
||||
final newTree = Tree.lookup(repo: repo, oid: index.writeTree());
|
||||
|
||||
final diff = Diff.treeToTree(
|
||||
repo: repo,
|
||||
oldTree: oldTree,
|
||||
newTree: newTree,
|
||||
oldTree: Commit.lookup(repo: repo, oid: repo.head.target).tree,
|
||||
newTree: Tree.lookup(repo: repo, oid: repo.index.writeTree()),
|
||||
);
|
||||
expect(
|
||||
diff.deltas.singleWhere((e) => e.newFile.path == 'staged_new').status,
|
||||
|
@ -587,28 +481,18 @@ index e69de29..c217c63 100644
|
|||
diff.deltas.singleWhere((e) => e.newFile.path == 'staged_new').status,
|
||||
GitDelta.renamed,
|
||||
);
|
||||
|
||||
commit.free();
|
||||
head.free();
|
||||
diff.free();
|
||||
index.free();
|
||||
oldTree.free();
|
||||
newTree.free();
|
||||
});
|
||||
|
||||
test('throws when trying to find similar entries and error occurs', () {
|
||||
final nullDiff = Diff(nullptr);
|
||||
expect(() => nullDiff.findSimilar(), throwsA(isA<LibGit2Error>()));
|
||||
expect(() => Diff(nullptr).findSimilar(), throwsA(isA<LibGit2Error>()));
|
||||
});
|
||||
|
||||
test('throws when trying to get patch Oid and error occurs', () {
|
||||
final nullDiff = Diff(nullptr);
|
||||
expect(() => nullDiff.patchOid, throwsA(isA<LibGit2Error>()));
|
||||
expect(() => Diff(nullptr).patchOid, throwsA(isA<LibGit2Error>()));
|
||||
});
|
||||
|
||||
test('returns deltas', () {
|
||||
final index = repo.index;
|
||||
final diff = Diff.indexToWorkdir(repo: repo, index: index);
|
||||
final diff = Diff.indexToWorkdir(repo: repo, index: repo.index);
|
||||
|
||||
expect(diff.deltas[0].numberOfFiles, 1);
|
||||
expect(diff.deltas[0].status, GitDelta.deleted);
|
||||
|
@ -635,110 +519,59 @@ index e69de29..c217c63 100644
|
|||
);
|
||||
|
||||
expect(diff.deltas[0].oldFile.mode, GitFilemode.blob);
|
||||
|
||||
diff.free();
|
||||
index.free();
|
||||
});
|
||||
|
||||
test('throws when trying to get delta with invalid index', () {
|
||||
final index = repo.index;
|
||||
final diff = Diff.indexToWorkdir(repo: repo, index: index);
|
||||
|
||||
final diff = Diff.indexToWorkdir(repo: repo, index: repo.index);
|
||||
expect(() => diff.deltas[-1], throwsA(isA<RangeError>()));
|
||||
|
||||
diff.free();
|
||||
index.free();
|
||||
});
|
||||
|
||||
test('returns patches', () {
|
||||
final index = repo.index;
|
||||
final diff = Diff.indexToWorkdir(repo: repo, index: index);
|
||||
final diff = Diff.indexToWorkdir(repo: repo, index: repo.index);
|
||||
final patches = diff.patches;
|
||||
|
||||
expect(patches.length, 8);
|
||||
expect(patches.first.delta.status, GitDelta.deleted);
|
||||
|
||||
for (final p in patches) {
|
||||
p.free();
|
||||
}
|
||||
diff.free();
|
||||
index.free();
|
||||
});
|
||||
|
||||
test('returns stats', () {
|
||||
final index = repo.index;
|
||||
final diff = Diff.indexToWorkdir(repo: repo, index: index);
|
||||
final diff = Diff.indexToWorkdir(repo: repo, index: repo.index);
|
||||
final stats = diff.stats;
|
||||
|
||||
expect(stats.insertions, 4);
|
||||
expect(stats.deletions, 2);
|
||||
expect(stats.filesChanged, 8);
|
||||
expect(stats.print(format: {GitDiffStats.full}, width: 80), statsPrint);
|
||||
|
||||
stats.free();
|
||||
diff.free();
|
||||
index.free();
|
||||
});
|
||||
|
||||
test('throws when trying to get stats and error occurs', () {
|
||||
final nullDiff = Diff(nullptr);
|
||||
expect(() => nullDiff.stats, throwsA(isA<LibGit2Error>()));
|
||||
expect(() => Diff(nullptr).stats, throwsA(isA<LibGit2Error>()));
|
||||
});
|
||||
|
||||
test('throws when trying to print stats and error occurs', () {
|
||||
final nullStats = DiffStats(nullptr);
|
||||
expect(
|
||||
() => nullStats.print(format: {GitDiffStats.full}, width: 80),
|
||||
() => DiffStats(nullptr).print(format: {GitDiffStats.full}, width: 80),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
});
|
||||
|
||||
test('returns patch diff string', () {
|
||||
final diff = Diff.parse(patchText);
|
||||
|
||||
expect(diff.patch, patchText);
|
||||
|
||||
diff.free();
|
||||
expect(Diff.parse(patchText).patch, patchText);
|
||||
});
|
||||
|
||||
test('returns hunks in a patch', () {
|
||||
test('manually releases allocated memory', () {
|
||||
final diff = Diff.parse(patchText);
|
||||
final patch = Patch.fromDiff(diff: diff, index: 0);
|
||||
final hunk = patch.hunks[0];
|
||||
|
||||
expect(patch.hunks.length, 1);
|
||||
expect(hunk.linesCount, 1);
|
||||
expect(hunk.oldStart, 0);
|
||||
expect(hunk.oldLines, 0);
|
||||
expect(hunk.newStart, 1);
|
||||
expect(hunk.newLines, 1);
|
||||
expect(hunk.header, '@@ -0,0 +1 @@\n');
|
||||
|
||||
patch.free();
|
||||
diff.free();
|
||||
expect(() => diff.free(), returnsNormally);
|
||||
});
|
||||
|
||||
test('returns lines in a hunk', () {
|
||||
final diff = Diff.parse(patchText);
|
||||
final patch = Patch.fromDiff(diff: diff, index: 0);
|
||||
final hunk = patch.hunks[0];
|
||||
final line = hunk.lines[0];
|
||||
|
||||
expect(hunk.lines.length, 1);
|
||||
expect(line.origin, GitDiffLine.addition);
|
||||
expect(line.oldLineNumber, -1);
|
||||
expect(line.newLineNumber, 1);
|
||||
expect(line.numLines, 1);
|
||||
expect(line.contentOffset, 155);
|
||||
expect(line.content, 'Modified content\n');
|
||||
|
||||
patch.free();
|
||||
diff.free();
|
||||
test('manually releases allocated memory for DiffStats object', () {
|
||||
final stats = Diff.parse(patchText).stats;
|
||||
expect(() => stats.free(), returnsNormally);
|
||||
});
|
||||
|
||||
test(
|
||||
'returns string representation of Diff, DiffDelta, DiffFile, '
|
||||
'DiffHunk, DiffLine and DiffStats objects', () {
|
||||
'returns string representation of Diff, DiffDelta, DiffFile '
|
||||
' and DiffStats objects', () {
|
||||
final diff = Diff.parse(patchText);
|
||||
final patch = Patch.fromDiff(diff: diff, index: 0);
|
||||
final stats = diff.stats;
|
||||
|
@ -746,13 +579,7 @@ index e69de29..c217c63 100644
|
|||
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();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@ void main() {
|
|||
});
|
||||
|
||||
tearDown(() {
|
||||
index.free();
|
||||
repo.free();
|
||||
tmpDir.deleteSync(recursive: true);
|
||||
});
|
||||
|
@ -152,30 +151,25 @@ void main() {
|
|||
final bare = Repository.open(
|
||||
p.join('test', 'assets', 'empty_bare.git'),
|
||||
);
|
||||
final bareIndex = bare.index;
|
||||
expect(() => bare.index.add('config'), throwsA(isA<LibGit2Error>()));
|
||||
|
||||
expect(() => bareIndex.add('config'), throwsA(isA<LibGit2Error>()));
|
||||
|
||||
bareIndex.free();
|
||||
bare.free();
|
||||
});
|
||||
});
|
||||
|
||||
group('addFromBuffer()', () {
|
||||
test('updates index entry from a buffer', () {
|
||||
final entry = index['file'];
|
||||
expect(repo.status, isEmpty);
|
||||
|
||||
index.addFromBuffer(entry: entry, buffer: 'updated');
|
||||
index.addFromBuffer(entry: index['file'], buffer: 'updated');
|
||||
expect(repo.status, {
|
||||
'file': {GitStatus.indexModified, GitStatus.wtModified}
|
||||
});
|
||||
});
|
||||
|
||||
test('throws when trying to update entry and error occurs', () {
|
||||
final nullEntry = IndexEntry(nullptr);
|
||||
expect(
|
||||
() => index.addFromBuffer(entry: nullEntry, buffer: ''),
|
||||
() => index.addFromBuffer(entry: IndexEntry(nullptr), buffer: ''),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
});
|
||||
|
@ -208,11 +202,8 @@ void main() {
|
|||
final bare = Repository.open(
|
||||
p.join('test', 'assets', 'empty_bare.git'),
|
||||
);
|
||||
final bareIndex = bare.index;
|
||||
expect(() => bare.index.addAll([]), throwsA(isA<LibGit2Error>()));
|
||||
|
||||
expect(() => bareIndex.addAll([]), throwsA(isA<LibGit2Error>()));
|
||||
|
||||
bareIndex.free();
|
||||
bare.free();
|
||||
});
|
||||
});
|
||||
|
@ -234,14 +225,11 @@ void main() {
|
|||
final bare = Repository.open(
|
||||
p.join('test', 'assets', 'empty_bare.git'),
|
||||
);
|
||||
final bareIndex = bare.index;
|
||||
|
||||
expect(
|
||||
() => bareIndex.updateAll(['not_there']),
|
||||
() => bare.index.updateAll(['not_there']),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
|
||||
bareIndex.free();
|
||||
bare.free();
|
||||
});
|
||||
});
|
||||
|
@ -293,9 +281,8 @@ void main() {
|
|||
});
|
||||
|
||||
test('reads tree with provided SHA hex', () {
|
||||
final tree = Tree.lookup(repo: repo, oid: repo['df2b8fc']);
|
||||
expect(index.length, 4);
|
||||
index.readTree(tree);
|
||||
index.readTree(Tree.lookup(repo: repo, oid: repo['df2b8fc']));
|
||||
|
||||
expect(index.length, 1);
|
||||
|
||||
|
@ -305,8 +292,7 @@ void main() {
|
|||
});
|
||||
|
||||
test('writes tree', () {
|
||||
final oid = index.writeTree();
|
||||
expect(oid.sha, 'a8ae3dd59e6e1802c6f78e05e301bfd57c9f334f');
|
||||
expect(index.writeTree().sha, 'a8ae3dd59e6e1802c6f78e05e301bfd57c9f334f');
|
||||
});
|
||||
|
||||
test('throws when trying to write tree to invalid repository', () {
|
||||
|
@ -320,20 +306,16 @@ void main() {
|
|||
final tmpDir = setupRepo(Directory(mergeRepoPath));
|
||||
final repo = Repository.open(tmpDir.path);
|
||||
|
||||
final conflictBranch = Branch.lookup(repo: repo, name: 'conflict-branch');
|
||||
final index = repo.index;
|
||||
final commit = AnnotatedCommit.lookup(
|
||||
Merge.commit(
|
||||
repo: repo,
|
||||
oid: conflictBranch.target,
|
||||
commit: AnnotatedCommit.lookup(
|
||||
repo: repo,
|
||||
oid: Branch.lookup(repo: repo, name: 'conflict-branch').target,
|
||||
),
|
||||
);
|
||||
|
||||
Merge.commit(repo: repo, commit: commit);
|
||||
expect(() => repo.index.writeTree(), throwsA(isA<LibGit2Error>()));
|
||||
|
||||
expect(() => index.writeTree(), throwsA(isA<LibGit2Error>()));
|
||||
|
||||
commit.free();
|
||||
conflictBranch.free();
|
||||
index.free();
|
||||
repo.free();
|
||||
tmpDir.deleteSync(recursive: true);
|
||||
});
|
||||
|
@ -356,30 +338,24 @@ void main() {
|
|||
final repoDir = setupRepo(Directory(mergeRepoPath));
|
||||
final conflictRepo = Repository.open(repoDir.path);
|
||||
|
||||
final conflictBranch = Branch.lookup(
|
||||
repo: conflictRepo,
|
||||
name: 'ancestor-conflict',
|
||||
);
|
||||
final commit = AnnotatedCommit.lookup(
|
||||
repo: conflictRepo,
|
||||
oid: conflictBranch.target,
|
||||
);
|
||||
|
||||
Checkout.reference(repo: conflictRepo, name: 'refs/heads/feature');
|
||||
conflictRepo.setHead('refs/heads/feature');
|
||||
|
||||
Merge.commit(repo: conflictRepo, commit: commit);
|
||||
Merge.commit(
|
||||
repo: conflictRepo,
|
||||
commit: AnnotatedCommit.lookup(
|
||||
repo: conflictRepo,
|
||||
oid: Branch.lookup(repo: conflictRepo, name: 'ancestor-conflict')
|
||||
.target,
|
||||
),
|
||||
);
|
||||
|
||||
final index = conflictRepo.index;
|
||||
final conflictedFile = index.conflicts['feature_file']!;
|
||||
final conflictedFile = conflictRepo.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();
|
||||
commit.free();
|
||||
conflictBranch.free();
|
||||
conflictRepo.free();
|
||||
repoDir.deleteSync(recursive: true);
|
||||
});
|
||||
|
@ -388,27 +364,23 @@ void main() {
|
|||
final repoDir = setupRepo(Directory(mergeRepoPath));
|
||||
final conflictRepo = Repository.open(repoDir.path);
|
||||
|
||||
final conflictBranch = Branch.lookup(
|
||||
Merge.commit(
|
||||
repo: conflictRepo,
|
||||
name: 'conflict-branch',
|
||||
);
|
||||
final commit = AnnotatedCommit.lookup(
|
||||
repo: conflictRepo,
|
||||
oid: conflictBranch.target,
|
||||
commit: AnnotatedCommit.lookup(
|
||||
repo: conflictRepo,
|
||||
oid: Branch.lookup(
|
||||
repo: conflictRepo,
|
||||
name: 'conflict-branch',
|
||||
).target,
|
||||
),
|
||||
);
|
||||
|
||||
Merge.commit(repo: conflictRepo, commit: commit);
|
||||
|
||||
final index = conflictRepo.index;
|
||||
final conflictedFile = index.conflicts['conflict_file']!;
|
||||
final conflictedFile = conflictRepo.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();
|
||||
commit.free();
|
||||
conflictBranch.free();
|
||||
conflictRepo.free();
|
||||
repoDir.deleteSync(recursive: true);
|
||||
});
|
||||
|
@ -417,30 +389,24 @@ void main() {
|
|||
final repoDir = setupRepo(Directory(mergeRepoPath));
|
||||
final conflictRepo = Repository.open(repoDir.path);
|
||||
|
||||
final conflictBranch = Branch.lookup(
|
||||
repo: conflictRepo,
|
||||
name: 'ancestor-conflict',
|
||||
);
|
||||
final commit = AnnotatedCommit.lookup(
|
||||
repo: conflictRepo,
|
||||
oid: conflictBranch.target,
|
||||
);
|
||||
|
||||
Checkout.reference(repo: conflictRepo, name: 'refs/heads/our-conflict');
|
||||
conflictRepo.setHead('refs/heads/our-conflict');
|
||||
|
||||
Merge.commit(repo: conflictRepo, commit: commit);
|
||||
Merge.commit(
|
||||
repo: conflictRepo,
|
||||
commit: AnnotatedCommit.lookup(
|
||||
repo: conflictRepo,
|
||||
oid: Branch.lookup(repo: conflictRepo, name: 'ancestor-conflict')
|
||||
.target,
|
||||
),
|
||||
);
|
||||
|
||||
final index = conflictRepo.index;
|
||||
final conflictedFile = index.conflicts['feature_file']!;
|
||||
final conflictedFile = conflictRepo.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();
|
||||
commit.free();
|
||||
conflictBranch.free();
|
||||
conflictRepo.free();
|
||||
repoDir.deleteSync(recursive: true);
|
||||
});
|
||||
|
@ -449,30 +415,23 @@ void main() {
|
|||
final repoDir = setupRepo(Directory(mergeRepoPath));
|
||||
final conflictRepo = Repository.open(repoDir.path);
|
||||
|
||||
final conflictBranch = Branch.lookup(
|
||||
repo: conflictRepo,
|
||||
name: 'their-conflict',
|
||||
);
|
||||
final commit = AnnotatedCommit.lookup(
|
||||
repo: conflictRepo,
|
||||
oid: conflictBranch.target,
|
||||
);
|
||||
|
||||
Checkout.reference(repo: conflictRepo, name: 'refs/heads/feature');
|
||||
conflictRepo.setHead('refs/heads/feature');
|
||||
|
||||
Merge.commit(repo: conflictRepo, commit: commit);
|
||||
Merge.commit(
|
||||
repo: conflictRepo,
|
||||
commit: AnnotatedCommit.lookup(
|
||||
repo: conflictRepo,
|
||||
oid: Branch.lookup(repo: conflictRepo, name: 'their-conflict').target,
|
||||
),
|
||||
);
|
||||
|
||||
final index = conflictRepo.index;
|
||||
final conflictedFile = index.conflicts['feature_file']!;
|
||||
final conflictedFile = conflictRepo.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();
|
||||
commit.free();
|
||||
conflictBranch.free();
|
||||
conflictRepo.free();
|
||||
repoDir.deleteSync(recursive: true);
|
||||
});
|
||||
|
@ -481,17 +440,19 @@ void main() {
|
|||
final repoDir = setupRepo(Directory(mergeRepoPath));
|
||||
final conflictRepo = Repository.open(repoDir.path);
|
||||
|
||||
final conflictBranch = Branch.lookup(
|
||||
repo: conflictRepo,
|
||||
name: 'conflict-branch',
|
||||
);
|
||||
final commit = AnnotatedCommit.lookup(
|
||||
repo: conflictRepo,
|
||||
oid: conflictBranch.target,
|
||||
);
|
||||
final index = conflictRepo.index;
|
||||
|
||||
Merge.commit(repo: conflictRepo, commit: commit);
|
||||
Merge.commit(
|
||||
repo: conflictRepo,
|
||||
commit: AnnotatedCommit.lookup(
|
||||
repo: conflictRepo,
|
||||
oid: Branch.lookup(
|
||||
repo: conflictRepo,
|
||||
name: 'conflict-branch',
|
||||
).target,
|
||||
),
|
||||
);
|
||||
|
||||
expect(index.hasConflicts, true);
|
||||
expect(index['.gitignore'].isConflict, false);
|
||||
expect(index.conflicts['conflict_file']!.our!.isConflict, true);
|
||||
|
@ -499,13 +460,11 @@ void main() {
|
|||
|
||||
final conflictedFile = index.conflicts['conflict_file']!;
|
||||
conflictedFile.remove();
|
||||
|
||||
expect(index.hasConflicts, false);
|
||||
expect(index.conflicts, isEmpty);
|
||||
expect(index.conflicts['conflict_file'], null);
|
||||
|
||||
index.free();
|
||||
commit.free();
|
||||
conflictBranch.free();
|
||||
conflictRepo.free();
|
||||
repoDir.deleteSync(recursive: true);
|
||||
});
|
||||
|
@ -522,27 +481,27 @@ void main() {
|
|||
final repoDir = setupRepo(Directory(mergeRepoPath));
|
||||
final conflictRepo = Repository.open(repoDir.path);
|
||||
|
||||
final conflictBranch = Branch.lookup(
|
||||
repo: conflictRepo,
|
||||
name: 'conflict-branch',
|
||||
);
|
||||
final commit = AnnotatedCommit.lookup(
|
||||
repo: conflictRepo,
|
||||
oid: conflictBranch.target,
|
||||
);
|
||||
final index = conflictRepo.index;
|
||||
|
||||
Merge.commit(repo: conflictRepo, commit: commit);
|
||||
Merge.commit(
|
||||
repo: conflictRepo,
|
||||
commit: AnnotatedCommit.lookup(
|
||||
repo: conflictRepo,
|
||||
oid: Branch.lookup(
|
||||
repo: conflictRepo,
|
||||
name: 'conflict-branch',
|
||||
).target,
|
||||
),
|
||||
);
|
||||
|
||||
expect(index.hasConflicts, true);
|
||||
expect(index.conflicts.length, 1);
|
||||
|
||||
index.cleanupConflict();
|
||||
|
||||
expect(index.hasConflicts, false);
|
||||
expect(index.conflicts, isEmpty);
|
||||
|
||||
index.free();
|
||||
commit.free();
|
||||
conflictBranch.free();
|
||||
conflictRepo.free();
|
||||
repoDir.deleteSync(recursive: true);
|
||||
});
|
||||
|
@ -554,13 +513,15 @@ void main() {
|
|||
);
|
||||
});
|
||||
|
||||
test('manually releases allocated memory', () {
|
||||
expect(() => repo.index.free(), returnsNormally);
|
||||
});
|
||||
|
||||
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();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -142,10 +142,7 @@ Santa Claus <santa.claus@northpole.xx> <me@company.xx>
|
|||
|
||||
group('Mailmap', () {
|
||||
test('initializes empty mailmap object', () {
|
||||
final empty = Mailmap.empty();
|
||||
expect(empty, isA<Mailmap>());
|
||||
|
||||
empty.free();
|
||||
expect(Mailmap.empty(), isA<Mailmap>());
|
||||
});
|
||||
|
||||
test('initializes from provided buffer', () {
|
||||
|
@ -158,8 +155,6 @@ Santa Claus <santa.claus@northpole.xx> <me@company.xx>
|
|||
[entry['realName'], entry['realEmail']],
|
||||
);
|
||||
}
|
||||
|
||||
mailmap.free();
|
||||
});
|
||||
|
||||
test('initializes from repository', () {
|
||||
|
@ -172,8 +167,6 @@ Santa Claus <santa.claus@northpole.xx> <me@company.xx>
|
|||
[entry['realName'], entry['realEmail']],
|
||||
);
|
||||
}
|
||||
|
||||
mailmap.free();
|
||||
});
|
||||
|
||||
test('throws when initializing from repository and error occurs', () {
|
||||
|
@ -192,8 +185,6 @@ Santa Claus <santa.claus@northpole.xx> <me@company.xx>
|
|||
[entry['name'], entry['email']],
|
||||
);
|
||||
}
|
||||
|
||||
mailmap.free();
|
||||
});
|
||||
|
||||
test('adds entries and resolves them', () {
|
||||
|
@ -214,21 +205,15 @@ Santa Claus <santa.claus@northpole.xx> <me@company.xx>
|
|||
[entry['realName'], entry['realEmail']],
|
||||
);
|
||||
}
|
||||
|
||||
mailmap.free();
|
||||
});
|
||||
|
||||
test('throws when trying to add entry with empty replace email', () {
|
||||
final mailmap = Mailmap.empty();
|
||||
|
||||
expect(
|
||||
() => mailmap.addEntry(
|
||||
() => Mailmap.empty().addEntry(
|
||||
replaceEmail: ' ',
|
||||
),
|
||||
throwsA(isA<ArgumentError>()),
|
||||
);
|
||||
|
||||
mailmap.free();
|
||||
});
|
||||
|
||||
test('resolves signature', () {
|
||||
|
@ -249,8 +234,10 @@ Santa Claus <santa.claus@northpole.xx> <me@company.xx>
|
|||
);
|
||||
|
||||
expect(mailmap.resolveSignature(signature), realSignature);
|
||||
});
|
||||
|
||||
mailmap.free();
|
||||
test('manually releases allocated memory', () {
|
||||
expect(() => Mailmap.empty().free(), returnsNormally);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -26,11 +26,13 @@ void main() {
|
|||
group('Merge', () {
|
||||
group('analysis', () {
|
||||
test('is up to date when no reference is provided', () {
|
||||
final result = Merge.analysis(repo: repo, theirHead: repo['c68ff54']);
|
||||
expect(result, [
|
||||
{GitMergeAnalysis.upToDate},
|
||||
GitMergePreference.none,
|
||||
]);
|
||||
expect(
|
||||
Merge.analysis(repo: repo, theirHead: repo['c68ff54']),
|
||||
[
|
||||
{GitMergeAnalysis.upToDate},
|
||||
GitMergePreference.none,
|
||||
],
|
||||
);
|
||||
expect(repo.status, isEmpty);
|
||||
});
|
||||
|
||||
|
@ -45,11 +47,10 @@ void main() {
|
|||
});
|
||||
|
||||
test('is fast forward', () {
|
||||
final ffCommit = Commit.lookup(repo: repo, oid: repo['f17d0d4']);
|
||||
final ffBranch = Branch.create(
|
||||
repo: repo,
|
||||
name: 'ff-branch',
|
||||
target: ffCommit,
|
||||
target: Commit.lookup(repo: repo, oid: repo['f17d0d4']),
|
||||
);
|
||||
|
||||
final result = Merge.analysis(
|
||||
|
@ -62,9 +63,6 @@ void main() {
|
|||
{GitMergeAnalysis.fastForward, GitMergeAnalysis.normal},
|
||||
);
|
||||
expect(repo.status, isEmpty);
|
||||
|
||||
ffBranch.free();
|
||||
ffCommit.free();
|
||||
});
|
||||
|
||||
test('is not fast forward and there is no conflicts', () {
|
||||
|
@ -76,10 +74,6 @@ void main() {
|
|||
|
||||
test('writes conflicts to index', () {
|
||||
final conflictBranch = Branch.lookup(repo: repo, name: 'conflict-branch');
|
||||
final commit = AnnotatedCommit.lookup(
|
||||
repo: repo,
|
||||
oid: conflictBranch.target,
|
||||
);
|
||||
final index = repo.index;
|
||||
|
||||
final result = Merge.analysis(
|
||||
|
@ -88,7 +82,10 @@ void main() {
|
|||
);
|
||||
expect(result[0], {GitMergeAnalysis.normal});
|
||||
|
||||
Merge.commit(repo: repo, commit: commit);
|
||||
Merge.commit(
|
||||
repo: repo,
|
||||
commit: AnnotatedCommit.lookup(repo: repo, oid: conflictBranch.target),
|
||||
);
|
||||
expect(index.hasConflicts, true);
|
||||
expect(index.conflicts.length, 1);
|
||||
expect(repo.state, GitRepositoryState.merge);
|
||||
|
@ -114,10 +111,6 @@ void main() {
|
|||
'conflict_file': {GitStatus.indexModified}
|
||||
},
|
||||
);
|
||||
|
||||
index.free();
|
||||
commit.free();
|
||||
conflictBranch.free();
|
||||
});
|
||||
|
||||
group('merge file from index', () {
|
||||
|
@ -129,19 +122,16 @@ master conflict edit
|
|||
conflict branch edit
|
||||
>>>>>>> conflict_file
|
||||
""";
|
||||
final conflictBranch = Branch.lookup(
|
||||
repo: repo,
|
||||
name: 'conflict-branch',
|
||||
);
|
||||
final commit = AnnotatedCommit.lookup(
|
||||
repo: repo,
|
||||
oid: conflictBranch.target,
|
||||
);
|
||||
final index = repo.index;
|
||||
|
||||
Merge.commit(repo: repo, commit: commit);
|
||||
Merge.commit(
|
||||
repo: repo,
|
||||
commit: AnnotatedCommit.lookup(
|
||||
repo: repo,
|
||||
oid: Branch.lookup(repo: repo, name: 'conflict-branch').target,
|
||||
),
|
||||
);
|
||||
|
||||
final conflictedFile = index.conflicts['conflict_file']!;
|
||||
final conflictedFile = repo.index.conflicts['conflict_file']!;
|
||||
final diff = Merge.fileFromIndex(
|
||||
repo: repo,
|
||||
ancestor: null,
|
||||
|
@ -150,10 +140,6 @@ conflict branch edit
|
|||
);
|
||||
|
||||
expect(diff, diffExpected);
|
||||
|
||||
index.free();
|
||||
commit.free();
|
||||
conflictBranch.free();
|
||||
});
|
||||
|
||||
test('merges with ancestor', () {
|
||||
|
@ -164,21 +150,19 @@ Feature edit on feature branch
|
|||
Another feature edit
|
||||
>>>>>>> feature_file
|
||||
""";
|
||||
final conflictBranch = Branch.lookup(
|
||||
repo: repo,
|
||||
name: 'ancestor-conflict',
|
||||
);
|
||||
final commit = AnnotatedCommit.lookup(
|
||||
repo: repo,
|
||||
oid: conflictBranch.target,
|
||||
);
|
||||
|
||||
Checkout.reference(repo: repo, name: 'refs/heads/feature');
|
||||
repo.setHead('refs/heads/feature');
|
||||
final index = repo.index;
|
||||
|
||||
Merge.commit(repo: repo, commit: commit);
|
||||
Merge.commit(
|
||||
repo: repo,
|
||||
commit: AnnotatedCommit.lookup(
|
||||
repo: repo,
|
||||
oid: Branch.lookup(repo: repo, name: 'ancestor-conflict').target,
|
||||
),
|
||||
);
|
||||
|
||||
final conflictedFile = index.conflicts['feature_file']!;
|
||||
final conflictedFile = repo.index.conflicts['feature_file']!;
|
||||
final diff = Merge.fileFromIndex(
|
||||
repo: repo,
|
||||
ancestor: conflictedFile.ancestor,
|
||||
|
@ -187,10 +171,6 @@ Another feature edit
|
|||
);
|
||||
|
||||
expect(diff, diffExpected);
|
||||
|
||||
index.free();
|
||||
commit.free();
|
||||
conflictBranch.free();
|
||||
});
|
||||
|
||||
test('merges with provided merge flags and file flags', () {
|
||||
|
@ -201,24 +181,18 @@ master conflict edit
|
|||
conflict branch edit
|
||||
>>>>>>> conflict_file
|
||||
""";
|
||||
final conflictBranch = Branch.lookup(
|
||||
repo: repo,
|
||||
name: 'conflict-branch',
|
||||
);
|
||||
final commit = AnnotatedCommit.lookup(
|
||||
repo: repo,
|
||||
oid: conflictBranch.target,
|
||||
);
|
||||
final index = repo.index;
|
||||
|
||||
Merge.commit(
|
||||
repo: repo,
|
||||
commit: commit,
|
||||
commit: AnnotatedCommit.lookup(
|
||||
repo: repo,
|
||||
oid: Branch.lookup(repo: repo, name: 'conflict-branch').target,
|
||||
),
|
||||
mergeFlags: {GitMergeFlag.noRecursive},
|
||||
fileFlags: {GitMergeFileFlag.ignoreWhitespaceEOL},
|
||||
);
|
||||
|
||||
final conflictedFile = index.conflicts['conflict_file']!;
|
||||
final conflictedFile = repo.index.conflicts['conflict_file']!;
|
||||
final diff = Merge.fileFromIndex(
|
||||
repo: repo,
|
||||
ancestor: null,
|
||||
|
@ -227,34 +201,23 @@ conflict branch edit
|
|||
);
|
||||
|
||||
expect(diff, diffExpected);
|
||||
|
||||
index.free();
|
||||
commit.free();
|
||||
conflictBranch.free();
|
||||
});
|
||||
|
||||
test('merges with provided merge favor', () {
|
||||
final conflictBranch = Branch.lookup(
|
||||
Merge.commit(
|
||||
repo: repo,
|
||||
name: 'conflict-branch',
|
||||
commit: AnnotatedCommit.lookup(
|
||||
repo: repo,
|
||||
oid: Branch.lookup(repo: repo, name: 'conflict-branch').target,
|
||||
),
|
||||
favor: GitMergeFileFavor.ours,
|
||||
);
|
||||
final commit = AnnotatedCommit.lookup(
|
||||
repo: repo,
|
||||
oid: conflictBranch.target,
|
||||
);
|
||||
final index = repo.index;
|
||||
|
||||
Merge.commit(repo: repo, commit: commit, favor: GitMergeFileFavor.ours);
|
||||
|
||||
expect(index.conflicts, isEmpty);
|
||||
expect(repo.index.conflicts, isEmpty);
|
||||
expect(
|
||||
File(p.join(repo.workdir, 'conflict_file')).readAsStringSync(),
|
||||
'master conflict edit\n',
|
||||
);
|
||||
|
||||
index.free();
|
||||
commit.free();
|
||||
conflictBranch.free();
|
||||
});
|
||||
|
||||
test('throws when error occurs', () {
|
||||
|
@ -328,59 +291,40 @@ theirs content
|
|||
group('merge commits', () {
|
||||
test('merges with default values', () {
|
||||
final theirCommit = Commit.lookup(repo: repo, oid: repo['5aecfa0']);
|
||||
final theirCommitAnnotated = AnnotatedCommit.lookup(
|
||||
repo: repo,
|
||||
oid: theirCommit.oid,
|
||||
);
|
||||
final ourCommit = Commit.lookup(repo: repo, oid: repo['1490545']);
|
||||
|
||||
final mergeIndex = Merge.commits(
|
||||
repo: repo,
|
||||
ourCommit: ourCommit,
|
||||
ourCommit: Commit.lookup(repo: repo, oid: repo['1490545']),
|
||||
theirCommit: theirCommit,
|
||||
);
|
||||
expect(mergeIndex.conflicts, isEmpty);
|
||||
final mergeCommitsTree = mergeIndex.writeTree(repo);
|
||||
|
||||
Merge.commit(repo: repo, commit: theirCommitAnnotated);
|
||||
final index = repo.index;
|
||||
expect(index.conflicts, isEmpty);
|
||||
final mergeTree = index.writeTree();
|
||||
Merge.commit(
|
||||
repo: repo,
|
||||
commit: AnnotatedCommit.lookup(repo: repo, oid: theirCommit.oid),
|
||||
);
|
||||
expect(repo.index.conflicts, isEmpty);
|
||||
final mergeTree = repo.index.writeTree();
|
||||
|
||||
expect(mergeCommitsTree == mergeTree, true);
|
||||
|
||||
index.free();
|
||||
mergeIndex.free();
|
||||
ourCommit.free();
|
||||
theirCommitAnnotated.free();
|
||||
theirCommit.free();
|
||||
});
|
||||
|
||||
test('merges with provided favor', () {
|
||||
final theirCommit = Commit.lookup(repo: repo, oid: repo['5aecfa0']);
|
||||
final ourCommit = Commit.lookup(repo: repo, oid: repo['1490545']);
|
||||
|
||||
final mergeIndex = Merge.commits(
|
||||
repo: repo,
|
||||
ourCommit: ourCommit,
|
||||
theirCommit: theirCommit,
|
||||
ourCommit: Commit.lookup(repo: repo, oid: repo['1490545']),
|
||||
theirCommit: Commit.lookup(repo: repo, oid: repo['5aecfa0']),
|
||||
favor: GitMergeFileFavor.ours,
|
||||
);
|
||||
expect(mergeIndex.conflicts, isEmpty);
|
||||
|
||||
mergeIndex.free();
|
||||
ourCommit.free();
|
||||
theirCommit.free();
|
||||
});
|
||||
|
||||
test('merges with provided merge and file flags', () {
|
||||
final theirCommit = Commit.lookup(repo: repo, oid: repo['5aecfa0']);
|
||||
final ourCommit = Commit.lookup(repo: repo, oid: repo['1490545']);
|
||||
|
||||
final mergeIndex = Merge.commits(
|
||||
repo: repo,
|
||||
ourCommit: ourCommit,
|
||||
theirCommit: theirCommit,
|
||||
ourCommit: Commit.lookup(repo: repo, oid: repo['1490545']),
|
||||
theirCommit: Commit.lookup(repo: repo, oid: repo['5aecfa0']),
|
||||
mergeFlags: {
|
||||
GitMergeFlag.findRenames,
|
||||
GitMergeFlag.noRecursive,
|
||||
|
@ -392,10 +336,6 @@ theirs content
|
|||
},
|
||||
);
|
||||
expect(mergeIndex.conflicts, isEmpty);
|
||||
|
||||
mergeIndex.free();
|
||||
ourCommit.free();
|
||||
theirCommit.free();
|
||||
});
|
||||
|
||||
test('throws when error occurs', () {
|
||||
|
@ -411,31 +351,33 @@ theirs content
|
|||
});
|
||||
|
||||
test('finds merge base for two commits', () {
|
||||
var base = Merge.base(
|
||||
repo: repo,
|
||||
commits: [repo['1490545'], repo['5aecfa0']],
|
||||
expect(
|
||||
Merge.base(repo: repo, commits: [repo['1490545'], repo['5aecfa0']]).sha,
|
||||
'fc38877b2552ab554752d9a77e1f48f738cca79b',
|
||||
);
|
||||
expect(base.sha, 'fc38877b2552ab554752d9a77e1f48f738cca79b');
|
||||
|
||||
base = Merge.base(
|
||||
repo: repo,
|
||||
commits: [repo['f17d0d4'], repo['5aecfa0']],
|
||||
expect(
|
||||
Merge.base(repo: repo, commits: [repo['f17d0d4'], repo['5aecfa0']]).sha,
|
||||
'f17d0d48eae3aa08cecf29128a35e310c97b3521',
|
||||
);
|
||||
expect(base.sha, 'f17d0d48eae3aa08cecf29128a35e310c97b3521');
|
||||
});
|
||||
|
||||
test('finds merge base for many commits', () {
|
||||
var base = Merge.base(
|
||||
repo: repo,
|
||||
commits: [repo['1490545'], repo['0e409d6'], repo['5aecfa0']],
|
||||
expect(
|
||||
Merge.base(
|
||||
repo: repo,
|
||||
commits: [repo['1490545'], repo['0e409d6'], repo['5aecfa0']],
|
||||
).sha,
|
||||
'fc38877b2552ab554752d9a77e1f48f738cca79b',
|
||||
);
|
||||
expect(base.sha, 'fc38877b2552ab554752d9a77e1f48f738cca79b');
|
||||
|
||||
base = Merge.base(
|
||||
repo: repo,
|
||||
commits: [repo['f17d0d4'], repo['5aecfa0'], repo['0e409d6']],
|
||||
expect(
|
||||
Merge.base(
|
||||
repo: repo,
|
||||
commits: [repo['f17d0d4'], repo['5aecfa0'], repo['0e409d6']],
|
||||
).sha,
|
||||
'f17d0d48eae3aa08cecf29128a35e310c97b3521',
|
||||
);
|
||||
expect(base.sha, 'f17d0d48eae3aa08cecf29128a35e310c97b3521');
|
||||
});
|
||||
|
||||
test('throws when trying to find merge base for invalid oid', () {
|
||||
|
@ -457,11 +399,13 @@ theirs content
|
|||
});
|
||||
|
||||
test('finds octopus merge base', () {
|
||||
final base = Merge.octopusBase(
|
||||
repo: repo,
|
||||
commits: [repo['1490545'], repo['0e409d6'], repo['5aecfa0']],
|
||||
expect(
|
||||
Merge.octopusBase(
|
||||
repo: repo,
|
||||
commits: [repo['1490545'], repo['0e409d6'], repo['5aecfa0']],
|
||||
).sha,
|
||||
'fc38877b2552ab554752d9a77e1f48f738cca79b',
|
||||
);
|
||||
expect(base.sha, 'fc38877b2552ab554752d9a77e1f48f738cca79b');
|
||||
});
|
||||
|
||||
test('throws when trying to find octopus merge base for invalid oid', () {
|
||||
|
@ -477,10 +421,6 @@ theirs content
|
|||
group('merge trees', () {
|
||||
test('merges with default values', () {
|
||||
final theirCommit = Commit.lookup(repo: repo, oid: repo['5aecfa0']);
|
||||
final theirCommitAnnotated = AnnotatedCommit.lookup(
|
||||
repo: repo,
|
||||
oid: theirCommit.oid,
|
||||
);
|
||||
final ourCommit = Commit.lookup(repo: repo, oid: repo['1490545']);
|
||||
final baseCommit = Commit.lookup(
|
||||
repo: repo,
|
||||
|
@ -489,36 +429,25 @@ theirs content
|
|||
commits: [ourCommit.oid, theirCommit.oid],
|
||||
),
|
||||
);
|
||||
final theirTree = theirCommit.tree;
|
||||
final ourTree = ourCommit.tree;
|
||||
final ancestorTree = baseCommit.tree;
|
||||
|
||||
final mergeIndex = Merge.trees(
|
||||
repo: repo,
|
||||
ancestorTree: ancestorTree,
|
||||
ourTree: ourTree,
|
||||
theirTree: theirTree,
|
||||
ancestorTree: baseCommit.tree,
|
||||
ourTree: ourCommit.tree,
|
||||
theirTree: theirCommit.tree,
|
||||
);
|
||||
expect(mergeIndex.conflicts, isEmpty);
|
||||
final mergeTreesTree = mergeIndex.writeTree(repo);
|
||||
|
||||
repo.setHead(ourCommit.oid);
|
||||
Merge.commit(repo: repo, commit: theirCommitAnnotated);
|
||||
final index = repo.index;
|
||||
expect(index.conflicts, isEmpty);
|
||||
final mergeTree = index.writeTree();
|
||||
Merge.commit(
|
||||
repo: repo,
|
||||
commit: AnnotatedCommit.lookup(repo: repo, oid: theirCommit.oid),
|
||||
);
|
||||
expect(repo.index.conflicts, isEmpty);
|
||||
|
||||
final mergeTree = repo.index.writeTree();
|
||||
expect(mergeTreesTree == mergeTree, true);
|
||||
|
||||
index.free();
|
||||
mergeIndex.free();
|
||||
ancestorTree.free();
|
||||
ourTree.free();
|
||||
theirTree.free();
|
||||
baseCommit.free();
|
||||
ourCommit.free();
|
||||
theirCommitAnnotated.free();
|
||||
theirCommit.free();
|
||||
});
|
||||
|
||||
test('merges with provided favor', () {
|
||||
|
@ -531,26 +460,15 @@ theirs content
|
|||
commits: [ourCommit.oid, theirCommit.oid],
|
||||
),
|
||||
);
|
||||
final theirTree = theirCommit.tree;
|
||||
final ourTree = ourCommit.tree;
|
||||
final ancestorTree = baseCommit.tree;
|
||||
|
||||
final mergeIndex = Merge.trees(
|
||||
repo: repo,
|
||||
ancestorTree: ancestorTree,
|
||||
ourTree: ourTree,
|
||||
theirTree: theirTree,
|
||||
ancestorTree: baseCommit.tree,
|
||||
ourTree: ourCommit.tree,
|
||||
theirTree: theirCommit.tree,
|
||||
favor: GitMergeFileFavor.ours,
|
||||
);
|
||||
expect(mergeIndex.conflicts, isEmpty);
|
||||
|
||||
mergeIndex.free();
|
||||
ancestorTree.free();
|
||||
ourTree.free();
|
||||
theirTree.free();
|
||||
baseCommit.free();
|
||||
ourCommit.free();
|
||||
theirCommit.free();
|
||||
});
|
||||
|
||||
test('throws when error occurs', () {
|
||||
|
@ -567,21 +485,17 @@ theirs content
|
|||
});
|
||||
|
||||
test('cherry-picks commit', () {
|
||||
final cherry = Commit.lookup(repo: repo, oid: repo['5aecfa0']);
|
||||
Merge.cherryPick(repo: repo, commit: cherry);
|
||||
Merge.cherryPick(
|
||||
repo: repo,
|
||||
commit: Commit.lookup(repo: repo, oid: repo['5aecfa0']),
|
||||
);
|
||||
expect(repo.state, GitRepositoryState.cherrypick);
|
||||
expect(repo.message, 'add another feature file\n');
|
||||
final index = repo.index;
|
||||
expect(index.conflicts, isEmpty);
|
||||
expect(repo.index.conflicts, isEmpty);
|
||||
|
||||
// pretend we've done commit
|
||||
repo.removeMessage();
|
||||
expect(
|
||||
() => repo.message,
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
|
||||
index.free();
|
||||
expect(() => repo.message, throwsA(isA<LibGit2Error>()));
|
||||
});
|
||||
|
||||
test('throws when error occurs', () {
|
||||
|
|
|
@ -43,7 +43,6 @@ void main() {
|
|||
expect(notes[i].oid.sha, notesExpected[i]['oid']);
|
||||
expect(notes[i].message, notesExpected[i]['message']);
|
||||
expect(notes[i].annotatedOid.sha, notesExpected[i]['annotatedOid']);
|
||||
notes[i].free();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -53,15 +52,11 @@ void main() {
|
|||
});
|
||||
|
||||
test('lookups note', () {
|
||||
final head = repo.head;
|
||||
final note = Note.lookup(repo: repo, annotatedOid: head.target);
|
||||
final note = Note.lookup(repo: repo, annotatedOid: repo.head.target);
|
||||
|
||||
expect(note.oid.sha, notesExpected[1]['oid']);
|
||||
expect(note.message, notesExpected[1]['message']);
|
||||
expect(note.annotatedOid.sha, notesExpected[1]['annotatedOid']);
|
||||
|
||||
note.free();
|
||||
head.free();
|
||||
});
|
||||
|
||||
test('creates note', () {
|
||||
|
@ -70,23 +65,20 @@ void main() {
|
|||
email: 'author@email.com',
|
||||
time: 1234,
|
||||
);
|
||||
final head = repo.head;
|
||||
final noteOid = Note.create(
|
||||
repo: repo,
|
||||
author: signature,
|
||||
committer: signature,
|
||||
annotatedOid: head.target,
|
||||
annotatedOid: repo.head.target,
|
||||
note: 'New note for HEAD',
|
||||
force: true,
|
||||
);
|
||||
final noteBlob = Blob.lookup(repo: repo, oid: noteOid);
|
||||
|
||||
expect(noteOid.sha, 'ffd6e2ceaf91c00ea6d29e2e897f906da720529f');
|
||||
expect(noteBlob.content, 'New note for HEAD');
|
||||
|
||||
noteBlob.free();
|
||||
head.free();
|
||||
signature.free();
|
||||
expect(
|
||||
Blob.lookup(repo: repo, oid: noteOid).content,
|
||||
'New note for HEAD',
|
||||
);
|
||||
});
|
||||
|
||||
test('throws when trying to create note and error occurs', () {
|
||||
|
@ -108,7 +100,6 @@ void main() {
|
|||
email: 'author@email.com',
|
||||
time: 1234,
|
||||
);
|
||||
final head = repo.head;
|
||||
|
||||
Note.delete(
|
||||
repo: repo,
|
||||
|
@ -118,12 +109,9 @@ void main() {
|
|||
);
|
||||
|
||||
expect(
|
||||
() => Note.lookup(repo: repo, annotatedOid: head.target),
|
||||
() => Note.lookup(repo: repo, annotatedOid: repo.head.target),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
|
||||
head.free();
|
||||
signature.free();
|
||||
});
|
||||
|
||||
test('throws when trying to delete note and error occurs', () {
|
||||
|
@ -138,10 +126,14 @@ void main() {
|
|||
);
|
||||
});
|
||||
|
||||
test('manually releases allocated memory', () {
|
||||
final note = Note.lookup(repo: repo, annotatedOid: repo['821ed6e']);
|
||||
expect(() => note.free(), returnsNormally);
|
||||
});
|
||||
|
||||
test('returns string representation of Note object', () {
|
||||
final note = Note.lookup(repo: repo, annotatedOid: repo['821ed6e']);
|
||||
expect(note.toString(), contains('Note{'));
|
||||
note.free();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -26,9 +26,7 @@ void main() {
|
|||
|
||||
group('Odb', () {
|
||||
test('successfully initializes', () {
|
||||
final odb = repo.odb;
|
||||
expect(odb, isA<Odb>());
|
||||
odb.free();
|
||||
expect(repo.odb, isA<Odb>());
|
||||
});
|
||||
|
||||
test('throws when trying to get odb and error occurs', () {
|
||||
|
@ -36,9 +34,7 @@ void main() {
|
|||
});
|
||||
|
||||
test('creates new odb with no backends', () {
|
||||
final odb = Odb.create();
|
||||
expect(odb, isA<Odb>());
|
||||
odb.free();
|
||||
expect(Odb.create(), isA<Odb>());
|
||||
});
|
||||
|
||||
test('adds disk alternate', () {
|
||||
|
@ -46,33 +42,22 @@ void main() {
|
|||
odb.addDiskAlternate(p.join(repo.path, 'objects'));
|
||||
|
||||
expect(odb.contains(repo[blobSha]), true);
|
||||
|
||||
odb.free();
|
||||
});
|
||||
|
||||
test('reads object', () {
|
||||
final oid = repo[blobSha];
|
||||
final odb = repo.odb;
|
||||
final object = odb.read(oid);
|
||||
final object = repo.odb.read(repo[blobSha]);
|
||||
|
||||
expect(object.oid, oid);
|
||||
expect(object.oid, repo[blobSha]);
|
||||
expect(object.type, GitObject.blob);
|
||||
expect(object.data, blobContent);
|
||||
expect(object.size, 13);
|
||||
|
||||
object.free();
|
||||
odb.free();
|
||||
});
|
||||
|
||||
test('throws when trying to read object and error occurs', () {
|
||||
final odb = repo.odb;
|
||||
|
||||
expect(
|
||||
() => odb.read(repo['0' * 40]),
|
||||
() => repo.odb.read(repo['0' * 40]),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
|
||||
odb.free();
|
||||
});
|
||||
|
||||
test("returns list of all objects oid's in database", () {
|
||||
|
@ -80,8 +65,6 @@ void main() {
|
|||
|
||||
expect(odb.objects, isNot(isEmpty));
|
||||
expect(odb.objects.contains(repo[commitSha]), true);
|
||||
|
||||
odb.free();
|
||||
});
|
||||
|
||||
test('throws when trying to get list of all objects and error occurs', () {
|
||||
|
@ -92,8 +75,6 @@ void main() {
|
|||
() => odb.objects,
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
|
||||
odb.free();
|
||||
});
|
||||
|
||||
test('writes data', () {
|
||||
|
@ -103,19 +84,13 @@ void main() {
|
|||
|
||||
expect(odb.contains(oid), true);
|
||||
expect(object.data, 'testing');
|
||||
|
||||
object.free();
|
||||
odb.free();
|
||||
});
|
||||
|
||||
test('throws when trying to write with invalid object type', () {
|
||||
final odb = repo.odb;
|
||||
expect(
|
||||
() => odb.write(type: GitObject.any, data: 'testing'),
|
||||
() => repo.odb.write(type: GitObject.any, data: 'testing'),
|
||||
throwsA(isA<ArgumentError>()),
|
||||
);
|
||||
|
||||
odb.free();
|
||||
});
|
||||
|
||||
test('throws when trying to write alternate odb to disk', () {
|
||||
|
@ -126,15 +101,20 @@ void main() {
|
|||
() => odb.write(type: GitObject.blob, data: ''),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
});
|
||||
|
||||
odb.free();
|
||||
test('manually releases allocated memory', () {
|
||||
expect(() => repo.odb.free(), returnsNormally);
|
||||
});
|
||||
|
||||
test('manually releases allocated memory for odbObject object', () {
|
||||
final object = repo.odb.read(repo[blobSha]);
|
||||
expect(() => object.free(), returnsNormally);
|
||||
});
|
||||
|
||||
test('returns string representation of OdbObject object', () {
|
||||
final odb = repo.odb;
|
||||
final object = odb.read(repo[blobSha]);
|
||||
final object = repo.odb.read(repo[blobSha]);
|
||||
expect(object.toString(), contains('OdbObject{'));
|
||||
odb.free();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -29,8 +29,6 @@ void main() {
|
|||
|
||||
expect(packbuilder, isA<PackBuilder>());
|
||||
expect(packbuilder.length, 0);
|
||||
|
||||
packbuilder.free();
|
||||
});
|
||||
|
||||
test('throws when trying to initialize and error occurs', () {
|
||||
|
@ -49,20 +47,13 @@ void main() {
|
|||
|
||||
packbuilder.add(odb.objects[1]);
|
||||
expect(packbuilder.length, 2);
|
||||
|
||||
odb.free();
|
||||
packbuilder.free();
|
||||
});
|
||||
|
||||
test('throws when trying to add object and error occurs', () {
|
||||
final packbuilder = PackBuilder(repo);
|
||||
|
||||
expect(
|
||||
() => packbuilder.add(Oid(nullptr)),
|
||||
() => PackBuilder(repo).add(Oid(nullptr)),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
|
||||
packbuilder.free();
|
||||
});
|
||||
|
||||
test('adds object recursively', () {
|
||||
|
@ -71,119 +62,86 @@ void main() {
|
|||
|
||||
packbuilder.addRecursively(oid);
|
||||
expect(packbuilder.length, 3);
|
||||
|
||||
packbuilder.free();
|
||||
});
|
||||
|
||||
test('throws when trying to add object recursively and error occurs', () {
|
||||
final packbuilder = PackBuilder(repo);
|
||||
|
||||
expect(
|
||||
() => packbuilder.addRecursively(Oid(nullptr)),
|
||||
() => PackBuilder(repo).addRecursively(Oid(nullptr)),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
|
||||
packbuilder.free();
|
||||
});
|
||||
|
||||
test('adds commit', () {
|
||||
final packbuilder = PackBuilder(repo);
|
||||
final oid = repo['f17d0d4'];
|
||||
|
||||
packbuilder.addCommit(oid);
|
||||
packbuilder.addCommit(repo['f17d0d4']);
|
||||
expect(packbuilder.length, 3);
|
||||
|
||||
packbuilder.free();
|
||||
});
|
||||
|
||||
test('throws when trying to add commit with invalid oid', () {
|
||||
final packbuilder = PackBuilder(repo);
|
||||
final oid = Oid.fromSHA(repo: repo, sha: '0' * 40);
|
||||
|
||||
expect(() => packbuilder.addCommit(oid), throwsA(isA<LibGit2Error>()));
|
||||
|
||||
packbuilder.free();
|
||||
expect(
|
||||
() => PackBuilder(repo).addCommit(oid),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
});
|
||||
|
||||
test('adds tree', () {
|
||||
final packbuilder = PackBuilder(repo);
|
||||
final oid = repo['df2b8fc'];
|
||||
|
||||
packbuilder.addTree(oid);
|
||||
packbuilder.addTree(repo['df2b8fc']);
|
||||
expect(packbuilder.length, 2);
|
||||
|
||||
packbuilder.free();
|
||||
});
|
||||
|
||||
test('throws when trying to add tree with invalid oid', () {
|
||||
final packbuilder = PackBuilder(repo);
|
||||
final oid = Oid.fromSHA(repo: repo, sha: '0' * 40);
|
||||
|
||||
expect(() => packbuilder.addTree(oid), throwsA(isA<LibGit2Error>()));
|
||||
|
||||
packbuilder.free();
|
||||
expect(
|
||||
() => PackBuilder(repo).addTree(oid),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
});
|
||||
|
||||
test('adds objects with walker', () {
|
||||
final oid = repo['f17d0d4'];
|
||||
final packbuilder = PackBuilder(repo);
|
||||
final walker = RevWalk(repo);
|
||||
walker.sorting({GitSort.none});
|
||||
walker.push(oid);
|
||||
walker.push(repo['f17d0d4']);
|
||||
|
||||
packbuilder.addWalk(walker);
|
||||
expect(packbuilder.length, 3);
|
||||
|
||||
walker.free();
|
||||
packbuilder.free();
|
||||
});
|
||||
|
||||
test('sets number of threads', () {
|
||||
final packbuilder = PackBuilder(repo);
|
||||
|
||||
expect(packbuilder.setThreads(1), 1);
|
||||
|
||||
packbuilder.free();
|
||||
expect(PackBuilder(repo).setThreads(1), 1);
|
||||
});
|
||||
|
||||
test('returns name of packfile', () {
|
||||
final packbuilder = PackBuilder(repo);
|
||||
final odb = repo.odb;
|
||||
|
||||
packbuilder.add(odb.objects[0]);
|
||||
packbuilder.add(repo.odb.objects[0]);
|
||||
Directory(packDirPath).createSync();
|
||||
|
||||
expect(packbuilder.name, isEmpty);
|
||||
packbuilder.write(null);
|
||||
expect(packbuilder.name, isNotEmpty);
|
||||
|
||||
packbuilder.free();
|
||||
});
|
||||
|
||||
test('packs with default arguments', () {
|
||||
final odb = repo.odb;
|
||||
final objectsCount = odb.objects.length;
|
||||
final objectsCount = repo.odb.objects.length;
|
||||
Directory(packDirPath).createSync();
|
||||
|
||||
final writtenCount = repo.pack();
|
||||
|
||||
expect(writtenCount, objectsCount);
|
||||
|
||||
odb.free();
|
||||
expect(repo.pack(), objectsCount);
|
||||
});
|
||||
|
||||
test('packs into provided path with threads set', () {
|
||||
final odb = repo.odb;
|
||||
final objectsCount = odb.objects.length;
|
||||
final testPackPath = p.join(repo.workdir, 'test-pack');
|
||||
Directory(testPackPath).createSync();
|
||||
|
||||
final writtenCount = repo.pack(path: testPackPath, threads: 1);
|
||||
|
||||
expect(writtenCount, objectsCount);
|
||||
expect(writtenCount, repo.odb.objects.length);
|
||||
expect(Directory(testPackPath).listSync().isNotEmpty, true);
|
||||
|
||||
odb.free();
|
||||
});
|
||||
|
||||
test('packs with provided packDelegate', () {
|
||||
|
@ -198,32 +156,26 @@ void main() {
|
|||
);
|
||||
for (final commit in repo.log(oid: ref.target)) {
|
||||
packBuilder.addRecursively(commit.oid);
|
||||
commit.free();
|
||||
}
|
||||
ref.free();
|
||||
branch.free();
|
||||
}
|
||||
}
|
||||
|
||||
final writtenCount = repo.pack(packDelegate: packDelegate);
|
||||
expect(writtenCount, 18);
|
||||
expect(repo.pack(packDelegate: packDelegate), 18);
|
||||
});
|
||||
|
||||
test('throws when trying to write pack into invalid path', () {
|
||||
final packbuilder = PackBuilder(repo);
|
||||
|
||||
expect(
|
||||
() => packbuilder.write('invalid/path'),
|
||||
() => PackBuilder(repo).write('invalid/path'),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
});
|
||||
|
||||
packbuilder.free();
|
||||
test('manually releases allocated memory', () {
|
||||
expect(() => PackBuilder(repo).free(), returnsNormally);
|
||||
});
|
||||
|
||||
test('returns string representation of PackBuilder object', () {
|
||||
final packbuilder = PackBuilder(repo);
|
||||
expect(packbuilder.toString(), contains('PackBuilder{'));
|
||||
packbuilder.free();
|
||||
expect(PackBuilder(repo).toString(), contains('PackBuilder{'));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -65,8 +65,6 @@ index e69de29..0000000
|
|||
|
||||
expect(patch.size(), 14);
|
||||
expect(patch.text, blobPatch);
|
||||
|
||||
patch.free();
|
||||
});
|
||||
|
||||
test('creates from one buffer (add)', () {
|
||||
|
@ -78,8 +76,6 @@ index e69de29..0000000
|
|||
);
|
||||
|
||||
expect(patch.text, blobPatchAdd);
|
||||
|
||||
patch.free();
|
||||
});
|
||||
|
||||
test('creates from one buffer (delete)', () {
|
||||
|
@ -91,65 +87,50 @@ index e69de29..0000000
|
|||
);
|
||||
|
||||
expect(patch.text, blobPatchDelete);
|
||||
|
||||
patch.free();
|
||||
});
|
||||
|
||||
test('creates from blobs', () {
|
||||
final oldBlob = Blob.lookup(repo: repo, oid: oldBlobOid);
|
||||
final newBlob = Blob.lookup(repo: repo, oid: newBlobOid);
|
||||
final patch = Patch.fromBlobs(
|
||||
oldBlob: oldBlob,
|
||||
newBlob: newBlob,
|
||||
oldBlob: Blob.lookup(repo: repo, oid: oldBlobOid),
|
||||
newBlob: Blob.lookup(repo: repo, oid: newBlobOid),
|
||||
oldBlobPath: path,
|
||||
newBlobPath: path,
|
||||
);
|
||||
|
||||
expect(patch.text, blobPatch);
|
||||
|
||||
patch.free();
|
||||
});
|
||||
|
||||
test('creates from one blob (add)', () {
|
||||
final newBlob = Blob.lookup(repo: repo, oid: newBlobOid);
|
||||
final patch = Patch.fromBlobs(
|
||||
oldBlob: null,
|
||||
newBlob: newBlob,
|
||||
newBlob: Blob.lookup(repo: repo, oid: newBlobOid),
|
||||
oldBlobPath: path,
|
||||
newBlobPath: path,
|
||||
);
|
||||
|
||||
expect(patch.text, blobPatchAdd);
|
||||
|
||||
patch.free();
|
||||
});
|
||||
|
||||
test('creates from one blob (delete)', () {
|
||||
final oldBlob = Blob.lookup(repo: repo, oid: oldBlobOid);
|
||||
final patch = Patch.fromBlobs(
|
||||
oldBlob: oldBlob,
|
||||
oldBlob: Blob.lookup(repo: repo, oid: oldBlobOid),
|
||||
newBlob: null,
|
||||
oldBlobPath: path,
|
||||
newBlobPath: path,
|
||||
);
|
||||
|
||||
expect(patch.text, blobPatchDelete);
|
||||
|
||||
patch.free();
|
||||
});
|
||||
|
||||
test('creates from blob and buffer', () {
|
||||
final blob = Blob.lookup(repo: repo, oid: oldBlobOid);
|
||||
final patch = Patch.fromBlobAndBuffer(
|
||||
blob: blob,
|
||||
blob: Blob.lookup(repo: repo, oid: oldBlobOid),
|
||||
buffer: newBuffer,
|
||||
blobPath: path,
|
||||
bufferPath: path,
|
||||
);
|
||||
|
||||
expect(patch.text, blobPatch);
|
||||
|
||||
patch.free();
|
||||
});
|
||||
|
||||
test('creates from empty blob and buffer', () {
|
||||
|
@ -161,8 +142,6 @@ index e69de29..0000000
|
|||
);
|
||||
|
||||
expect(patch.text, blobPatchAdd);
|
||||
|
||||
patch.free();
|
||||
});
|
||||
|
||||
test('throws when trying to create from diff and error occurs', () {
|
||||
|
@ -176,6 +155,43 @@ index e69de29..0000000
|
|||
expect(() => Patch(nullptr).text, throwsA(isA<LibGit2Error>()));
|
||||
});
|
||||
|
||||
test('returns hunks in a patch', () {
|
||||
final patch = Patch.fromBuffers(
|
||||
oldBuffer: oldBuffer,
|
||||
newBuffer: newBuffer,
|
||||
oldBufferPath: path,
|
||||
newBufferPath: path,
|
||||
);
|
||||
final hunk = patch.hunks[0];
|
||||
|
||||
expect(patch.hunks.length, 1);
|
||||
expect(hunk.linesCount, 1);
|
||||
expect(hunk.oldStart, 0);
|
||||
expect(hunk.oldLines, 0);
|
||||
expect(hunk.newStart, 1);
|
||||
expect(hunk.newLines, 1);
|
||||
expect(hunk.header, '@@ -0,0 +1 @@\n');
|
||||
});
|
||||
|
||||
test('returns lines in a hunk', () {
|
||||
final patch = Patch.fromBuffers(
|
||||
oldBuffer: oldBuffer,
|
||||
newBuffer: newBuffer,
|
||||
oldBufferPath: path,
|
||||
newBufferPath: path,
|
||||
);
|
||||
final hunk = patch.hunks[0];
|
||||
final line = hunk.lines[0];
|
||||
|
||||
expect(hunk.lines.length, 1);
|
||||
expect(line.origin, GitDiffLine.addition);
|
||||
expect(line.oldLineNumber, -1);
|
||||
expect(line.newLineNumber, 1);
|
||||
expect(line.numLines, 1);
|
||||
expect(line.contentOffset, 0);
|
||||
expect(line.content, 'Feature edit\n');
|
||||
});
|
||||
|
||||
test('returns line counts of each type in a patch', () {
|
||||
final patch = Patch.fromBuffers(
|
||||
oldBuffer: oldBuffer,
|
||||
|
@ -189,11 +205,21 @@ index e69de29..0000000
|
|||
expect(stats.insertions, equals(1));
|
||||
expect(stats.deletions, equals(0));
|
||||
expect(stats.toString(), contains('PatchStats{'));
|
||||
|
||||
patch.free();
|
||||
});
|
||||
|
||||
test('returns string representation of Patch object', () {
|
||||
test('manually releases allocated memory', () {
|
||||
final patch = Patch.fromBuffers(
|
||||
oldBuffer: oldBuffer,
|
||||
newBuffer: newBuffer,
|
||||
oldBufferPath: path,
|
||||
newBufferPath: path,
|
||||
);
|
||||
expect(() => patch.free(), returnsNormally);
|
||||
});
|
||||
|
||||
test(
|
||||
'returns string representation of Patch, DiffHunk and DiffLine objects',
|
||||
() {
|
||||
final patch = Patch.fromBuffers(
|
||||
oldBuffer: oldBuffer,
|
||||
newBuffer: newBuffer,
|
||||
|
@ -202,8 +228,8 @@ index e69de29..0000000
|
|||
);
|
||||
|
||||
expect(patch.toString(), contains('Patch{'));
|
||||
|
||||
patch.free();
|
||||
expect(patch.hunks[0].toString(), contains('DiffHunk{'));
|
||||
expect(patch.hunks[0].lines[0].toString(), contains('DiffLine{'));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -33,15 +33,7 @@ void main() {
|
|||
time: 1234,
|
||||
);
|
||||
final master = Reference.lookup(repo: repo, name: 'refs/heads/master');
|
||||
final branchHead = AnnotatedCommit.fromReference(
|
||||
repo: repo,
|
||||
reference: master,
|
||||
);
|
||||
final feature = Reference.lookup(repo: repo, name: 'refs/heads/feature');
|
||||
final ontoHead = AnnotatedCommit.fromReference(
|
||||
repo: repo,
|
||||
reference: feature,
|
||||
);
|
||||
|
||||
Checkout.reference(repo: repo, name: feature.name);
|
||||
repo.setHead(feature.name);
|
||||
|
@ -49,8 +41,8 @@ void main() {
|
|||
|
||||
final rebase = Rebase.init(
|
||||
repo: repo,
|
||||
branch: branchHead,
|
||||
onto: ontoHead,
|
||||
branch: AnnotatedCommit.fromReference(repo: repo, reference: master),
|
||||
onto: AnnotatedCommit.fromReference(repo: repo, reference: feature),
|
||||
);
|
||||
|
||||
expect(rebase.origHeadOid, master.target);
|
||||
|
@ -76,13 +68,6 @@ void main() {
|
|||
|
||||
rebase.finish();
|
||||
expect(repo.index['.gitignore'], isA<IndexEntry>());
|
||||
|
||||
rebase.free();
|
||||
ontoHead.free();
|
||||
branchHead.free();
|
||||
feature.free();
|
||||
master.free();
|
||||
signature.free();
|
||||
});
|
||||
|
||||
test('performs rebase without branch provided', () {
|
||||
|
@ -92,11 +77,10 @@ void main() {
|
|||
time: 1234,
|
||||
);
|
||||
final feature = Reference.lookup(repo: repo, name: 'refs/heads/feature');
|
||||
final ontoHead = AnnotatedCommit.lookup(repo: repo, oid: feature.target);
|
||||
|
||||
final rebase = Rebase.init(
|
||||
repo: repo,
|
||||
onto: ontoHead,
|
||||
onto: AnnotatedCommit.lookup(repo: repo, oid: feature.target),
|
||||
);
|
||||
|
||||
expect(
|
||||
|
@ -124,11 +108,6 @@ void main() {
|
|||
}
|
||||
|
||||
rebase.finish();
|
||||
|
||||
rebase.free();
|
||||
ontoHead.free();
|
||||
feature.free();
|
||||
signature.free();
|
||||
});
|
||||
|
||||
test('performs rebase with provided upstream', () {
|
||||
|
@ -138,9 +117,7 @@ void main() {
|
|||
time: 1234,
|
||||
);
|
||||
final master = Reference.lookup(repo: repo, name: 'refs/heads/master');
|
||||
final branchHead = AnnotatedCommit.lookup(repo: repo, oid: master.target);
|
||||
final feature = Reference.lookup(repo: repo, name: 'refs/heads/feature');
|
||||
final upstream = AnnotatedCommit.lookup(repo: repo, oid: repo[shas[1]]);
|
||||
|
||||
Checkout.reference(repo: repo, name: feature.name);
|
||||
repo.setHead(feature.name);
|
||||
|
@ -148,8 +125,8 @@ void main() {
|
|||
|
||||
final rebase = Rebase.init(
|
||||
repo: repo,
|
||||
branch: branchHead,
|
||||
upstream: upstream,
|
||||
branch: AnnotatedCommit.lookup(repo: repo, oid: master.target),
|
||||
upstream: AnnotatedCommit.lookup(repo: repo, oid: repo[shas[1]]),
|
||||
);
|
||||
|
||||
expect(rebase.origHeadOid, master.target);
|
||||
|
@ -170,13 +147,6 @@ void main() {
|
|||
|
||||
rebase.finish();
|
||||
expect(repo.index['conflict_file'], isA<IndexEntry>());
|
||||
|
||||
rebase.free();
|
||||
upstream.free();
|
||||
branchHead.free();
|
||||
feature.free();
|
||||
master.free();
|
||||
signature.free();
|
||||
});
|
||||
|
||||
test(
|
||||
|
@ -191,21 +161,21 @@ void main() {
|
|||
email: 'author@email.com',
|
||||
time: 1234,
|
||||
);
|
||||
final master = Reference.lookup(repo: repo, name: 'refs/heads/master');
|
||||
final branchHead = AnnotatedCommit.lookup(repo: repo, oid: master.target);
|
||||
final conflict = Reference.lookup(
|
||||
repo: repo,
|
||||
name: 'refs/heads/conflict-branch',
|
||||
);
|
||||
final ontoHead = AnnotatedCommit.lookup(repo: repo, oid: conflict.target);
|
||||
|
||||
Checkout.reference(repo: repo, name: conflict.name);
|
||||
repo.setHead(conflict.name);
|
||||
|
||||
final rebase = Rebase.init(
|
||||
repo: repo,
|
||||
branch: branchHead,
|
||||
onto: ontoHead,
|
||||
branch: AnnotatedCommit.lookup(
|
||||
repo: repo,
|
||||
oid: Reference.lookup(repo: repo, name: 'refs/heads/master').target,
|
||||
),
|
||||
onto: AnnotatedCommit.lookup(repo: repo, oid: conflict.target),
|
||||
);
|
||||
expect(rebase.operations.length, 1);
|
||||
|
||||
|
@ -216,67 +186,48 @@ void main() {
|
|||
() => rebase.commit(committer: signature),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
|
||||
rebase.free();
|
||||
ontoHead.free();
|
||||
branchHead.free();
|
||||
conflict.free();
|
||||
master.free();
|
||||
signature.free();
|
||||
});
|
||||
|
||||
test('throws when trying to perfrom next rebase operation and error occurs',
|
||||
() {
|
||||
final signature = Signature.create(
|
||||
name: 'Author',
|
||||
email: 'author@email.com',
|
||||
time: 1234,
|
||||
);
|
||||
final master = Reference.lookup(repo: repo, name: 'refs/heads/master');
|
||||
final branchHead = AnnotatedCommit.lookup(repo: repo, oid: master.target);
|
||||
final conflict = Reference.lookup(
|
||||
repo: repo,
|
||||
name: 'refs/heads/conflict-branch',
|
||||
);
|
||||
final ontoHead = AnnotatedCommit.lookup(repo: repo, oid: conflict.target);
|
||||
|
||||
Checkout.reference(repo: repo, name: conflict.name);
|
||||
repo.setHead(conflict.name);
|
||||
|
||||
final rebase = Rebase.init(
|
||||
repo: repo,
|
||||
branch: branchHead,
|
||||
onto: ontoHead,
|
||||
branch: AnnotatedCommit.lookup(
|
||||
repo: repo,
|
||||
oid: Reference.lookup(repo: repo, name: 'refs/heads/master').target,
|
||||
),
|
||||
onto: AnnotatedCommit.lookup(repo: repo, oid: conflict.target),
|
||||
);
|
||||
expect(rebase.operations.length, 1);
|
||||
|
||||
rebase.next(); // repo now have conflicts
|
||||
expect(() => rebase.next(), throwsA(isA<LibGit2Error>()));
|
||||
|
||||
rebase.free();
|
||||
ontoHead.free();
|
||||
branchHead.free();
|
||||
conflict.free();
|
||||
master.free();
|
||||
signature.free();
|
||||
});
|
||||
|
||||
test('aborts rebase in progress', () {
|
||||
final master = Reference.lookup(repo: repo, name: 'refs/heads/master');
|
||||
final branchHead = AnnotatedCommit.lookup(repo: repo, oid: master.target);
|
||||
final conflict = Reference.lookup(
|
||||
repo: repo,
|
||||
name: 'refs/heads/conflict-branch',
|
||||
);
|
||||
final ontoHead = AnnotatedCommit.lookup(repo: repo, oid: conflict.target);
|
||||
|
||||
Checkout.reference(repo: repo, name: conflict.name);
|
||||
repo.setHead(conflict.name);
|
||||
|
||||
final rebase = Rebase.init(
|
||||
repo: repo,
|
||||
branch: branchHead,
|
||||
onto: ontoHead,
|
||||
branch: AnnotatedCommit.lookup(
|
||||
repo: repo,
|
||||
oid: Reference.lookup(repo: repo, name: 'refs/heads/master').target,
|
||||
),
|
||||
onto: AnnotatedCommit.lookup(repo: repo, oid: conflict.target),
|
||||
);
|
||||
expect(rebase.operations.length, 1);
|
||||
|
||||
|
@ -287,35 +238,36 @@ void main() {
|
|||
rebase.abort();
|
||||
expect(repo.status, isEmpty);
|
||||
expect(repo.state, GitRepositoryState.none);
|
||||
|
||||
rebase.free();
|
||||
ontoHead.free();
|
||||
branchHead.free();
|
||||
conflict.free();
|
||||
master.free();
|
||||
});
|
||||
|
||||
test('opens an existing rebase', () {
|
||||
final feature = Reference.lookup(repo: repo, name: 'refs/heads/feature');
|
||||
final ontoHead = AnnotatedCommit.lookup(repo: repo, oid: feature.target);
|
||||
|
||||
final rebase = Rebase.init(
|
||||
repo: repo,
|
||||
onto: ontoHead,
|
||||
onto: AnnotatedCommit.lookup(
|
||||
repo: repo,
|
||||
oid: Reference.lookup(repo: repo, name: 'refs/heads/feature').target,
|
||||
),
|
||||
);
|
||||
expect(rebase.operations.length, 3);
|
||||
|
||||
final openRebase = Rebase.open(repo);
|
||||
expect(openRebase.operations.length, 3);
|
||||
|
||||
openRebase.free();
|
||||
rebase.free();
|
||||
ontoHead.free();
|
||||
feature.free();
|
||||
});
|
||||
|
||||
test('throws when trying to open an existing rebase but there is none', () {
|
||||
expect(() => Rebase.open(repo), throwsA(isA<LibGit2Error>()));
|
||||
});
|
||||
|
||||
test('manually releases allocated memory', () {
|
||||
final rebase = Rebase.init(
|
||||
repo: repo,
|
||||
onto: AnnotatedCommit.lookup(
|
||||
repo: repo,
|
||||
oid: Reference.lookup(repo: repo, name: 'refs/heads/feature').target,
|
||||
),
|
||||
);
|
||||
|
||||
expect(() => rebase.free(), returnsNormally);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -46,25 +46,22 @@ void main() {
|
|||
});
|
||||
|
||||
test('returns correct type of reference', () {
|
||||
final head = repo.head;
|
||||
expect(head.type, ReferenceType.direct);
|
||||
head.free();
|
||||
|
||||
final ref = Reference.lookup(repo: repo, name: 'HEAD');
|
||||
expect(ref.type, ReferenceType.symbolic);
|
||||
ref.free();
|
||||
expect(repo.head.type, ReferenceType.direct);
|
||||
expect(
|
||||
Reference.lookup(repo: repo, name: 'HEAD').type,
|
||||
ReferenceType.symbolic,
|
||||
);
|
||||
});
|
||||
|
||||
test('returns SHA hex of direct reference', () {
|
||||
final head = repo.head;
|
||||
expect(head.target.sha, lastCommit);
|
||||
head.free();
|
||||
expect(repo.head.target.sha, lastCommit);
|
||||
});
|
||||
|
||||
test('returns SHA hex of symbolic reference', () {
|
||||
final ref = Reference.lookup(repo: repo, name: 'HEAD');
|
||||
expect(ref.target.sha, lastCommit);
|
||||
ref.free();
|
||||
expect(
|
||||
Reference.lookup(repo: repo, name: 'HEAD').target.sha,
|
||||
lastCommit,
|
||||
);
|
||||
});
|
||||
|
||||
test('throws when trying to resolve invalid reference', () {
|
||||
|
@ -75,9 +72,7 @@ void main() {
|
|||
});
|
||||
|
||||
test('returns the full name', () {
|
||||
final head = repo.head;
|
||||
expect(head.name, 'refs/heads/master');
|
||||
head.free();
|
||||
expect(repo.head.name, 'refs/heads/master');
|
||||
});
|
||||
|
||||
test('returns the short name', () {
|
||||
|
@ -87,25 +82,22 @@ void main() {
|
|||
target: repo[lastCommit],
|
||||
);
|
||||
|
||||
final head = repo.head;
|
||||
|
||||
expect(head.shorthand, 'master');
|
||||
expect(repo.head.shorthand, 'master');
|
||||
expect(ref.shorthand, 'origin/upstream');
|
||||
|
||||
head.free();
|
||||
ref.free();
|
||||
});
|
||||
|
||||
test('checks if reference is a local branch', () {
|
||||
final ref = Reference.lookup(repo: repo, name: 'refs/heads/feature');
|
||||
expect(ref.isBranch, true);
|
||||
ref.free();
|
||||
expect(
|
||||
Reference.lookup(repo: repo, name: 'refs/heads/feature').isBranch,
|
||||
true,
|
||||
);
|
||||
});
|
||||
|
||||
test('checks if reference is a note', () {
|
||||
final ref = Reference.lookup(repo: repo, name: 'refs/heads/master');
|
||||
expect(ref.isNote, false);
|
||||
ref.free();
|
||||
expect(
|
||||
Reference.lookup(repo: repo, name: 'refs/heads/master').isNote,
|
||||
false,
|
||||
);
|
||||
});
|
||||
|
||||
test('checks if reference is a remote branch', () {
|
||||
|
@ -114,23 +106,25 @@ void main() {
|
|||
name: 'refs/remotes/origin/master',
|
||||
);
|
||||
expect(ref.isRemote, true);
|
||||
ref.free();
|
||||
});
|
||||
|
||||
test('checks if reference is a tag', () {
|
||||
final ref = Reference.lookup(repo: repo, name: 'refs/tags/v0.1');
|
||||
expect(ref.isTag, true);
|
||||
ref.free();
|
||||
expect(
|
||||
Reference.lookup(repo: repo, name: 'refs/tags/v0.1').isTag,
|
||||
true,
|
||||
);
|
||||
});
|
||||
|
||||
test('checks if reflog exists for the reference', () {
|
||||
var ref = Reference.lookup(repo: repo, name: 'refs/heads/master');
|
||||
expect(ref.hasLog, true);
|
||||
expect(
|
||||
Reference.lookup(repo: repo, name: 'refs/heads/master').hasLog,
|
||||
true,
|
||||
);
|
||||
|
||||
ref = Reference.lookup(repo: repo, name: 'refs/tags/v0.1');
|
||||
expect(ref.hasLog, false);
|
||||
|
||||
ref.free();
|
||||
expect(
|
||||
Reference.lookup(repo: repo, name: 'refs/tags/v0.1').hasLog,
|
||||
false,
|
||||
);
|
||||
});
|
||||
|
||||
test('ensures updates to the reference will append to its log', () {
|
||||
|
@ -141,12 +135,8 @@ void main() {
|
|||
name: 'refs/tags/tag',
|
||||
target: repo[lastCommit],
|
||||
);
|
||||
final reflog = ref.log;
|
||||
|
||||
expect(reflog.length, 1);
|
||||
|
||||
reflog.free();
|
||||
ref.free();
|
||||
expect(ref.log.length, 1);
|
||||
});
|
||||
|
||||
test('throws when trying to ensure there is a reflog and error occurs', () {
|
||||
|
@ -167,24 +157,17 @@ void main() {
|
|||
|
||||
expect(repo.references.length, 6);
|
||||
expect(duplicate.equals(ref), true);
|
||||
|
||||
duplicate.free();
|
||||
ref.free();
|
||||
});
|
||||
|
||||
group('create direct', () {
|
||||
test('creates with oid as target', () {
|
||||
final ref = Reference.lookup(repo: repo, name: 'refs/heads/master');
|
||||
final refFromOid = Reference.create(
|
||||
Reference.create(
|
||||
repo: repo,
|
||||
name: 'refs/tags/from.oid',
|
||||
target: ref.target,
|
||||
target: repo.head.target,
|
||||
);
|
||||
|
||||
expect(repo.references, contains('refs/tags/from.oid'));
|
||||
|
||||
refFromOid.free();
|
||||
ref.free();
|
||||
});
|
||||
|
||||
test('creates with log message', () {
|
||||
|
@ -196,15 +179,11 @@ void main() {
|
|||
logMessage: 'log message',
|
||||
);
|
||||
|
||||
final reflog = ref.log;
|
||||
final reflogEntry = reflog[0];
|
||||
final reflogEntry = ref.log[0];
|
||||
|
||||
expect(reflogEntry.message, 'log message');
|
||||
expect(reflogEntry.committer.name, 'name');
|
||||
expect(reflogEntry.committer.email, 'email');
|
||||
|
||||
reflog.free();
|
||||
ref.free();
|
||||
});
|
||||
|
||||
test('throws if target is not valid', () {
|
||||
|
@ -239,7 +218,7 @@ void main() {
|
|||
});
|
||||
|
||||
test('creates with force flag if name already exists', () {
|
||||
final ref = Reference.create(
|
||||
Reference.create(
|
||||
repo: repo,
|
||||
name: 'refs/tags/test',
|
||||
target: repo[lastCommit],
|
||||
|
@ -253,13 +232,10 @@ void main() {
|
|||
);
|
||||
|
||||
expect(forceRef.target.sha, lastCommit);
|
||||
|
||||
ref.free();
|
||||
forceRef.free();
|
||||
});
|
||||
|
||||
test('throws if name already exists', () {
|
||||
final ref = Reference.create(
|
||||
Reference.create(
|
||||
repo: repo,
|
||||
name: 'refs/tags/test',
|
||||
target: repo[lastCommit],
|
||||
|
@ -273,8 +249,6 @@ void main() {
|
|||
),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
|
||||
ref.free();
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -288,12 +262,10 @@ void main() {
|
|||
|
||||
expect(repo.references, contains('refs/tags/symbolic'));
|
||||
expect(ref.type, ReferenceType.symbolic);
|
||||
|
||||
ref.free();
|
||||
});
|
||||
|
||||
test('creates with force flag if name already exists', () {
|
||||
final ref = Reference.create(
|
||||
Reference.create(
|
||||
repo: repo,
|
||||
name: 'refs/tags/test',
|
||||
target: 'refs/heads/master',
|
||||
|
@ -308,13 +280,10 @@ void main() {
|
|||
|
||||
expect(forceRef.target.sha, lastCommit);
|
||||
expect(forceRef.type, ReferenceType.symbolic);
|
||||
|
||||
ref.free();
|
||||
forceRef.free();
|
||||
});
|
||||
|
||||
test('throws if name already exists', () {
|
||||
final ref = Reference.create(
|
||||
Reference.create(
|
||||
repo: repo,
|
||||
name: 'refs/tags/exists',
|
||||
target: 'refs/heads/master',
|
||||
|
@ -328,8 +297,6 @@ void main() {
|
|||
),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
|
||||
ref.free();
|
||||
});
|
||||
|
||||
test('throws if name is not valid', () {
|
||||
|
@ -353,21 +320,16 @@ void main() {
|
|||
logMessage: 'log message',
|
||||
);
|
||||
|
||||
final reflog = ref.log;
|
||||
final reflogEntry = reflog[0];
|
||||
final reflogEntry = ref.log[0];
|
||||
|
||||
expect(reflogEntry.message, 'log message');
|
||||
expect(reflogEntry.committer.name, 'name');
|
||||
expect(reflogEntry.committer.email, 'email');
|
||||
|
||||
reflog.free();
|
||||
ref.free();
|
||||
});
|
||||
});
|
||||
|
||||
test('deletes reference', () {
|
||||
expect(repo.references, contains('refs/tags/v0.1'));
|
||||
|
||||
Reference.delete(repo: repo, name: 'refs/tags/v0.1');
|
||||
expect(repo.references, isNot(contains('refs/tags/v0.1')));
|
||||
});
|
||||
|
@ -376,7 +338,6 @@ void main() {
|
|||
test('with provided name', () {
|
||||
final ref = Reference.lookup(repo: repo, name: 'refs/heads/master');
|
||||
expect(ref.target.sha, lastCommit);
|
||||
ref.free();
|
||||
});
|
||||
|
||||
test('throws when error occured', () {
|
||||
|
@ -389,11 +350,7 @@ void main() {
|
|||
|
||||
test('returns log for reference', () {
|
||||
final ref = Reference.lookup(repo: repo, name: 'refs/heads/master');
|
||||
final reflog = ref.log;
|
||||
expect(reflog.last.message, 'commit (initial): init');
|
||||
|
||||
reflog.free();
|
||||
ref.free();
|
||||
expect(ref.log.last.message, 'commit (initial): init');
|
||||
});
|
||||
|
||||
group('set target', () {
|
||||
|
@ -401,8 +358,6 @@ void main() {
|
|||
final ref = Reference.lookup(repo: repo, name: 'refs/heads/master');
|
||||
ref.setTarget(target: repo[newCommit]);
|
||||
expect(ref.target.sha, newCommit);
|
||||
|
||||
ref.free();
|
||||
});
|
||||
|
||||
test('sets symbolic target with provided reference name', () {
|
||||
|
@ -411,8 +366,6 @@ void main() {
|
|||
|
||||
ref.setTarget(target: 'refs/heads/feature');
|
||||
expect(ref.target.sha, '5aecfa0fb97eadaac050ccb99f03c3fb65460ad4');
|
||||
|
||||
ref.free();
|
||||
});
|
||||
|
||||
test('sets target with log message', () {
|
||||
|
@ -422,13 +375,10 @@ void main() {
|
|||
repo.setIdentity(name: 'name', email: 'email');
|
||||
ref.setTarget(target: 'refs/heads/feature', logMessage: 'log message');
|
||||
expect(ref.target.sha, '5aecfa0fb97eadaac050ccb99f03c3fb65460ad4');
|
||||
final reflog = ref.log;
|
||||
expect(reflog.first.message, 'log message');
|
||||
expect(reflog.first.committer.name, 'name');
|
||||
expect(reflog.first.committer.email, 'email');
|
||||
|
||||
reflog.free();
|
||||
ref.free();
|
||||
final logEntry = ref.log.first;
|
||||
expect(logEntry.message, 'log message');
|
||||
expect(logEntry.committer.name, 'name');
|
||||
expect(logEntry.committer.email, 'email');
|
||||
});
|
||||
|
||||
test('throws on invalid target', () {
|
||||
|
@ -444,8 +394,6 @@ void main() {
|
|||
);
|
||||
|
||||
expect(() => ref.setTarget(target: 0), throwsA(isA<ArgumentError>()));
|
||||
|
||||
ref.free();
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -508,9 +456,6 @@ void main() {
|
|||
);
|
||||
expect(repo.references, isNot(contains('refs/tags/v0.1')));
|
||||
expect(repo.references.length, 5);
|
||||
|
||||
ref1.free();
|
||||
ref2.free();
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -523,10 +468,6 @@ void main() {
|
|||
expect(ref1.notEquals(ref2), false);
|
||||
expect(ref1.equals(ref3), false);
|
||||
expect(ref1.notEquals(ref3), true);
|
||||
|
||||
ref1.free();
|
||||
ref2.free();
|
||||
ref3.free();
|
||||
});
|
||||
|
||||
test('peels to non-tag object when no type is provided', () {
|
||||
|
@ -535,23 +476,17 @@ void main() {
|
|||
final peeled = ref.peel() as Commit;
|
||||
|
||||
expect(peeled.oid, commit.oid);
|
||||
|
||||
peeled.free();
|
||||
commit.free();
|
||||
ref.free();
|
||||
});
|
||||
|
||||
test('peels to object of provided type', () {
|
||||
final ref = Reference.lookup(repo: repo, name: 'refs/heads/master');
|
||||
final blob = Blob.lookup(repo: repo, oid: repo['9c78c21']);
|
||||
final blobRef = Reference.create(
|
||||
repo: repo,
|
||||
name: 'refs/tags/blob',
|
||||
target: blob.oid,
|
||||
target: Blob.lookup(repo: repo, oid: repo['9c78c21']).oid,
|
||||
);
|
||||
final tagRef = Reference.lookup(repo: repo, name: 'refs/tags/v0.2');
|
||||
final commit = Commit.lookup(repo: repo, oid: ref.target);
|
||||
final tree = commit.tree;
|
||||
|
||||
final peeledCommit = ref.peel(GitObject.commit) as Commit;
|
||||
final peeledTree = ref.peel(GitObject.tree) as Tree;
|
||||
|
@ -559,20 +494,9 @@ void main() {
|
|||
final peeledTag = tagRef.peel(GitObject.tag) as Tag;
|
||||
|
||||
expect(peeledCommit.oid, commit.oid);
|
||||
expect(peeledTree.oid, tree.oid);
|
||||
expect(peeledTree.oid, commit.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();
|
||||
});
|
||||
|
||||
test('throws when trying to peel and error occurs', () {
|
||||
|
@ -598,10 +522,14 @@ void main() {
|
|||
);
|
||||
});
|
||||
|
||||
test('manually releases allocated memory', () {
|
||||
final ref = Reference.lookup(repo: repo, name: 'refs/heads/master');
|
||||
expect(() => ref.free(), returnsNormally);
|
||||
});
|
||||
|
||||
test('returns string representation of Reference object', () {
|
||||
final ref = Reference.lookup(repo: repo, name: 'refs/heads/master');
|
||||
expect(ref.toString(), contains('Reference{'));
|
||||
ref.free();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -10,19 +10,15 @@ import 'helpers/util.dart';
|
|||
void main() {
|
||||
late Repository repo;
|
||||
late RefLog reflog;
|
||||
late Reference head;
|
||||
late Directory tmpDir;
|
||||
|
||||
setUp(() {
|
||||
tmpDir = setupRepo(Directory(p.join('test', 'assets', 'test_repo')));
|
||||
repo = Repository.open(tmpDir.path);
|
||||
head = repo.head;
|
||||
reflog = RefLog(head);
|
||||
reflog = RefLog(repo.head);
|
||||
});
|
||||
|
||||
tearDown(() {
|
||||
reflog.free();
|
||||
head.free();
|
||||
repo.free();
|
||||
tmpDir.deleteSync(recursive: true);
|
||||
});
|
||||
|
@ -52,9 +48,9 @@ void main() {
|
|||
});
|
||||
|
||||
test('deletes the reflog of provided reference', () {
|
||||
expect(head.hasLog, true);
|
||||
RefLog.delete(head);
|
||||
expect(head.hasLog, false);
|
||||
expect(repo.head.hasLog, true);
|
||||
RefLog.delete(repo.head);
|
||||
expect(repo.head.hasLog, false);
|
||||
});
|
||||
|
||||
test('renames existing reflog', () {
|
||||
|
@ -94,19 +90,21 @@ void main() {
|
|||
);
|
||||
|
||||
expect(reflog.length, 4);
|
||||
reflog.add(oid: head.target, committer: committer);
|
||||
reflog.add(oid: repo.head.target, committer: committer);
|
||||
expect(reflog.length, 5);
|
||||
|
||||
reflog.add(oid: head.target, committer: committer, message: 'new entry');
|
||||
reflog.add(
|
||||
oid: repo.head.target,
|
||||
committer: committer,
|
||||
message: 'new entry',
|
||||
);
|
||||
expect(reflog.length, 6);
|
||||
expect(reflog[0].message, 'new entry');
|
||||
|
||||
committer.free();
|
||||
});
|
||||
|
||||
test('throws when trying to add new entry', () {
|
||||
expect(
|
||||
() => reflog.add(oid: head.target, committer: Signature(nullptr)),
|
||||
() => reflog.add(oid: repo.head.target, committer: Signature(nullptr)),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
});
|
||||
|
@ -132,12 +130,12 @@ void main() {
|
|||
reflog.remove(0);
|
||||
|
||||
// making sure change is only in memory
|
||||
final oldReflog = RefLog(head);
|
||||
final oldReflog = RefLog(repo.head);
|
||||
expect(oldReflog.length, 4);
|
||||
|
||||
reflog.write();
|
||||
|
||||
final newReflog = RefLog(head);
|
||||
final newReflog = RefLog(repo.head);
|
||||
expect(newReflog.length, 3);
|
||||
});
|
||||
|
||||
|
@ -147,9 +145,10 @@ void main() {
|
|||
Reference.delete(repo: repo, name: ref.name);
|
||||
|
||||
expect(() => reflog.write(), throwsA(isA<LibGit2Error>()));
|
||||
});
|
||||
|
||||
reflog.free();
|
||||
ref.free();
|
||||
test('manually releases allocated memory', () {
|
||||
expect(() => RefLog(repo.head).free(), returnsNormally);
|
||||
});
|
||||
|
||||
test('returns string representation of RefLogEntry object', () {
|
||||
|
|
|
@ -30,7 +30,6 @@ void main() {
|
|||
});
|
||||
|
||||
tearDown(() {
|
||||
remote.free();
|
||||
originRepo.free();
|
||||
clonedRepo.free();
|
||||
tmpDir.deleteSync(recursive: true);
|
||||
|
@ -41,35 +40,26 @@ void main() {
|
|||
group('Remote', () {
|
||||
test('fetch() does not prune branch by default', () {
|
||||
remote.fetch();
|
||||
|
||||
final branches = clonedRepo.branches;
|
||||
expect(branches.any((branch) => branch.name == 'origin/feature'), true);
|
||||
|
||||
for (final branch in branches) {
|
||||
branch.free();
|
||||
}
|
||||
expect(
|
||||
clonedRepo.branches.any((branch) => branch.name == 'origin/feature'),
|
||||
true,
|
||||
);
|
||||
});
|
||||
|
||||
test('fetch() prunes branch with provided flag', () {
|
||||
remote.fetch(prune: GitFetchPrune.prune);
|
||||
|
||||
final branches = clonedRepo.branches;
|
||||
expect(branches.any((branch) => branch.name == 'origin/feature'), false);
|
||||
|
||||
for (final branch in branches) {
|
||||
branch.free();
|
||||
}
|
||||
expect(
|
||||
clonedRepo.branches.any((branch) => branch.name == 'origin/feature'),
|
||||
false,
|
||||
);
|
||||
});
|
||||
|
||||
test('fetch() does not prune branch with provided flag', () {
|
||||
remote.fetch(prune: GitFetchPrune.noPrune);
|
||||
|
||||
final branches = clonedRepo.branches;
|
||||
expect(branches.any((branch) => branch.name == 'origin/feature'), true);
|
||||
|
||||
for (final branch in branches) {
|
||||
branch.free();
|
||||
}
|
||||
expect(
|
||||
clonedRepo.branches.any((branch) => branch.name == 'origin/feature'),
|
||||
true,
|
||||
);
|
||||
});
|
||||
|
||||
test('prune() prunes branches', () {
|
||||
|
@ -81,22 +71,18 @@ void main() {
|
|||
final callbacks = Callbacks(updateTips: updateTips);
|
||||
|
||||
remote.fetch(prune: GitFetchPrune.noPrune);
|
||||
var branches = clonedRepo.branches;
|
||||
expect(branches.any((branch) => branch.name == 'origin/feature'), true);
|
||||
|
||||
for (final branch in branches) {
|
||||
branch.free();
|
||||
}
|
||||
expect(
|
||||
clonedRepo.branches.any((branch) => branch.name == 'origin/feature'),
|
||||
true,
|
||||
);
|
||||
|
||||
remote.prune(callbacks);
|
||||
|
||||
branches = clonedRepo.branches;
|
||||
expect(pruned, contains('refs/remotes/origin/feature'));
|
||||
expect(branches.any((branch) => branch.name == 'origin/feature'), false);
|
||||
|
||||
for (final branch in branches) {
|
||||
branch.free();
|
||||
}
|
||||
expect(
|
||||
clonedRepo.branches.any((branch) => branch.name == 'origin/feature'),
|
||||
false,
|
||||
);
|
||||
});
|
||||
|
||||
test(
|
||||
|
|
|
@ -34,8 +34,6 @@ void main() {
|
|||
expect(remote.url, remoteUrl);
|
||||
expect(remote.pushUrl, '');
|
||||
expect(remote.toString(), contains('Remote{'));
|
||||
|
||||
remote.free();
|
||||
});
|
||||
|
||||
test('throws when provided name for lookup is not found', () {
|
||||
|
@ -56,8 +54,6 @@ void main() {
|
|||
expect(remote.name, 'upstream');
|
||||
expect(remote.url, remoteUrl);
|
||||
expect(remote.pushUrl, '');
|
||||
|
||||
remote.free();
|
||||
});
|
||||
|
||||
test('creates with provided fetchspec', () {
|
||||
|
@ -74,19 +70,12 @@ void main() {
|
|||
expect(remote.url, remoteUrl);
|
||||
expect(remote.pushUrl, '');
|
||||
expect(remote.fetchRefspecs, [spec]);
|
||||
|
||||
remote.free();
|
||||
});
|
||||
|
||||
test('throws when trying to create with fetchspec with invalid remote name',
|
||||
() {
|
||||
expect(
|
||||
() => Remote.create(
|
||||
repo: repo,
|
||||
name: '',
|
||||
url: '',
|
||||
fetch: '',
|
||||
),
|
||||
() => Remote.create(repo: repo, name: '', url: '', fetch: ''),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
});
|
||||
|
@ -101,8 +90,6 @@ void main() {
|
|||
|
||||
Remote.delete(repo: repo, name: remote.name);
|
||||
expect(repo.remotes.length, 1);
|
||||
|
||||
remote.free();
|
||||
});
|
||||
|
||||
test('throws when trying to delete non existing remote', () {
|
||||
|
@ -118,16 +105,13 @@ void main() {
|
|||
final problems = Remote.rename(
|
||||
repo: repo,
|
||||
oldName: remoteName,
|
||||
newName: 'new',
|
||||
newName: 'renamed',
|
||||
);
|
||||
expect(problems, isEmpty);
|
||||
expect(remote.name, isNot('new'));
|
||||
expect(remote.name, isNot('renamed'));
|
||||
|
||||
final newRemote = Remote.lookup(repo: repo, name: 'new');
|
||||
expect(newRemote.name, 'new');
|
||||
|
||||
newRemote.free();
|
||||
remote.free();
|
||||
final renamedRemote = Remote.lookup(repo: repo, name: 'renamed');
|
||||
expect(renamedRemote.name, 'renamed');
|
||||
});
|
||||
|
||||
test('returns list of non-default refspecs that cannot be renamed', () {
|
||||
|
@ -142,8 +126,6 @@ void main() {
|
|||
Remote.rename(repo: repo, oldName: remote.name, newName: 'renamed'),
|
||||
['+refs/*:refs/*'],
|
||||
);
|
||||
|
||||
remote.free();
|
||||
});
|
||||
|
||||
test('throws when renaming with invalid names', () {
|
||||
|
@ -154,17 +136,12 @@ void main() {
|
|||
});
|
||||
|
||||
test('sets url', () {
|
||||
final remote = Remote.lookup(repo: repo, name: remoteName);
|
||||
expect(remote.url, remoteUrl);
|
||||
expect(Remote.lookup(repo: repo, name: remoteName).url, remoteUrl);
|
||||
|
||||
const newUrl = 'git://new/url.git';
|
||||
Remote.setUrl(repo: repo, remote: remoteName, url: newUrl);
|
||||
|
||||
final newRemote = Remote.lookup(repo: repo, name: remoteName);
|
||||
expect(newRemote.url, newUrl);
|
||||
|
||||
newRemote.free();
|
||||
remote.free();
|
||||
expect(Remote.lookup(repo: repo, name: remoteName).url, newUrl);
|
||||
});
|
||||
|
||||
test('throws when trying to set invalid url name', () {
|
||||
|
@ -178,10 +155,7 @@ void main() {
|
|||
const newUrl = 'git://new/url.git';
|
||||
Remote.setPushUrl(repo: repo, remote: remoteName, url: newUrl);
|
||||
|
||||
final remote = Remote.lookup(repo: repo, name: remoteName);
|
||||
expect(remote.pushUrl, newUrl);
|
||||
|
||||
remote.free();
|
||||
expect(Remote.lookup(repo: repo, name: remoteName).pushUrl, newUrl);
|
||||
});
|
||||
|
||||
test('throws when trying to set invalid push url name', () {
|
||||
|
@ -215,14 +189,11 @@ void main() {
|
|||
refspec.rTransform('refs/remotes/origin/master'),
|
||||
'refs/heads/master',
|
||||
);
|
||||
|
||||
remote.free();
|
||||
});
|
||||
|
||||
test('throws when trying to transform refspec with invalid reference name',
|
||||
() {
|
||||
final remote = Remote.lookup(repo: repo, name: 'origin');
|
||||
final refspec = remote.getRefspec(0);
|
||||
final refspec = Remote.lookup(repo: repo, name: 'origin').getRefspec(0);
|
||||
|
||||
expect(
|
||||
() => refspec.transform('invalid/name'),
|
||||
|
@ -233,8 +204,6 @@ void main() {
|
|||
() => refspec.rTransform('invalid/name'),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
|
||||
remote.free();
|
||||
});
|
||||
|
||||
test('adds fetch refspec', () {
|
||||
|
@ -252,8 +221,6 @@ void main() {
|
|||
'+refs/test/*:refs/test/remotes/*',
|
||||
],
|
||||
);
|
||||
|
||||
remote.free();
|
||||
});
|
||||
|
||||
test('throws when trying to add fetch refspec for invalid remote name', () {
|
||||
|
@ -276,8 +243,6 @@ void main() {
|
|||
final remote = Remote.lookup(repo: repo, name: 'origin');
|
||||
expect(remote.pushRefspecs.length, 1);
|
||||
expect(remote.pushRefspecs, ['+refs/test/*:refs/test/remotes/*']);
|
||||
|
||||
remote.free();
|
||||
});
|
||||
|
||||
test('throws when trying to add push refspec for invalid remote name', () {
|
||||
|
@ -308,8 +273,6 @@ void main() {
|
|||
(refs.first['oid']! as Oid).sha,
|
||||
'49322bb17d3acc9146f98c97d078513228bbf3c0',
|
||||
);
|
||||
|
||||
remote.free();
|
||||
});
|
||||
|
||||
test(
|
||||
|
@ -319,8 +282,6 @@ void main() {
|
|||
final remote = Remote.lookup(repo: repo, name: 'libgit2');
|
||||
|
||||
expect(() => remote.ls(), throwsA(isA<LibGit2Error>()));
|
||||
|
||||
remote.free();
|
||||
});
|
||||
|
||||
test(
|
||||
|
@ -350,8 +311,6 @@ void main() {
|
|||
expect(stats.indexedDeltas, 3);
|
||||
expect(stats.receivedBytes, 0);
|
||||
expect(stats.toString(), contains('TransferProgress{'));
|
||||
|
||||
remote.free();
|
||||
},
|
||||
tags: 'remote_fetch',
|
||||
);
|
||||
|
@ -384,8 +343,6 @@ void main() {
|
|||
expect(stats.indexedDeltas, 3);
|
||||
expect(stats.receivedBytes, 0);
|
||||
expect(stats.toString(), contains('TransferProgress{'));
|
||||
|
||||
remote.free();
|
||||
},
|
||||
tags: 'remote_fetch',
|
||||
);
|
||||
|
@ -412,8 +369,6 @@ void main() {
|
|||
),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
|
||||
remote.free();
|
||||
},
|
||||
tags: 'remote_fetch',
|
||||
);
|
||||
|
@ -426,8 +381,6 @@ void main() {
|
|||
() => remote.fetch(),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
|
||||
remote.free();
|
||||
});
|
||||
|
||||
test(
|
||||
|
@ -442,9 +395,8 @@ void main() {
|
|||
|
||||
TransferProgress? callbackStats;
|
||||
void tp(TransferProgress stats) => callbackStats = stats;
|
||||
final callbacks = Callbacks(transferProgress: tp);
|
||||
|
||||
final stats = remote.fetch(callbacks: callbacks);
|
||||
final stats = remote.fetch(callbacks: Callbacks(transferProgress: tp));
|
||||
|
||||
expect(stats.totalObjects == callbackStats?.totalObjects, true);
|
||||
expect(stats.indexedObjects == callbackStats?.indexedObjects, true);
|
||||
|
@ -453,8 +405,6 @@ void main() {
|
|||
expect(stats.totalDeltas == callbackStats?.totalDeltas, true);
|
||||
expect(stats.indexedDeltas == callbackStats?.indexedDeltas, true);
|
||||
expect(stats.receivedBytes == callbackStats?.receivedBytes, true);
|
||||
|
||||
remote.free();
|
||||
},
|
||||
tags: 'remote_fetch',
|
||||
);
|
||||
|
@ -475,16 +425,10 @@ Total 69 (delta 0), reused 1 (delta 0), pack-reused 68
|
|||
final remote = Remote.lookup(repo: repo, name: 'libgit2');
|
||||
|
||||
final sidebandOutput = StringBuffer();
|
||||
void sideband(String message) {
|
||||
sidebandOutput.write(message);
|
||||
}
|
||||
void sideband(String message) => sidebandOutput.write(message);
|
||||
|
||||
final callbacks = Callbacks(sidebandProgress: sideband);
|
||||
|
||||
remote.fetch(callbacks: callbacks);
|
||||
remote.fetch(callbacks: Callbacks(sidebandProgress: sideband));
|
||||
expect(sidebandOutput.toString(), sidebandMessage);
|
||||
|
||||
remote.free();
|
||||
},
|
||||
tags: 'remote_fetch',
|
||||
);
|
||||
|
@ -525,12 +469,8 @@ Total 69 (delta 0), reused 1 (delta 0), pack-reused 68
|
|||
});
|
||||
}
|
||||
|
||||
final callbacks = Callbacks(updateTips: updateTips);
|
||||
|
||||
remote.fetch(callbacks: callbacks);
|
||||
remote.fetch(callbacks: Callbacks(updateTips: updateTips));
|
||||
expect(updateTipsOutput, tipsExpected);
|
||||
|
||||
remote.free();
|
||||
},
|
||||
tags: 'remote_fetch',
|
||||
);
|
||||
|
@ -557,16 +497,16 @@ Total 69 (delta 0), reused 1 (delta 0), pack-reused 68
|
|||
updateRefOutput[refname] = message;
|
||||
}
|
||||
|
||||
final callbacks = Callbacks(pushUpdateReference: updateRef);
|
||||
|
||||
remote.push(refspecs: ['refs/heads/master'], callbacks: callbacks);
|
||||
remote.push(
|
||||
refspecs: ['refs/heads/master'],
|
||||
callbacks: Callbacks(pushUpdateReference: updateRef),
|
||||
);
|
||||
expect(
|
||||
Commit.lookup(repo: originRepo, oid: originRepo.head.target).oid.sha,
|
||||
'821ed6e80627b8769d170a293862f9fc60825226',
|
||||
);
|
||||
expect(updateRefOutput, {'refs/heads/master': ''});
|
||||
|
||||
remote.free();
|
||||
originRepo.free();
|
||||
originDir.delete(recursive: true);
|
||||
});
|
||||
|
@ -579,8 +519,26 @@ Total 69 (delta 0), reused 1 (delta 0), pack-reused 68
|
|||
() => remote.push(refspecs: ['refs/heads/master']),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
});
|
||||
|
||||
remote.free();
|
||||
test('manually releases allocated memory', () {
|
||||
final remote = Remote.lookup(repo: repo, name: 'origin');
|
||||
expect(() => remote.free(), returnsNormally);
|
||||
});
|
||||
});
|
||||
|
||||
group('RemoteCallback', () {
|
||||
test('initializes and returns values', () {
|
||||
const remoteCallback = RemoteCallback(
|
||||
name: 'name',
|
||||
url: 'url',
|
||||
fetch: 'fetchRefspec',
|
||||
);
|
||||
|
||||
expect(remoteCallback, isA<RemoteCallback>());
|
||||
expect(remoteCallback.name, 'name');
|
||||
expect(remoteCallback.url, 'url');
|
||||
expect(remoteCallback.fetch, 'fetchRefspec');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -9,7 +9,6 @@ import 'package:test/test.dart';
|
|||
import 'helpers/util.dart';
|
||||
|
||||
void main() {
|
||||
late Repository repo;
|
||||
late Directory tmpDir;
|
||||
final cloneDir = Directory(
|
||||
p.join(Directory.systemTemp.path, 'repository_cloned'),
|
||||
|
@ -17,14 +16,12 @@ void main() {
|
|||
|
||||
setUp(() {
|
||||
tmpDir = setupRepo(Directory(p.join('test', 'assets', 'test_repo')));
|
||||
repo = Repository.open(tmpDir.path);
|
||||
if (cloneDir.existsSync()) {
|
||||
cloneDir.delete(recursive: true);
|
||||
}
|
||||
});
|
||||
|
||||
tearDown(() {
|
||||
repo.free();
|
||||
tmpDir.deleteSync(recursive: true);
|
||||
if (cloneDir.existsSync()) {
|
||||
cloneDir.deleteSync(recursive: true);
|
||||
|
@ -72,14 +69,13 @@ void main() {
|
|||
clonedRepo.free();
|
||||
});
|
||||
|
||||
test('clones repository with provided remote callback', () {
|
||||
Remote remote(Repository repo, String name, String url) =>
|
||||
Remote.create(repo: repo, name: 'test', url: tmpDir.path);
|
||||
|
||||
test(
|
||||
'clones repository with provided remote callback having default fetch '
|
||||
'refspec value', () {
|
||||
final clonedRepo = Repository.clone(
|
||||
url: tmpDir.path,
|
||||
localPath: cloneDir.path,
|
||||
remote: remote,
|
||||
remoteCallback: RemoteCallback(name: 'test', url: tmpDir.path),
|
||||
);
|
||||
|
||||
expect(clonedRepo.isEmpty, false);
|
||||
|
@ -90,15 +86,35 @@ void main() {
|
|||
clonedRepo.free();
|
||||
});
|
||||
|
||||
test('throws when cloning repository with invalid remote callback', () {
|
||||
Remote remote(Repository repo, String name, String url) =>
|
||||
Remote.create(repo: repo, name: '', url: '');
|
||||
test('clones repository with provided remote callback ', () {
|
||||
const fetchRefspec = '+refs/heads/*:refs/remotes/spec/*';
|
||||
final clonedRepo = Repository.clone(
|
||||
url: tmpDir.path,
|
||||
localPath: cloneDir.path,
|
||||
remoteCallback: RemoteCallback(
|
||||
name: 'test',
|
||||
url: tmpDir.path,
|
||||
fetch: fetchRefspec,
|
||||
),
|
||||
);
|
||||
|
||||
final remote = Remote.lookup(repo: clonedRepo, name: 'test');
|
||||
|
||||
expect(clonedRepo.isEmpty, false);
|
||||
expect(clonedRepo.isBare, false);
|
||||
expect(clonedRepo.remotes, ['test']);
|
||||
expect(clonedRepo.references, contains('refs/remotes/spec/master'));
|
||||
expect(remote.fetchRefspecs, [fetchRefspec]);
|
||||
|
||||
clonedRepo.free();
|
||||
});
|
||||
|
||||
test('throws when cloning repository with invalid remote callback', () {
|
||||
expect(
|
||||
() => Repository.clone(
|
||||
url: tmpDir.path,
|
||||
localPath: cloneDir.path,
|
||||
remote: remote,
|
||||
remoteCallback: const RemoteCallback(name: '', url: ''),
|
||||
),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
|
@ -113,13 +129,10 @@ void main() {
|
|||
}
|
||||
callbackPath.createSync();
|
||||
|
||||
Repository repository(String path, bool bare) =>
|
||||
Repository.init(path: callbackPath.path);
|
||||
|
||||
final clonedRepo = Repository.clone(
|
||||
url: tmpDir.path,
|
||||
localPath: cloneDir.path,
|
||||
repository: repository,
|
||||
repositoryCallback: RepositoryCallback(path: callbackPath.path),
|
||||
);
|
||||
|
||||
expect(clonedRepo.isEmpty, false);
|
||||
|
@ -131,17 +144,41 @@ void main() {
|
|||
});
|
||||
|
||||
test('throws when cloning repository with invalid repository callback', () {
|
||||
Repository repository(String path, bool bare) =>
|
||||
Repository.init(path: '');
|
||||
|
||||
expect(
|
||||
() => Repository.clone(
|
||||
url: tmpDir.path,
|
||||
localPath: cloneDir.path,
|
||||
repository: repository,
|
||||
repositoryCallback: const RepositoryCallback(path: ''),
|
||||
),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
group('RepositoryCallback', () {
|
||||
test('initializes and returns values', () {
|
||||
const repositoryCallback = RepositoryCallback(
|
||||
path: 'some/path',
|
||||
bare: true,
|
||||
flags: {GitRepositoryInit.noReinit},
|
||||
mode: 1,
|
||||
workdirPath: 'some/path',
|
||||
description: 'description',
|
||||
templatePath: 'some/path',
|
||||
initialHead: 'feature',
|
||||
originUrl: 'some.url',
|
||||
);
|
||||
|
||||
expect(repositoryCallback, isA<RepositoryCallback>());
|
||||
expect(repositoryCallback.path, 'some/path');
|
||||
expect(repositoryCallback.bare, true);
|
||||
expect(repositoryCallback.flags, {GitRepositoryInit.noReinit});
|
||||
expect(repositoryCallback.mode, 1);
|
||||
expect(repositoryCallback.workdirPath, 'some/path');
|
||||
expect(repositoryCallback.description, 'description');
|
||||
expect(repositoryCallback.templatePath, 'some/path');
|
||||
expect(repositoryCallback.initialHead, 'feature');
|
||||
expect(repositoryCallback.originUrl, 'some.url');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@ import 'package:path/path.dart' as p;
|
|||
import 'package:test/test.dart';
|
||||
|
||||
void main() {
|
||||
late Repository repo;
|
||||
final initDir = Directory(p.join(Directory.systemTemp.path, 'init_repo'));
|
||||
|
||||
setUp(() {
|
||||
|
@ -17,27 +16,30 @@ void main() {
|
|||
});
|
||||
|
||||
tearDown(() {
|
||||
repo.free();
|
||||
initDir.deleteSync(recursive: true);
|
||||
});
|
||||
group('Repository.init', () {
|
||||
test('creates new bare repo at provided path', () {
|
||||
repo = Repository.init(path: initDir.path, bare: true);
|
||||
final repo = Repository.init(path: initDir.path, bare: true);
|
||||
|
||||
expect(repo.path, contains('init_repo'));
|
||||
expect(repo.isBare, true);
|
||||
|
||||
repo.free();
|
||||
});
|
||||
|
||||
test('creates new standard repo at provided path', () {
|
||||
repo = Repository.init(path: initDir.path);
|
||||
final repo = Repository.init(path: initDir.path);
|
||||
|
||||
expect(repo.path, contains('init_repo/.git/'));
|
||||
expect(repo.isBare, false);
|
||||
expect(repo.isEmpty, true);
|
||||
|
||||
repo.free();
|
||||
});
|
||||
|
||||
test('creates new standard repo with provided options', () {
|
||||
repo = Repository.init(
|
||||
final repo = Repository.init(
|
||||
path: initDir.path,
|
||||
description: 'test repo',
|
||||
originUrl: 'test.url',
|
||||
|
@ -52,6 +54,8 @@ void main() {
|
|||
'test repo',
|
||||
);
|
||||
expect(Remote.lookup(repo: repo, name: 'origin').url, 'test.url');
|
||||
|
||||
repo.free();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -25,22 +25,17 @@ void main() {
|
|||
|
||||
group('Repository', () {
|
||||
test('returns config for repository', () {
|
||||
final config = repo.config;
|
||||
expect(
|
||||
config['remote.origin.url'].value,
|
||||
repo.config['remote.origin.url'].value,
|
||||
'git://github.com/SkinnyMind/libgit2dart.git',
|
||||
);
|
||||
|
||||
config.free();
|
||||
});
|
||||
|
||||
test('returns snapshot of repository config', () {
|
||||
final snapshot = repo.configSnapshot;
|
||||
expect(
|
||||
snapshot['remote.origin.url'].value,
|
||||
repo.configSnapshot['remote.origin.url'].value,
|
||||
'git://github.com/SkinnyMind/libgit2dart.git',
|
||||
);
|
||||
snapshot.free();
|
||||
});
|
||||
|
||||
test('returns list of commits by walking from provided starting oid', () {
|
||||
|
@ -57,10 +52,6 @@ void main() {
|
|||
for (var i = 0; i < commits.length; i++) {
|
||||
expect(commits[i].oid.sha, log[i]);
|
||||
}
|
||||
|
||||
for (final c in commits) {
|
||||
c.free();
|
||||
}
|
||||
});
|
||||
|
||||
group('.discover()', () {
|
||||
|
@ -119,11 +110,6 @@ void main() {
|
|||
});
|
||||
|
||||
group('setHead', () {
|
||||
late Reference head;
|
||||
|
||||
setUp(() => head = repo.head);
|
||||
tearDown(() => head.free());
|
||||
|
||||
test('sets head when target is reference', () {
|
||||
expect(repo.head.name, 'refs/heads/master');
|
||||
expect(repo.head.target.sha, lastCommit);
|
||||
|
@ -164,9 +150,8 @@ void main() {
|
|||
|
||||
test('returns status of a repository', () {
|
||||
File(p.join(tmpDir.path, 'new_file.txt')).createSync();
|
||||
final index = repo.index;
|
||||
index.remove('file');
|
||||
index.add('new_file.txt');
|
||||
repo.index.remove('file');
|
||||
repo.index.add('new_file.txt');
|
||||
expect(
|
||||
repo.status,
|
||||
{
|
||||
|
@ -174,8 +159,6 @@ void main() {
|
|||
'new_file.txt': {GitStatus.indexNew}
|
||||
},
|
||||
);
|
||||
|
||||
index.free();
|
||||
});
|
||||
|
||||
test('throws when trying to get status of bare repository', () {
|
||||
|
@ -188,14 +171,14 @@ void main() {
|
|||
|
||||
test('cleans up state', () {
|
||||
expect(repo.state, GitRepositoryState.none);
|
||||
final commit = Commit.lookup(repo: repo, oid: repo['5aecfa0']);
|
||||
Merge.cherryPick(repo: repo, commit: commit);
|
||||
Merge.cherryPick(
|
||||
repo: repo,
|
||||
commit: Commit.lookup(repo: repo, oid: repo['5aecfa0']),
|
||||
);
|
||||
|
||||
expect(repo.state, GitRepositoryState.cherrypick);
|
||||
repo.stateCleanup();
|
||||
expect(repo.state, GitRepositoryState.none);
|
||||
|
||||
commit.free();
|
||||
});
|
||||
|
||||
test('throws when trying to clean up state and error occurs', () {
|
||||
|
@ -206,15 +189,12 @@ void main() {
|
|||
});
|
||||
|
||||
test('returns status of a single file for provided path', () {
|
||||
final index = repo.index;
|
||||
index.remove('file');
|
||||
repo.index.remove('file');
|
||||
expect(
|
||||
repo.statusFile('file'),
|
||||
{GitStatus.indexDeleted, GitStatus.wtNew},
|
||||
);
|
||||
expect(repo.statusFile('.gitignore'), {GitStatus.current});
|
||||
|
||||
index.free();
|
||||
});
|
||||
|
||||
test('throws when checking status of a single file for invalid path', () {
|
||||
|
@ -229,9 +209,6 @@ void main() {
|
|||
final signature = repo.defaultSignature;
|
||||
expect(signature.name, 'Some Name');
|
||||
expect(signature.email, 'some@email.com');
|
||||
|
||||
signature.free();
|
||||
config.free();
|
||||
});
|
||||
|
||||
test('returns attribute value', () {
|
||||
|
@ -265,9 +242,11 @@ void main() {
|
|||
repo.aheadBehind(local: commit1.oid, upstream: commit1.oid),
|
||||
[0, 0],
|
||||
);
|
||||
});
|
||||
|
||||
commit1.free();
|
||||
commit2.free();
|
||||
test('manually releases allocated memory', () {
|
||||
final repo = Repository.open(tmpDir.path);
|
||||
expect(() => repo.free(), returnsNormally);
|
||||
});
|
||||
|
||||
test('returns string representation of Repository object', () {
|
||||
|
|
|
@ -25,68 +25,48 @@ void main() {
|
|||
|
||||
group('Reset', () {
|
||||
test('resets with hard', () {
|
||||
var contents = file.readAsStringSync();
|
||||
expect(contents, 'Feature edit\n');
|
||||
expect(file.readAsStringSync(), 'Feature edit\n');
|
||||
|
||||
repo.reset(oid: repo[sha], resetType: GitReset.hard);
|
||||
contents = file.readAsStringSync();
|
||||
expect(contents, isEmpty);
|
||||
expect(file.readAsStringSync(), isEmpty);
|
||||
});
|
||||
|
||||
test('resets with soft', () {
|
||||
var contents = file.readAsStringSync();
|
||||
expect(contents, 'Feature edit\n');
|
||||
expect(file.readAsStringSync(), 'Feature edit\n');
|
||||
|
||||
repo.reset(oid: repo[sha], resetType: GitReset.soft);
|
||||
contents = file.readAsStringSync();
|
||||
expect(contents, 'Feature edit\n');
|
||||
expect(file.readAsStringSync(), 'Feature edit\n');
|
||||
|
||||
final index = repo.index;
|
||||
final diff = Diff.indexToWorkdir(repo: repo, index: index);
|
||||
final diff = Diff.indexToWorkdir(repo: repo, index: repo.index);
|
||||
expect(diff.deltas, isEmpty);
|
||||
|
||||
index.free();
|
||||
});
|
||||
|
||||
test('resets with mixed', () {
|
||||
var contents = file.readAsStringSync();
|
||||
expect(contents, 'Feature edit\n');
|
||||
expect(file.readAsStringSync(), 'Feature edit\n');
|
||||
|
||||
repo.reset(oid: repo[sha], resetType: GitReset.mixed);
|
||||
contents = file.readAsStringSync();
|
||||
expect(contents, 'Feature edit\n');
|
||||
expect(file.readAsStringSync(), 'Feature edit\n');
|
||||
|
||||
final index = repo.index;
|
||||
final diff = Diff.indexToWorkdir(repo: repo, index: index);
|
||||
final diff = Diff.indexToWorkdir(repo: repo, index: repo.index);
|
||||
expect(diff.deltas.length, 1);
|
||||
|
||||
index.free();
|
||||
});
|
||||
|
||||
group('resetDefault', () {
|
||||
test('updates entry in the index', () {
|
||||
file.writeAsStringSync('new edit');
|
||||
|
||||
final index = repo.index;
|
||||
index.add('feature_file');
|
||||
repo.index.add('feature_file');
|
||||
expect(repo.status['feature_file'], {GitStatus.indexModified});
|
||||
|
||||
final head = repo.head;
|
||||
repo.resetDefault(oid: head.target, pathspec: ['feature_file']);
|
||||
repo.resetDefault(oid: repo.head.target, pathspec: ['feature_file']);
|
||||
expect(repo.status['feature_file'], {GitStatus.wtModified});
|
||||
|
||||
head.free();
|
||||
index.free();
|
||||
});
|
||||
|
||||
test('throws when pathspec list is empty', () {
|
||||
final head = repo.head;
|
||||
expect(
|
||||
() => repo.resetDefault(oid: head.target, pathspec: []),
|
||||
() => repo.resetDefault(oid: repo.head.target, pathspec: []),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
|
||||
head.free();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -42,11 +42,6 @@ void main() {
|
|||
final tag = RevParse.single(repo: repo, spec: 'v0.2') as Tag;
|
||||
expect(tag, isA<Tag>());
|
||||
expect(tag.message, 'annotated tag\n');
|
||||
|
||||
commit.free();
|
||||
tree.free();
|
||||
blob.free();
|
||||
tag.free();
|
||||
});
|
||||
|
||||
test('.single() throws when spec string not found or invalid', () {
|
||||
|
@ -68,10 +63,6 @@ void main() {
|
|||
expect(headParse.reference?.equals(masterRef), true);
|
||||
expect(headParse.toString(), contains('RevParse{'));
|
||||
|
||||
masterRef.free();
|
||||
headParse.object.free();
|
||||
headParse.reference?.free();
|
||||
|
||||
final featureRef = Reference.lookup(
|
||||
repo: repo,
|
||||
name: 'refs/heads/feature',
|
||||
|
@ -83,10 +74,6 @@ void main() {
|
|||
'5aecfa0fb97eadaac050ccb99f03c3fb65460ad4',
|
||||
);
|
||||
expect(headParse.reference?.equals(featureRef), true);
|
||||
|
||||
featureRef.free();
|
||||
headParse.object.free();
|
||||
headParse.reference?.free();
|
||||
});
|
||||
|
||||
test('.ext() returns only commit when no intermidiate reference found', () {
|
||||
|
@ -94,8 +81,6 @@ void main() {
|
|||
|
||||
expect(headParse.object.oid.sha, parentSHA);
|
||||
expect(headParse.reference, isNull);
|
||||
|
||||
headParse.object.free();
|
||||
});
|
||||
|
||||
test('.ext() throws when spec string not found or invalid', () {
|
||||
|
@ -119,17 +104,12 @@ void main() {
|
|||
expect(revspec.flags, {GitRevSpec.single});
|
||||
expect(revspec.toString(), contains('RevSpec{'));
|
||||
|
||||
revspec.from.free();
|
||||
|
||||
revspec = RevParse.range(repo: repo, spec: 'HEAD^1..5aecfa');
|
||||
|
||||
expect(revspec.from.oid.sha, parentSHA);
|
||||
expect(revspec.to?.oid.sha, '5aecfa0fb97eadaac050ccb99f03c3fb65460ad4');
|
||||
expect(revspec.flags, {GitRevSpec.range});
|
||||
|
||||
revspec.from.free();
|
||||
revspec.to?.free();
|
||||
|
||||
revspec = RevParse.range(repo: repo, spec: 'HEAD...feature');
|
||||
|
||||
expect(revspec.from.oid.sha, headSHA);
|
||||
|
@ -139,9 +119,6 @@ void main() {
|
|||
Merge.base(repo: repo, commits: [revspec.from.oid, revspec.to!.oid]),
|
||||
isA<Oid>(),
|
||||
);
|
||||
|
||||
revspec.from.free();
|
||||
revspec.to?.free();
|
||||
});
|
||||
|
||||
test('throws on invalid range spec', () {
|
||||
|
|
|
@ -30,9 +30,7 @@ void main() {
|
|||
|
||||
group('RevWalk', () {
|
||||
test('initializes walker', () {
|
||||
final walker = RevWalk(repo);
|
||||
expect(walker, isA<RevWalk>());
|
||||
walker.free();
|
||||
expect(RevWalk(repo), isA<RevWalk>());
|
||||
});
|
||||
|
||||
test('throws when trying to initialize and error occurs', () {
|
||||
|
@ -44,55 +42,42 @@ void main() {
|
|||
|
||||
test('returns list of commits with default sorting', () {
|
||||
final walker = RevWalk(repo);
|
||||
final start = Oid.fromSHA(repo: repo, sha: log.first);
|
||||
|
||||
walker.push(start);
|
||||
walker.push(repo[log.first]);
|
||||
final commits = walker.walk();
|
||||
|
||||
for (var i = 0; i < commits.length; i++) {
|
||||
expect(commits[i].oid.sha, log[i]);
|
||||
commits[i].free();
|
||||
}
|
||||
|
||||
walker.free();
|
||||
});
|
||||
|
||||
test('returns list of commits with reverse sorting', () {
|
||||
final walker = RevWalk(repo);
|
||||
final start = Oid.fromSHA(repo: repo, sha: log.first);
|
||||
|
||||
walker.push(start);
|
||||
walker.push(repo[log.first]);
|
||||
walker.sorting({GitSort.reverse});
|
||||
final commits = walker.walk();
|
||||
|
||||
for (var i = 0; i < commits.length; i++) {
|
||||
expect(commits[i].oid.sha, log.reversed.toList()[i]);
|
||||
commits[i].free();
|
||||
}
|
||||
|
||||
walker.free();
|
||||
});
|
||||
|
||||
test('changes sorting', () {
|
||||
final walker = RevWalk(repo);
|
||||
final start = Oid.fromSHA(repo: repo, sha: log.first);
|
||||
|
||||
walker.push(start);
|
||||
walker.push(repo[log.first]);
|
||||
final timeSortedCommits = walker.walk();
|
||||
|
||||
for (var i = 0; i < timeSortedCommits.length; i++) {
|
||||
expect(timeSortedCommits[i].oid.sha, log[i]);
|
||||
timeSortedCommits[i].free();
|
||||
}
|
||||
|
||||
walker.sorting({GitSort.time, GitSort.reverse});
|
||||
final reverseSortedCommits = walker.walk();
|
||||
for (var i = 0; i < reverseSortedCommits.length; i++) {
|
||||
expect(reverseSortedCommits[i].oid.sha, log.reversed.toList()[i]);
|
||||
reverseSortedCommits[i].free();
|
||||
}
|
||||
|
||||
walker.free();
|
||||
});
|
||||
|
||||
test('adds matching references for traversal with provided glob', () {
|
||||
|
@ -101,11 +86,6 @@ void main() {
|
|||
walker.pushGlob('heads');
|
||||
final commits = walker.walk();
|
||||
expect(commits.length, 7);
|
||||
|
||||
for (final c in commits) {
|
||||
c.free();
|
||||
}
|
||||
walker.free();
|
||||
});
|
||||
|
||||
test("adds repository's head for traversal", () {
|
||||
|
@ -114,11 +94,6 @@ void main() {
|
|||
walker.pushHead();
|
||||
final commits = walker.walk();
|
||||
expect(commits.length, 6);
|
||||
|
||||
for (final c in commits) {
|
||||
c.free();
|
||||
}
|
||||
walker.free();
|
||||
});
|
||||
|
||||
test('adds reference for traversal with provided name', () {
|
||||
|
@ -127,23 +102,14 @@ void main() {
|
|||
walker.pushReference('refs/heads/master');
|
||||
final commits = walker.walk();
|
||||
expect(commits.length, 6);
|
||||
|
||||
for (final c in commits) {
|
||||
c.free();
|
||||
}
|
||||
walker.free();
|
||||
});
|
||||
|
||||
test('throws when trying to add reference for traversal with invalid name',
|
||||
() {
|
||||
final walker = RevWalk(repo);
|
||||
|
||||
expect(
|
||||
() => walker.pushReference('invalid'),
|
||||
() => RevWalk(repo).pushReference('invalid'),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
|
||||
walker.free();
|
||||
});
|
||||
|
||||
test('adds range for traversal', () {
|
||||
|
@ -152,22 +118,13 @@ void main() {
|
|||
walker.pushRange('HEAD..@{-1}');
|
||||
final commits = walker.walk();
|
||||
expect(commits.length, 1);
|
||||
|
||||
for (final c in commits) {
|
||||
c.free();
|
||||
}
|
||||
walker.free();
|
||||
});
|
||||
|
||||
test('throws when trying to add invalid range for traversal', () {
|
||||
final walker = RevWalk(repo);
|
||||
|
||||
expect(
|
||||
() => walker.pushRange('HEAD..invalid'),
|
||||
() => RevWalk(repo).pushRange('HEAD..invalid'),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
|
||||
walker.free();
|
||||
});
|
||||
|
||||
test('hides commit and its ancestors', () {
|
||||
|
@ -178,22 +135,13 @@ void main() {
|
|||
final commits = walker.walk();
|
||||
|
||||
expect(commits.length, 2);
|
||||
|
||||
for (final c in commits) {
|
||||
c.free();
|
||||
}
|
||||
walker.free();
|
||||
});
|
||||
|
||||
test('throws when trying to hide commit oid and error occurs', () {
|
||||
final walker = RevWalk(repo);
|
||||
|
||||
expect(
|
||||
() => walker.hide(repo['0' * 40]),
|
||||
() => RevWalk(repo).hide(repo['0' * 40]),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
|
||||
walker.free();
|
||||
});
|
||||
|
||||
test('hides oids of references for provided glob pattern', () {
|
||||
|
@ -207,105 +155,72 @@ void main() {
|
|||
walker.hideGlob('*master');
|
||||
final hiddenCommits = walker.walk();
|
||||
expect(hiddenCommits.length, 1);
|
||||
|
||||
hiddenCommits[0].free();
|
||||
for (final c in commits) {
|
||||
c.free();
|
||||
}
|
||||
walker.free();
|
||||
});
|
||||
|
||||
test('hides head', () {
|
||||
final head = repo.head;
|
||||
final walker = RevWalk(repo);
|
||||
|
||||
walker.push(head.target);
|
||||
walker.push(repo.head.target);
|
||||
final commits = walker.walk();
|
||||
expect(commits.length, 6);
|
||||
|
||||
walker.push(head.target);
|
||||
walker.push(repo.head.target);
|
||||
walker.hideHead();
|
||||
final hiddenCommits = walker.walk();
|
||||
expect(hiddenCommits.length, 0);
|
||||
|
||||
for (final c in commits) {
|
||||
c.free();
|
||||
}
|
||||
head.free();
|
||||
walker.free();
|
||||
});
|
||||
|
||||
test('hides oids of reference with provided name', () {
|
||||
final head = repo.head;
|
||||
final walker = RevWalk(repo);
|
||||
|
||||
walker.push(head.target);
|
||||
walker.push(repo.head.target);
|
||||
final commits = walker.walk();
|
||||
expect(commits.length, 6);
|
||||
|
||||
walker.push(head.target);
|
||||
walker.push(repo.head.target);
|
||||
walker.hideReference('refs/heads/master');
|
||||
final hiddenCommits = walker.walk();
|
||||
expect(hiddenCommits.length, 0);
|
||||
|
||||
for (final c in commits) {
|
||||
c.free();
|
||||
}
|
||||
head.free();
|
||||
walker.free();
|
||||
});
|
||||
|
||||
test('throws when trying to hide oids of reference with invalid name', () {
|
||||
final walker = RevWalk(repo);
|
||||
|
||||
expect(
|
||||
() => walker.hideReference('invalid'),
|
||||
() => RevWalk(repo).hideReference('invalid'),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
|
||||
walker.free();
|
||||
});
|
||||
|
||||
test('resets walker', () {
|
||||
final walker = RevWalk(repo);
|
||||
final start = Oid.fromSHA(repo: repo, sha: log.first);
|
||||
|
||||
walker.push(start);
|
||||
walker.push(repo[log.first]);
|
||||
walker.reset();
|
||||
final commits = walker.walk();
|
||||
|
||||
expect(commits, <Commit>[]);
|
||||
|
||||
walker.free();
|
||||
});
|
||||
|
||||
test('simplifies walker by enqueuing only first parent for each commit',
|
||||
() {
|
||||
final walker = RevWalk(repo);
|
||||
final start = Oid.fromSHA(repo: repo, sha: log.first);
|
||||
|
||||
walker.push(start);
|
||||
walker.push(repo[log.first]);
|
||||
walker.simplifyFirstParent();
|
||||
final commits = walker.walk();
|
||||
|
||||
for (var i = 0; i < commits.length; i++) {
|
||||
expect(commits.length, 3);
|
||||
commits[i].free();
|
||||
}
|
||||
|
||||
walker.free();
|
||||
expect(commits.length, 3);
|
||||
});
|
||||
|
||||
test('throws when trying to add new root for traversal and error occurs',
|
||||
() {
|
||||
final walker = RevWalk(repo);
|
||||
|
||||
expect(
|
||||
() => walker.push(repo['0' * 40]),
|
||||
() => RevWalk(repo).push(repo['0' * 40]),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
});
|
||||
|
||||
walker.free();
|
||||
test('manually releases allocated memory', () {
|
||||
expect(() => RevWalk(repo).free(), returnsNormally);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -16,9 +16,6 @@ void main() {
|
|||
);
|
||||
});
|
||||
|
||||
tearDown(() {
|
||||
signature.free();
|
||||
});
|
||||
group('Signature', () {
|
||||
test('creates with provided time and offset', () {
|
||||
expect(signature, isA<Signature>());
|
||||
|
@ -50,7 +47,6 @@ void main() {
|
|||
lessThan(5),
|
||||
);
|
||||
expect(sig.offset, isA<int>());
|
||||
sig.free();
|
||||
});
|
||||
|
||||
test('returns correct values', () {
|
||||
|
@ -66,9 +62,16 @@ void main() {
|
|||
email: email,
|
||||
time: time,
|
||||
);
|
||||
expect(signature == otherSignature, true);
|
||||
expect(signature, equals(otherSignature));
|
||||
});
|
||||
|
||||
otherSignature.free();
|
||||
test('manually releases allocated memory', () {
|
||||
final signature = Signature.create(
|
||||
name: name,
|
||||
email: email,
|
||||
time: time,
|
||||
);
|
||||
expect(() => signature.free(), returnsNormally);
|
||||
});
|
||||
|
||||
test('returns string representation of Signature object', () {
|
||||
|
|
|
@ -24,7 +24,6 @@ void main() {
|
|||
});
|
||||
|
||||
tearDown(() {
|
||||
stasher.free();
|
||||
repo.free();
|
||||
tmpDir.deleteSync(recursive: true);
|
||||
});
|
||||
|
@ -62,14 +61,11 @@ void main() {
|
|||
|
||||
test('leaves changes added to index intact', () {
|
||||
File(filePath).writeAsStringSync('edit', mode: FileMode.append);
|
||||
final index = repo.index;
|
||||
index.add('file');
|
||||
repo.index.add('file');
|
||||
|
||||
Stash.create(repo: repo, stasher: stasher, flags: {GitStash.keepIndex});
|
||||
expect(repo.status.isEmpty, false);
|
||||
expect(repo.stashes.length, 1);
|
||||
|
||||
index.free();
|
||||
});
|
||||
|
||||
test('applies changes from stash', () {
|
||||
|
@ -109,8 +105,6 @@ void main() {
|
|||
Stash.apply(repo: repo, reinstateIndex: true);
|
||||
expect(repo.status, contains('stash.this'));
|
||||
expect(index.find('stash.this'), true);
|
||||
|
||||
index.free();
|
||||
});
|
||||
|
||||
test('throws when trying to apply with wrong index', () {
|
||||
|
@ -182,8 +176,6 @@ void main() {
|
|||
Stash.pop(repo: repo, reinstateIndex: true);
|
||||
expect(repo.status, contains('stash.this'));
|
||||
expect(index.find('stash.this'), true);
|
||||
|
||||
index.free();
|
||||
});
|
||||
|
||||
test('throws when trying to pop with wrong index', () {
|
||||
|
|
|
@ -47,8 +47,6 @@ void main() {
|
|||
expect(submodule.ignore, GitSubmoduleIgnore.none);
|
||||
expect(submodule.updateRule, GitSubmoduleUpdate.checkout);
|
||||
expect(submodule.toString(), contains('Submodule{'));
|
||||
|
||||
submodule.free();
|
||||
});
|
||||
|
||||
test('throws when trying to lookup and submodule not found', () {
|
||||
|
@ -70,8 +68,11 @@ void main() {
|
|||
});
|
||||
|
||||
test('updates with provided init flag', () {
|
||||
final submoduleFilePath =
|
||||
p.join(repo.workdir, testSubmodule, 'master.txt');
|
||||
final submoduleFilePath = p.join(
|
||||
repo.workdir,
|
||||
testSubmodule,
|
||||
'master.txt',
|
||||
);
|
||||
expect(File(submoduleFilePath).existsSync(), false);
|
||||
|
||||
Submodule.update(repo: repo, name: testSubmodule, init: true);
|
||||
|
@ -92,24 +93,20 @@ void main() {
|
|||
Submodule.update(repo: repo, name: testSubmodule);
|
||||
|
||||
final submoduleRepo = submodule.open();
|
||||
final subHead = submoduleRepo.head;
|
||||
expect(submoduleRepo, isA<Repository>());
|
||||
expect(subHead.target.sha, submoduleHeadSha);
|
||||
expect(submoduleRepo.head.target.sha, submoduleHeadSha);
|
||||
expect(
|
||||
submodule.workdirOid?.sha,
|
||||
'49322bb17d3acc9146f98c97d078513228bbf3c0',
|
||||
);
|
||||
|
||||
subHead.free();
|
||||
submoduleRepo.free();
|
||||
submodule.free();
|
||||
});
|
||||
|
||||
test('throws when trying to open repository for not initialized submodule',
|
||||
() {
|
||||
final submodule = Submodule.lookup(repo: repo, name: testSubmodule);
|
||||
expect(() => submodule.open(), throwsA(isA<LibGit2Error>()));
|
||||
submodule.free();
|
||||
});
|
||||
|
||||
test('adds submodule', () {
|
||||
|
@ -125,7 +122,6 @@ void main() {
|
|||
expect(submoduleRepo.isEmpty, false);
|
||||
|
||||
submoduleRepo.free();
|
||||
submodule.free();
|
||||
});
|
||||
|
||||
test('throws when trying to add submodule with wrong url', () {
|
||||
|
@ -170,9 +166,6 @@ void main() {
|
|||
expect(updatedSubmodule.branch, 'updated');
|
||||
expect(updatedSubmodule.ignore, GitSubmoduleIgnore.all);
|
||||
expect(updatedSubmodule.updateRule, GitSubmoduleUpdate.rebase);
|
||||
|
||||
updatedSubmodule.free();
|
||||
submodule.free();
|
||||
});
|
||||
|
||||
test('syncs', () {
|
||||
|
@ -205,13 +198,8 @@ void main() {
|
|||
'https://updated.com/',
|
||||
);
|
||||
|
||||
updatedSubmRepoConfig.free();
|
||||
submRepo.free();
|
||||
updatedSubmRepo.free();
|
||||
updatedSubmodule.free();
|
||||
submRepoConfig.free();
|
||||
repoConfig.free();
|
||||
submodule.free();
|
||||
});
|
||||
|
||||
test('reloads info', () {
|
||||
|
@ -222,8 +210,6 @@ void main() {
|
|||
submodule.reload();
|
||||
|
||||
expect(submodule.url, 'updated');
|
||||
|
||||
submodule.free();
|
||||
});
|
||||
|
||||
test('returns status for a submodule', () {
|
||||
|
@ -259,8 +245,11 @@ void main() {
|
|||
GitSubmoduleStatus.inWorkdir,
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
submodule.free();
|
||||
test('manually releases allocated memory', () {
|
||||
final submodule = Submodule.lookup(repo: repo, name: testSubmodule);
|
||||
expect(() => submodule.free(), returnsNormally);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -21,7 +21,6 @@ void main() {
|
|||
});
|
||||
|
||||
tearDown(() {
|
||||
tag.free();
|
||||
repo.free();
|
||||
tmpDir.deleteSync(recursive: true);
|
||||
});
|
||||
|
@ -50,18 +49,14 @@ void main() {
|
|||
offset: 180,
|
||||
);
|
||||
final target = tag.target as Commit;
|
||||
final tagger = tag.tagger;
|
||||
|
||||
expect(tag.oid, tagOid);
|
||||
expect(tag.name, 'v0.2');
|
||||
expect(tag.message, 'annotated tag\n');
|
||||
expect(tag.targetType, GitObject.commit);
|
||||
expect(target.message, 'add subdirectory file\n');
|
||||
expect(tagger, signature);
|
||||
expect(tag.tagger, signature);
|
||||
expect(tag.toString(), contains('Tag{'));
|
||||
|
||||
signature.free();
|
||||
target.free();
|
||||
});
|
||||
|
||||
test('creates new annotated tag with commit as target', () {
|
||||
|
@ -85,19 +80,14 @@ void main() {
|
|||
);
|
||||
|
||||
final newTag = Tag.lookup(repo: repo, oid: oid);
|
||||
final tagger = newTag.tagger;
|
||||
final newTagTarget = newTag.target as Commit;
|
||||
|
||||
expect(newTag.oid, oid);
|
||||
expect(newTag.name, tagName);
|
||||
expect(newTag.message, message);
|
||||
expect(newTag.targetOid.sha, targetSHA);
|
||||
expect(tagger, signature);
|
||||
expect(newTag.tagger, signature);
|
||||
expect(newTagTarget.oid, target);
|
||||
|
||||
newTag.free();
|
||||
newTagTarget.free();
|
||||
signature.free();
|
||||
});
|
||||
|
||||
test('creates new lightweight tag with commit as target', () {
|
||||
|
@ -115,8 +105,6 @@ void main() {
|
|||
|
||||
expect(newTag.shorthand, tagName);
|
||||
expect(newTag.target, target);
|
||||
|
||||
newTag.free();
|
||||
});
|
||||
|
||||
test('creates new annotated tag with tree as target', () {
|
||||
|
@ -139,18 +127,13 @@ void main() {
|
|||
);
|
||||
|
||||
final newTag = Tag.lookup(repo: repo, oid: oid);
|
||||
final tagger = newTag.tagger;
|
||||
final newTagTarget = newTag.target as Tree;
|
||||
|
||||
expect(newTag.oid, oid);
|
||||
expect(newTag.name, tagName);
|
||||
expect(newTag.message, message);
|
||||
expect(tagger, signature);
|
||||
expect(newTag.tagger, signature);
|
||||
expect(newTagTarget.oid, target);
|
||||
|
||||
newTag.free();
|
||||
newTagTarget.free();
|
||||
signature.free();
|
||||
});
|
||||
|
||||
test('creates new lightweight tag with tree as target', () {
|
||||
|
@ -168,8 +151,6 @@ void main() {
|
|||
|
||||
expect(newTag.shorthand, tagName);
|
||||
expect(newTag.target, target);
|
||||
|
||||
newTag.free();
|
||||
});
|
||||
|
||||
test('creates new annotated tag with blob as target', () {
|
||||
|
@ -192,18 +173,13 @@ void main() {
|
|||
);
|
||||
|
||||
final newTag = Tag.lookup(repo: repo, oid: oid);
|
||||
final tagger = newTag.tagger;
|
||||
final newTagTarget = newTag.target as Blob;
|
||||
|
||||
expect(newTag.oid, oid);
|
||||
expect(newTag.name, tagName);
|
||||
expect(newTag.message, message);
|
||||
expect(tagger, signature);
|
||||
expect(newTag.tagger, signature);
|
||||
expect(newTagTarget.oid, target);
|
||||
|
||||
newTag.free();
|
||||
newTagTarget.free();
|
||||
signature.free();
|
||||
});
|
||||
|
||||
test('creates new lightweight tag with blob as target', () {
|
||||
|
@ -221,8 +197,6 @@ void main() {
|
|||
|
||||
expect(newTag.shorthand, tagName);
|
||||
expect(newTag.target, target);
|
||||
|
||||
newTag.free();
|
||||
});
|
||||
|
||||
test('creates new annotated tag with tag as target', () {
|
||||
|
@ -244,18 +218,13 @@ void main() {
|
|||
);
|
||||
|
||||
final newTag = Tag.lookup(repo: repo, oid: oid);
|
||||
final tagger = newTag.tagger;
|
||||
final newTagTarget = newTag.target as Tag;
|
||||
|
||||
expect(newTag.oid, oid);
|
||||
expect(newTag.name, tagName);
|
||||
expect(newTag.message, message);
|
||||
expect(tagger, signature);
|
||||
expect(newTag.tagger, signature);
|
||||
expect(newTagTarget.oid, tag.oid);
|
||||
|
||||
newTag.free();
|
||||
newTagTarget.free();
|
||||
signature.free();
|
||||
});
|
||||
|
||||
test('creates new lightweight tag with tag as target', () {
|
||||
|
@ -272,8 +241,6 @@ void main() {
|
|||
|
||||
expect(newTag.shorthand, tagName);
|
||||
expect(newTag.target, tag.oid);
|
||||
|
||||
newTag.free();
|
||||
});
|
||||
|
||||
test(
|
||||
|
@ -303,20 +270,15 @@ void main() {
|
|||
);
|
||||
|
||||
final newTag = Tag.lookup(repo: repo, oid: oid);
|
||||
final tagger = newTag.tagger;
|
||||
final newTagTarget = newTag.target as Commit;
|
||||
|
||||
expect(newTag.oid, oid);
|
||||
expect(newTag.name, tagName);
|
||||
expect(newTag.message, message);
|
||||
expect(newTag.targetOid.sha, targetSHA);
|
||||
expect(tagger, signature);
|
||||
expect(newTag.tagger, signature);
|
||||
expect(newTagTarget.oid, target);
|
||||
expect(repo.tags.length, equals(2));
|
||||
|
||||
newTag.free();
|
||||
newTagTarget.free();
|
||||
signature.free();
|
||||
});
|
||||
|
||||
test(
|
||||
|
@ -342,8 +304,6 @@ void main() {
|
|||
expect(newTag.shorthand, tagName);
|
||||
expect(newTag.target, target);
|
||||
expect(repo.tags.length, equals(2));
|
||||
|
||||
newTag.free();
|
||||
});
|
||||
|
||||
test('throws when trying to create annotated tag with invalid name', () {
|
||||
|
@ -420,5 +380,10 @@ void main() {
|
|||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
});
|
||||
|
||||
test('manually releases allocated memory', () {
|
||||
tag = Tag.lookup(repo: repo, oid: tagOid);
|
||||
expect(() => tag.free(), returnsNormally);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@ void main() {
|
|||
});
|
||||
|
||||
tearDown(() {
|
||||
tree.free();
|
||||
repo.free();
|
||||
tmpDir.deleteSync(recursive: true);
|
||||
});
|
||||
|
@ -65,7 +64,6 @@ void main() {
|
|||
final entry = tree['dir/dir_file.txt'];
|
||||
expect(entry.oid.sha, 'e69de29bb2d1d6434b8b29ae775ad8c2e48c5391');
|
||||
expect(entry.toString(), contains('TreeEntry{'));
|
||||
entry.free();
|
||||
});
|
||||
|
||||
test('throws when nothing found for provided path', () {
|
||||
|
@ -92,9 +90,17 @@ void main() {
|
|||
expect(entry.name, 'filename');
|
||||
expect(entry.filemode, GitFilemode.blob);
|
||||
expect(entry.oid, fileOid);
|
||||
});
|
||||
|
||||
builder.free();
|
||||
newTree.free();
|
||||
test('manually releases allocated memory', () {
|
||||
final tree = Tree.lookup(repo: repo, oid: repo['a8ae3dd']);
|
||||
expect(() => tree.free(), returnsNormally);
|
||||
});
|
||||
|
||||
test(
|
||||
'manually releases allocated memory for tree entry '
|
||||
'looked up by path', () {
|
||||
expect(() => tree['dir/dir_file.txt'].free(), returnsNormally);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@ void main() {
|
|||
});
|
||||
|
||||
tearDown(() {
|
||||
tree.free();
|
||||
repo.free();
|
||||
tmpDir.deleteSync(recursive: true);
|
||||
});
|
||||
|
@ -29,18 +28,14 @@ void main() {
|
|||
final builder = TreeBuilder(repo: repo);
|
||||
expect(builder, isA<TreeBuilder>());
|
||||
expect(builder.toString(), contains('TreeBuilder{'));
|
||||
builder.free();
|
||||
});
|
||||
|
||||
test('initializes tree builder with provided tree', () {
|
||||
final builder = TreeBuilder(repo: repo, tree: tree);
|
||||
final oid = builder.write();
|
||||
|
||||
expect(builder, isA<TreeBuilder>());
|
||||
expect(builder.length, tree.length);
|
||||
expect(oid, tree.oid);
|
||||
|
||||
builder.free();
|
||||
expect(builder.write(), tree.oid);
|
||||
});
|
||||
|
||||
test('throws when trying to initialize and error occurs', () {
|
||||
|
@ -56,8 +51,6 @@ void main() {
|
|||
expect(builder.length, 4);
|
||||
builder.clear();
|
||||
expect(builder.length, 0);
|
||||
|
||||
builder.free();
|
||||
});
|
||||
|
||||
test('builds the tree builder from entry of tree', () {
|
||||
|
@ -72,8 +65,6 @@ void main() {
|
|||
filemode: entry.filemode,
|
||||
);
|
||||
expect(builder[entry.name].name, entry.name);
|
||||
|
||||
builder.free();
|
||||
});
|
||||
|
||||
test('throws when trying to add entry with invalid name or invalid oid',
|
||||
|
@ -96,8 +87,6 @@ void main() {
|
|||
),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
|
||||
builder.free();
|
||||
});
|
||||
|
||||
test('removes an entry', () {
|
||||
|
@ -108,14 +97,17 @@ void main() {
|
|||
builder.remove('.gitignore');
|
||||
expect(() => builder['.gitignore'], throwsA(isA<ArgumentError>()));
|
||||
expect(builder.length, tree.length - 1);
|
||||
|
||||
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>()));
|
||||
builder.free();
|
||||
expect(
|
||||
() => TreeBuilder(repo: repo).remove('not.there'),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
});
|
||||
|
||||
test('manually releases allocated memory', () {
|
||||
expect(() => TreeBuilder(repo: repo).free(), returnsNormally);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -38,28 +38,21 @@ void main() {
|
|||
name: worktreeName,
|
||||
path: worktreeDir.path,
|
||||
);
|
||||
final branches = repo.branches;
|
||||
|
||||
expect(repo.worktrees, [worktreeName]);
|
||||
expect(branches.any((branch) => branch.name == worktreeName), true);
|
||||
expect(repo.branches.any((branch) => branch.name == worktreeName), true);
|
||||
expect(worktree.name, worktreeName);
|
||||
expect(worktree.path, contains('worktree'));
|
||||
expect(worktree.isLocked, false);
|
||||
expect(worktree.toString(), contains('Worktree{'));
|
||||
expect(File(p.join(worktreeDir.path, '.git')).existsSync(), true);
|
||||
|
||||
for (final branch in branches) {
|
||||
branch.free();
|
||||
}
|
||||
worktree.free();
|
||||
});
|
||||
|
||||
test('creates worktree at provided path from provided reference', () {
|
||||
final head = RevParse.single(repo: repo, spec: 'HEAD') as Commit;
|
||||
final worktreeBranch = Branch.create(
|
||||
repo: repo,
|
||||
name: 'v1',
|
||||
target: head,
|
||||
target: RevParse.single(repo: repo, spec: 'HEAD') as Commit,
|
||||
);
|
||||
final ref = Reference.lookup(repo: repo, name: 'refs/heads/v1');
|
||||
expect(repo.worktrees, <String>[]);
|
||||
|
@ -83,14 +76,6 @@ void main() {
|
|||
expect(repo.worktrees, <String>[]);
|
||||
expect(worktreeBranch.isCheckedOut, false);
|
||||
expect(branches.any((branch) => branch.name == 'v1'), true);
|
||||
|
||||
for (final branch in branches) {
|
||||
branch.free();
|
||||
}
|
||||
worktreeBranch.free();
|
||||
ref.free();
|
||||
head.free();
|
||||
worktree.free();
|
||||
});
|
||||
|
||||
test('throws when trying to create worktree with invalid name or path', () {
|
||||
|
@ -113,19 +98,16 @@ void main() {
|
|||
});
|
||||
|
||||
test('lookups worktree', () {
|
||||
final worktree = Worktree.create(
|
||||
Worktree.create(
|
||||
repo: repo,
|
||||
name: worktreeName,
|
||||
path: worktreeDir.path,
|
||||
);
|
||||
final lookedupWorktree = Worktree.lookup(repo: repo, name: worktreeName);
|
||||
final worktree = Worktree.lookup(repo: repo, name: worktreeName);
|
||||
|
||||
expect(lookedupWorktree.name, worktreeName);
|
||||
expect(lookedupWorktree.path, contains('worktree'));
|
||||
expect(lookedupWorktree.isLocked, false);
|
||||
|
||||
lookedupWorktree.free();
|
||||
worktree.free();
|
||||
expect(worktree.name, worktreeName);
|
||||
expect(worktree.path, contains('worktree'));
|
||||
expect(worktree.isLocked, false);
|
||||
});
|
||||
|
||||
test('throws when trying to lookup and error occurs', () {
|
||||
|
@ -148,8 +130,6 @@ void main() {
|
|||
|
||||
worktree.unlock();
|
||||
expect(worktree.isLocked, false);
|
||||
|
||||
worktree.free();
|
||||
});
|
||||
|
||||
test('prunes worktree', () {
|
||||
|
@ -170,8 +150,6 @@ void main() {
|
|||
|
||||
worktree.prune();
|
||||
expect(repo.worktrees, <String>[]);
|
||||
|
||||
worktree.free();
|
||||
});
|
||||
|
||||
test('throws when trying get list of worktrees and error occurs', () {
|
||||
|
@ -180,5 +158,14 @@ void main() {
|
|||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
});
|
||||
|
||||
test('manually releases allocated memory', () {
|
||||
final worktree = Worktree.create(
|
||||
repo: repo,
|
||||
name: worktreeName,
|
||||
path: worktreeDir.path,
|
||||
);
|
||||
expect(() => worktree.free(), returnsNormally);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue