mirror of
https://github.com/SkinnyMind/libgit2dart.git
synced 2025-05-05 04:39:07 -04:00
refactor!: use class names instead of aliases from Repository in tests (#37)
BREAKING CHANGE: move API methods related to diffing into Diff class
This commit is contained in:
parent
3e1ece4e6f
commit
08cbe8a17f
28 changed files with 943 additions and 834 deletions
|
@ -60,7 +60,8 @@ void main() {
|
|||
|
||||
group('Blame', () {
|
||||
test('returns the blame for provided file', () {
|
||||
final blame = repo.blame(
|
||||
final blame = Blame.file(
|
||||
repo: repo,
|
||||
path: 'feature_file',
|
||||
oldestCommit: repo['f17d0d4'],
|
||||
);
|
||||
|
@ -86,11 +87,14 @@ void main() {
|
|||
});
|
||||
|
||||
test('throws when provided file path is invalid', () {
|
||||
expect(() => repo.blame(path: 'invalid'), throwsA(isA<LibGit2Error>()));
|
||||
expect(
|
||||
() => Blame.file(repo: repo, path: 'invalid'),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
});
|
||||
|
||||
test('returns blame for buffer', () {
|
||||
final blame = repo.blame(path: 'feature_file');
|
||||
final blame = Blame.file(repo: repo, path: 'feature_file');
|
||||
expect(blame.length, 2);
|
||||
|
||||
final bufferBlame = Blame.buffer(reference: blame, buffer: ' ');
|
||||
|
@ -106,7 +110,7 @@ void main() {
|
|||
});
|
||||
|
||||
test('throws when trying to get blame for empty buffer', () {
|
||||
final blame = repo.blame(path: 'feature_file');
|
||||
final blame = Blame.file(repo: repo, path: 'feature_file');
|
||||
expect(
|
||||
() => Blame.buffer(reference: blame, buffer: ''),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
|
@ -115,7 +119,8 @@ void main() {
|
|||
});
|
||||
|
||||
test('returns the blame for provided file with minMatchCharacters set', () {
|
||||
final blame = repo.blame(
|
||||
final blame = Blame.file(
|
||||
repo: repo,
|
||||
path: 'feature_file',
|
||||
minMatchCharacters: 1,
|
||||
flags: {GitBlameFlag.trackCopiesSameFile},
|
||||
|
@ -127,7 +132,7 @@ void main() {
|
|||
});
|
||||
|
||||
test('returns the blame for provided line', () {
|
||||
final blame = repo.blame(path: 'feature_file');
|
||||
final blame = Blame.file(repo: repo, path: 'feature_file');
|
||||
|
||||
final hunk = blame.forLine(1);
|
||||
|
||||
|
@ -148,21 +153,22 @@ void main() {
|
|||
});
|
||||
|
||||
test('throws when provided index for hunk is invalid', () {
|
||||
final blame = repo.blame(path: 'feature_file');
|
||||
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 = repo.blame(path: 'feature_file');
|
||||
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', () {
|
||||
final blame = repo.blame(
|
||||
final blame = Blame.file(
|
||||
repo: repo,
|
||||
path: 'feature_file',
|
||||
newestCommit: repo['fc38877'],
|
||||
flags: {GitBlameFlag.ignoreWhitespace},
|
||||
|
@ -190,7 +196,8 @@ void main() {
|
|||
|
||||
test('returns the blame for provided file with minLine and maxLine set',
|
||||
() {
|
||||
final blame = repo.blame(
|
||||
final blame = Blame.file(
|
||||
repo: repo,
|
||||
path: 'feature_file',
|
||||
minLine: 1,
|
||||
maxLine: 1,
|
||||
|
@ -217,7 +224,7 @@ void main() {
|
|||
});
|
||||
|
||||
test('returns string representation of BlameHunk object', () {
|
||||
final blame = repo.blame(path: 'feature_file');
|
||||
final blame = Blame.file(repo: repo, path: 'feature_file');
|
||||
expect(blame.toString(), contains('BlameHunk{'));
|
||||
blame.free();
|
||||
});
|
||||
|
|
|
@ -26,20 +26,20 @@ void main() {
|
|||
|
||||
group('Blob', () {
|
||||
test('lookups blob with provided oid', () {
|
||||
final blob = repo.lookupBlob(repo[blobSHA]);
|
||||
final blob = Blob.lookup(repo: repo, oid: repo[blobSHA]);
|
||||
expect(blob, isA<Blob>());
|
||||
blob.free();
|
||||
});
|
||||
|
||||
test('throws when trying to lookup with invalid oid', () {
|
||||
expect(
|
||||
() => repo.lookupBlob(repo['0' * 40]),
|
||||
() => Blob.lookup(repo: repo, oid: repo['0' * 40]),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
});
|
||||
|
||||
test('returns correct values', () {
|
||||
final blob = repo.lookupBlob(repo[blobSHA]);
|
||||
final blob = Blob.lookup(repo: repo, oid: repo[blobSHA]);
|
||||
|
||||
expect(blob.oid.sha, blobSHA);
|
||||
expect(blob.isBinary, false);
|
||||
|
@ -50,8 +50,8 @@ void main() {
|
|||
});
|
||||
|
||||
test('creates new blob with provided content', () {
|
||||
final oid = repo.createBlob(newBlobContent);
|
||||
final newBlob = repo.lookupBlob(oid);
|
||||
final oid = Blob.create(repo: repo, content: newBlobContent);
|
||||
final newBlob = Blob.lookup(repo: repo, oid: oid);
|
||||
|
||||
expect(newBlob.oid.sha, '18fdaeef018e57a92bcad2d4a35b577f34089af6');
|
||||
expect(newBlob.isBinary, false);
|
||||
|
@ -70,8 +70,11 @@ void main() {
|
|||
});
|
||||
|
||||
test('creates new blob from file at provided relative path', () {
|
||||
final oid = repo.createBlobFromWorkdir('feature_file');
|
||||
final newBlob = repo.lookupBlob(oid);
|
||||
final oid = Blob.createFromWorkdir(
|
||||
repo: repo,
|
||||
relativePath: 'feature_file',
|
||||
);
|
||||
final newBlob = Blob.lookup(repo: repo, oid: oid);
|
||||
|
||||
expect(newBlob.oid.sha, blobSHA);
|
||||
expect(newBlob.isBinary, false);
|
||||
|
@ -83,7 +86,10 @@ void main() {
|
|||
|
||||
test('throws when creating new blob from invalid path', () {
|
||||
expect(
|
||||
() => repo.createBlobFromWorkdir('invalid/path.txt'),
|
||||
() => Blob.createFromWorkdir(
|
||||
repo: repo,
|
||||
relativePath: 'invalid/path.txt',
|
||||
),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
});
|
||||
|
@ -92,8 +98,8 @@ void main() {
|
|||
final outsideFile = File(
|
||||
p.join(Directory.current.absolute.path, 'test', 'blob_test.dart'),
|
||||
);
|
||||
final oid = repo.createBlobFromDisk(outsideFile.path);
|
||||
final newBlob = repo.lookupBlob(oid);
|
||||
final oid = Blob.createFromDisk(repo: repo, path: outsideFile.path);
|
||||
final newBlob = Blob.lookup(repo: repo, oid: oid);
|
||||
|
||||
expect(newBlob, isA<Blob>());
|
||||
expect(newBlob.isBinary, false);
|
||||
|
@ -103,13 +109,13 @@ void main() {
|
|||
|
||||
test('throws when trying to create from invalid path', () {
|
||||
expect(
|
||||
() => repo.createBlobFromDisk('invalid.file'),
|
||||
() => Blob.createFromDisk(repo: repo, path: 'invalid.file'),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
});
|
||||
|
||||
test('duplicates blob', () {
|
||||
final blob = repo.lookupBlob(repo[blobSHA]);
|
||||
final blob = Blob.lookup(repo: repo, oid: repo[blobSHA]);
|
||||
final dupBlob = blob.duplicate();
|
||||
|
||||
expect(blob.oid.sha, dupBlob.oid.sha);
|
||||
|
@ -119,8 +125,8 @@ void main() {
|
|||
});
|
||||
|
||||
test('filters content of a blob', () {
|
||||
final blobOid = repo.createBlob('clrf\nclrf\n');
|
||||
final blob = repo.lookupBlob(blobOid);
|
||||
final blobOid = Blob.create(repo: repo, content: 'clrf\nclrf\n');
|
||||
final blob = Blob.lookup(repo: repo, oid: blobOid);
|
||||
|
||||
expect(blob.filterContent(asPath: 'file.crlf'), 'clrf\r\nclrf\r\n');
|
||||
|
||||
|
@ -130,11 +136,12 @@ void main() {
|
|||
test('filters content of a blob with provided commit for attributes', () {
|
||||
repo.checkout(target: 'refs/tags/v0.2');
|
||||
|
||||
final blobOid = repo.createBlob('clrf\nclrf\n');
|
||||
final blob = repo.lookupBlob(blobOid);
|
||||
final blobOid = Blob.create(repo: repo, content: 'clrf\nclrf\n');
|
||||
final blob = Blob.lookup(repo: repo, oid: blobOid);
|
||||
|
||||
final commit = repo.lookupCommit(
|
||||
repo['d2f3abc9324a22a9f80fec2c131ec43c93430618'],
|
||||
final commit = Commit.lookup(
|
||||
repo: repo,
|
||||
oid: repo['d2f3abc9324a22a9f80fec2c131ec43c93430618'],
|
||||
);
|
||||
|
||||
expect(
|
||||
|
@ -176,31 +183,26 @@ index e69de29..0000000
|
|||
+++ /dev/null
|
||||
""";
|
||||
test('creates patch with changes between blobs', () {
|
||||
final a = repo.lookupBlob(
|
||||
repo['e69de29bb2d1d6434b8b29ae775ad8c2e48c5391'],
|
||||
);
|
||||
final b = repo.lookupBlob(
|
||||
repo['9c78c21d6680a7ffebc76f7ac68cacc11d8f48bc'],
|
||||
);
|
||||
final patch = repo.diffBlobs(
|
||||
a: a,
|
||||
b: b,
|
||||
aPath: path,
|
||||
bPath: path,
|
||||
final oldBlob = Blob.lookup(repo: repo, oid: repo['e69de29']);
|
||||
final newBlob = Blob.lookup(repo: repo, oid: repo['9c78c21']);
|
||||
|
||||
final patch = oldBlob.diff(
|
||||
newBlob: newBlob,
|
||||
oldAsPath: path,
|
||||
newAsPath: path,
|
||||
);
|
||||
|
||||
expect(patch.text, blobPatch);
|
||||
|
||||
patch.free();
|
||||
a.free();
|
||||
b.free();
|
||||
oldBlob.free();
|
||||
newBlob.free();
|
||||
});
|
||||
|
||||
test('creates patch with changes between blobs from one blob (delete)',
|
||||
() {
|
||||
final blob = repo.lookupBlob(
|
||||
repo['e69de29bb2d1d6434b8b29ae775ad8c2e48c5391'],
|
||||
);
|
||||
final blob = Blob.lookup(repo: repo, oid: repo['e69de29']);
|
||||
|
||||
final patch = blob.diff(
|
||||
newBlob: null,
|
||||
oldAsPath: path,
|
||||
|
@ -214,9 +216,7 @@ index e69de29..0000000
|
|||
});
|
||||
|
||||
test('creates patch with changes between blob and buffer', () {
|
||||
final blob = repo.lookupBlob(
|
||||
repo['e69de29bb2d1d6434b8b29ae775ad8c2e48c5391'],
|
||||
);
|
||||
final blob = Blob.lookup(repo: repo, oid: repo['e69de29']);
|
||||
|
||||
final patch = blob.diffToBuffer(
|
||||
buffer: 'Feature edit\n',
|
||||
|
@ -229,25 +229,19 @@ index e69de29..0000000
|
|||
});
|
||||
|
||||
test('creates patch with changes between blob and buffer (delete)', () {
|
||||
final a = repo.lookupBlob(
|
||||
repo['e69de29bb2d1d6434b8b29ae775ad8c2e48c5391'],
|
||||
);
|
||||
final patch = Patch.create(
|
||||
a: a,
|
||||
b: null,
|
||||
aPath: path,
|
||||
bPath: path,
|
||||
);
|
||||
final blob = Blob.lookup(repo: repo, oid: repo['e69de29']);
|
||||
|
||||
final patch = blob.diffToBuffer(buffer: null, oldAsPath: path);
|
||||
|
||||
expect(patch.text, blobPatchDelete);
|
||||
|
||||
patch.free();
|
||||
a.free();
|
||||
blob.free();
|
||||
});
|
||||
});
|
||||
|
||||
test('returns string representation of Blob object', () {
|
||||
final blob = repo.lookupBlob(repo[blobSHA]);
|
||||
final blob = Blob.lookup(repo: repo, oid: repo[blobSHA]);
|
||||
expect(blob.toString(), contains('Blob{'));
|
||||
blob.free();
|
||||
});
|
||||
|
|
|
@ -28,7 +28,7 @@ void main() {
|
|||
group('Branch', () {
|
||||
test('returns a list of all branches', () {
|
||||
const branchesExpected = ['feature', 'master', 'origin/master'];
|
||||
final branches = repo.branches;
|
||||
final branches = Branch.list(repo: repo);
|
||||
|
||||
for (var i = 0; i < branches.length; i++) {
|
||||
expect(branches[i].name, branchesExpected[i]);
|
||||
|
@ -38,7 +38,7 @@ void main() {
|
|||
|
||||
test('returns a list of local branches', () {
|
||||
const branchesExpected = ['feature', 'master'];
|
||||
final branches = repo.branchesLocal;
|
||||
final branches = Branch.list(repo: repo, type: GitBranch.local);
|
||||
|
||||
for (var i = 0; i < branches.length; i++) {
|
||||
expect(branches[i].name, branchesExpected[i]);
|
||||
|
@ -48,7 +48,7 @@ void main() {
|
|||
|
||||
test('returns a list of remote branches', () {
|
||||
const branchesExpected = ['origin/master'];
|
||||
final branches = repo.branchesRemote;
|
||||
final branches = Branch.list(repo: repo, type: GitBranch.remote);
|
||||
|
||||
for (var i = 0; i < branches.length; i++) {
|
||||
expect(branches[i].name, branchesExpected[i]);
|
||||
|
@ -57,31 +57,37 @@ void main() {
|
|||
});
|
||||
|
||||
test('throws when trying to return list and error occurs', () {
|
||||
final nullRepo = Repository(nullptr);
|
||||
expect(() => Branch.list(repo: nullRepo), throwsA(isA<LibGit2Error>()));
|
||||
expect(
|
||||
() => Branch.list(repo: Repository(nullptr)),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
});
|
||||
|
||||
test('returns a branch with provided name', () {
|
||||
final branch = repo.lookupBranch(name: 'master');
|
||||
final branch = Branch.lookup(repo: repo, name: 'master');
|
||||
expect(branch.target.sha, lastCommit.sha);
|
||||
branch.free();
|
||||
});
|
||||
|
||||
test('throws when provided name not found', () {
|
||||
expect(
|
||||
() => repo.lookupBranch(name: 'invalid'),
|
||||
() => Branch.lookup(repo: repo, name: 'invalid'),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
|
||||
expect(
|
||||
() => repo.lookupBranch(name: 'origin/invalid', type: GitBranch.remote),
|
||||
() => Branch.lookup(
|
||||
repo: repo,
|
||||
name: 'origin/invalid',
|
||||
type: GitBranch.remote,
|
||||
),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
});
|
||||
|
||||
test('checks if branch is current head', () {
|
||||
final masterBranch = repo.lookupBranch(name: 'master');
|
||||
final featureBranch = repo.lookupBranch(name: 'feature');
|
||||
final masterBranch = Branch.lookup(repo: repo, name: 'master');
|
||||
final featureBranch = Branch.lookup(repo: repo, name: 'feature');
|
||||
|
||||
expect(masterBranch.isHead, true);
|
||||
expect(featureBranch.isHead, false);
|
||||
|
@ -99,8 +105,8 @@ void main() {
|
|||
});
|
||||
|
||||
test('checks if branch is checked out', () {
|
||||
final masterBranch = repo.lookupBranch(name: 'master');
|
||||
final featureBranch = repo.lookupBranch(name: 'feature');
|
||||
final masterBranch = Branch.lookup(repo: repo, name: 'master');
|
||||
final featureBranch = Branch.lookup(repo: repo, name: 'feature');
|
||||
|
||||
expect(masterBranch.isCheckedOut, true);
|
||||
expect(featureBranch.isCheckedOut, false);
|
||||
|
@ -118,7 +124,7 @@ void main() {
|
|||
});
|
||||
|
||||
test('returns name', () {
|
||||
final branch = repo.lookupBranch(name: 'master');
|
||||
final branch = Branch.lookup(repo: repo, name: 'master');
|
||||
expect(branch.name, 'master');
|
||||
branch.free();
|
||||
});
|
||||
|
@ -129,7 +135,7 @@ void main() {
|
|||
});
|
||||
|
||||
test('returns remote name of a remote-tracking branch', () {
|
||||
final branch = repo.branchesRemote.first;
|
||||
final branch = Branch.list(repo: repo, type: GitBranch.remote).first;
|
||||
expect(branch.remoteName, 'origin');
|
||||
branch.free();
|
||||
});
|
||||
|
@ -137,12 +143,12 @@ void main() {
|
|||
test(
|
||||
'throws when getting remote name of a remote-tracking branch and '
|
||||
'error occurs', () {
|
||||
final branch = repo.lookupBranch(name: 'master');
|
||||
final branch = Branch.lookup(repo: repo, name: 'master');
|
||||
expect(() => branch.remoteName, throwsA(isA<LibGit2Error>()));
|
||||
});
|
||||
|
||||
test('returns upstream of a local branch', () {
|
||||
final branch = repo.lookupBranch(name: 'master');
|
||||
final branch = Branch.lookup(repo: repo, name: 'master');
|
||||
final upstream = branch.upstream;
|
||||
|
||||
expect(upstream.isRemote, true);
|
||||
|
@ -153,17 +159,18 @@ void main() {
|
|||
});
|
||||
|
||||
test('throws when trying to get upstream of a remote branch', () {
|
||||
final branch = repo.branchesRemote.first;
|
||||
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 = repo.lookupBranch(name: 'master');
|
||||
final branch = Branch.lookup(repo: repo, name: 'master');
|
||||
var upstream = branch.upstream;
|
||||
expect(upstream.name, 'refs/remotes/origin/master');
|
||||
|
||||
final ref = repo.createReference(
|
||||
final ref = Reference.create(
|
||||
repo: repo,
|
||||
name: 'refs/remotes/origin/new',
|
||||
target: 'refs/heads/master',
|
||||
);
|
||||
|
@ -178,7 +185,7 @@ void main() {
|
|||
});
|
||||
|
||||
test('unsets upstream of a branch', () {
|
||||
final branch = repo.lookupBranch(name: 'master');
|
||||
final branch = Branch.lookup(repo: repo, name: 'master');
|
||||
final upstream = branch.upstream;
|
||||
expect(upstream.name, 'refs/remotes/origin/master');
|
||||
|
||||
|
@ -190,7 +197,7 @@ void main() {
|
|||
});
|
||||
|
||||
test('throws when trying to set upstream of a branch and error occurs', () {
|
||||
final branch = repo.lookupBranch(name: 'master');
|
||||
final branch = Branch.lookup(repo: repo, name: 'master');
|
||||
expect(
|
||||
() => branch.setUpstream('some/upstream'),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
|
@ -199,50 +206,53 @@ void main() {
|
|||
});
|
||||
|
||||
test('returns upstream name of a local branch', () {
|
||||
final branch = repo.lookupBranch(name: 'master');
|
||||
final branch = Branch.lookup(repo: repo, name: 'master');
|
||||
expect(branch.upstreamName, 'refs/remotes/origin/master');
|
||||
branch.free();
|
||||
});
|
||||
|
||||
test('throws when trying to get upstream name of a branch and error occurs',
|
||||
() {
|
||||
final branch = repo.lookupBranch(name: 'feature');
|
||||
final branch = Branch.lookup(repo: repo, name: 'feature');
|
||||
expect(() => branch.upstreamName, throwsA(isA<LibGit2Error>()));
|
||||
branch.free();
|
||||
});
|
||||
|
||||
test('returns upstream remote of a local branch', () {
|
||||
final branch = repo.lookupBranch(name: 'master');
|
||||
final branch = Branch.lookup(repo: repo, name: 'master');
|
||||
expect(branch.upstreamRemote, 'origin');
|
||||
branch.free();
|
||||
});
|
||||
|
||||
test('throws when trying to get upstream remote of a remote branch', () {
|
||||
final branch = repo.branchesRemote.first;
|
||||
final branch = Branch.list(repo: repo, type: GitBranch.remote).first;
|
||||
expect(() => branch.upstreamName, throwsA(isA<LibGit2Error>()));
|
||||
branch.free();
|
||||
});
|
||||
|
||||
test('returns upstream merge of a local branch', () {
|
||||
final branch = repo.lookupBranch(name: 'master');
|
||||
final branch = Branch.lookup(repo: repo, name: 'master');
|
||||
expect(branch.upstreamMerge, 'refs/heads/master');
|
||||
branch.free();
|
||||
});
|
||||
|
||||
test('throws when trying to get upstream merge of a remote branch', () {
|
||||
final branch = repo.branchesRemote.first;
|
||||
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 = repo.lookupCommit(lastCommit);
|
||||
final commit = Commit.lookup(repo: repo, oid: lastCommit);
|
||||
final branch = Branch.create(
|
||||
repo: repo,
|
||||
name: 'testing',
|
||||
target: commit,
|
||||
);
|
||||
final branches = Branch.list(repo: repo);
|
||||
|
||||
final branch = repo.createBranch(name: 'testing', target: commit);
|
||||
final branches = repo.branches;
|
||||
|
||||
expect(repo.branches.length, 4);
|
||||
expect(branches.length, 4);
|
||||
expect(branch.target, lastCommit);
|
||||
|
||||
for (final branch in branches) {
|
||||
|
@ -253,10 +263,10 @@ void main() {
|
|||
});
|
||||
|
||||
test('throws when name already exists', () {
|
||||
final commit = repo.lookupCommit(lastCommit);
|
||||
final commit = Commit.lookup(repo: repo, oid: lastCommit);
|
||||
|
||||
expect(
|
||||
() => repo.createBranch(name: 'feature', target: commit),
|
||||
() => Branch.create(repo: repo, name: 'feature', target: commit),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
|
||||
|
@ -264,14 +274,14 @@ void main() {
|
|||
});
|
||||
|
||||
test('creates branch with force flag when name already exists', () {
|
||||
final commit = repo.lookupCommit(lastCommit);
|
||||
|
||||
final branch = repo.createBranch(
|
||||
final commit = Commit.lookup(repo: repo, oid: lastCommit);
|
||||
final branch = Branch.create(
|
||||
repo: repo,
|
||||
name: 'feature',
|
||||
target: commit,
|
||||
force: true,
|
||||
);
|
||||
final localBranches = repo.branchesLocal;
|
||||
final localBranches = Branch.list(repo: repo, type: GitBranch.local);
|
||||
|
||||
expect(localBranches.length, 2);
|
||||
expect(branch.target, lastCommit);
|
||||
|
@ -286,17 +296,17 @@ void main() {
|
|||
|
||||
group('delete()', () {
|
||||
test('deletes branch', () {
|
||||
repo.deleteBranch('feature');
|
||||
Branch.delete(repo: repo, name: 'feature');
|
||||
|
||||
expect(
|
||||
() => repo.lookupBranch(name: 'feature'),
|
||||
() => Branch.lookup(repo: repo, name: 'feature'),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
});
|
||||
|
||||
test('throws when trying to delete current HEAD', () {
|
||||
expect(
|
||||
() => repo.deleteBranch('master'),
|
||||
() => Branch.delete(repo: repo, name: 'master'),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
});
|
||||
|
@ -304,13 +314,13 @@ void main() {
|
|||
|
||||
group('rename()', () {
|
||||
test('renames branch', () {
|
||||
repo.renameBranch(oldName: 'feature', newName: 'renamed');
|
||||
final branch = repo.lookupBranch(name: 'renamed');
|
||||
final branches = repo.branches;
|
||||
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(
|
||||
() => repo.lookupBranch(name: 'feature'),
|
||||
() => Branch.lookup(repo: repo, name: 'feature'),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
expect(branch.target, featureCommit);
|
||||
|
@ -323,18 +333,23 @@ void main() {
|
|||
|
||||
test('throws when name already exists', () {
|
||||
expect(
|
||||
() => repo.renameBranch(oldName: 'feature', newName: 'master'),
|
||||
() => Branch.rename(
|
||||
repo: repo,
|
||||
oldName: 'feature',
|
||||
newName: 'master',
|
||||
),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
});
|
||||
|
||||
test('renames branch with force flag when name already exists', () {
|
||||
repo.renameBranch(
|
||||
Branch.rename(
|
||||
repo: repo,
|
||||
oldName: 'master',
|
||||
newName: 'feature',
|
||||
force: true,
|
||||
);
|
||||
final branch = repo.lookupBranch(name: 'feature');
|
||||
final branch = Branch.lookup(repo: repo, name: 'feature');
|
||||
|
||||
expect(branch.target, lastCommit);
|
||||
|
||||
|
@ -343,14 +358,18 @@ void main() {
|
|||
|
||||
test('throws when name is invalid', () {
|
||||
expect(
|
||||
() => repo.renameBranch(oldName: 'feature', newName: 'inv@{id'),
|
||||
() => Branch.rename(
|
||||
repo: repo,
|
||||
oldName: 'feature',
|
||||
newName: 'inv@{id',
|
||||
),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
test('returns string representation of Branch object', () {
|
||||
final branch = repo.lookupBranch(name: 'master');
|
||||
final branch = Branch.lookup(repo: repo, name: 'master');
|
||||
expect(branch.toString(), contains('Branch{'));
|
||||
branch.free();
|
||||
});
|
||||
|
|
|
@ -30,10 +30,7 @@ void main() {
|
|||
time: 124,
|
||||
);
|
||||
tip = repo['821ed6e80627b8769d170a293862f9fc60825226'];
|
||||
tree = Tree.lookup(
|
||||
repo: repo,
|
||||
oid: repo['a8ae3dd59e6e1802c6f78e05e301bfd57c9f334f'],
|
||||
);
|
||||
tree = Tree.lookup(repo: repo, oid: repo['a8ae3dd']);
|
||||
});
|
||||
|
||||
tearDown(() {
|
||||
|
@ -46,14 +43,14 @@ void main() {
|
|||
|
||||
group('Commit', () {
|
||||
test('lookups commit for provided oid', () {
|
||||
final commit = repo.lookupCommit(tip);
|
||||
final commit = Commit.lookup(repo: repo, oid: tip);
|
||||
expect(commit, isA<Commit>());
|
||||
commit.free();
|
||||
});
|
||||
|
||||
test('throws when trying to lookup with invalid oid', () {
|
||||
expect(
|
||||
() => repo.lookupCommit(repo['0' * 40]),
|
||||
() => Commit.lookup(repo: repo, oid: repo['0' * 40]),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
});
|
||||
|
@ -65,15 +62,14 @@ void main() {
|
|||
});
|
||||
|
||||
test('reverts commit affecting index and workdir', () {
|
||||
final commit = repo.lookupCommit(
|
||||
repo['821ed6e80627b8769d170a293862f9fc60825226'],
|
||||
);
|
||||
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(file.existsSync(), true);
|
||||
|
||||
repo.revert(commit);
|
||||
commit.revert();
|
||||
|
||||
expect(index.find('dir/dir_file.txt'), false);
|
||||
expect(file.existsSync(), false);
|
||||
|
||||
|
@ -82,22 +78,18 @@ void main() {
|
|||
});
|
||||
|
||||
test('throws when trying to revert and error occurs', () {
|
||||
expect(() => repo.revert(Commit(nullptr)), throwsA(isA<LibGit2Error>()));
|
||||
expect(() => Commit(nullptr).revert(), throwsA(isA<LibGit2Error>()));
|
||||
});
|
||||
|
||||
test('reverts commit to provided commit', () {
|
||||
final to = repo.lookupCommit(
|
||||
repo['78b8bf123e3952c970ae5c1ce0a3ea1d1336f6e8'],
|
||||
);
|
||||
final from = repo.lookupCommit(
|
||||
repo['821ed6e80627b8769d170a293862f9fc60825226'],
|
||||
);
|
||||
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(file.existsSync(), true);
|
||||
|
||||
final revertIndex = repo.revertCommit(revertCommit: from, ourCommit: to);
|
||||
final revertIndex = from.revertTo(commit: to);
|
||||
expect(revertIndex.find('dir/dir_file.txt'), false);
|
||||
expect(file.existsSync(), true);
|
||||
|
||||
|
@ -110,17 +102,15 @@ void main() {
|
|||
test('throws when trying to revert commit and error occurs', () {
|
||||
final nullCommit = Commit(nullptr);
|
||||
expect(
|
||||
() => repo.revertCommit(
|
||||
revertCommit: nullCommit,
|
||||
ourCommit: nullCommit,
|
||||
),
|
||||
() => nullCommit.revertTo(commit: nullCommit),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
});
|
||||
|
||||
test('creates commit', () {
|
||||
final parent = repo.lookupCommit(tip);
|
||||
final oid = repo.createCommit(
|
||||
final parent = Commit.lookup(repo: repo, oid: tip);
|
||||
final oid = Commit.create(
|
||||
repo: repo,
|
||||
updateRef: 'HEAD',
|
||||
message: message,
|
||||
author: author,
|
||||
|
@ -129,7 +119,7 @@ void main() {
|
|||
parents: [parent],
|
||||
);
|
||||
|
||||
final commit = repo.lookupCommit(oid);
|
||||
final commit = Commit.lookup(repo: repo, oid: oid);
|
||||
|
||||
expect(commit.oid, oid);
|
||||
expect(commit.message, message);
|
||||
|
@ -150,7 +140,7 @@ void main() {
|
|||
});
|
||||
|
||||
test('writes commit into the buffer', () {
|
||||
final parent = repo.lookupCommit(tip);
|
||||
final parent = Commit.lookup(repo: repo, oid: tip);
|
||||
final commit = Commit.createBuffer(
|
||||
repo: repo,
|
||||
updateRef: 'HEAD',
|
||||
|
@ -178,7 +168,8 @@ Some description.
|
|||
});
|
||||
|
||||
test('creates commit without parents', () {
|
||||
final oid = repo.createCommit(
|
||||
final oid = Commit.create(
|
||||
repo: repo,
|
||||
updateRef: 'refs/heads/new',
|
||||
message: message,
|
||||
author: author,
|
||||
|
@ -187,7 +178,7 @@ Some description.
|
|||
parents: [],
|
||||
);
|
||||
|
||||
final commit = repo.lookupCommit(oid);
|
||||
final commit = Commit.lookup(repo: repo, oid: oid);
|
||||
|
||||
expect(commit.oid, oid);
|
||||
expect(commit.message, message);
|
||||
|
@ -202,10 +193,8 @@ Some description.
|
|||
});
|
||||
|
||||
test('creates commit with 2 parents', () {
|
||||
final parent1 = repo.lookupCommit(tip);
|
||||
final parent2 = repo.lookupCommit(
|
||||
repo['fc38877b2552ab554752d9a77e1f48f738cca79b'],
|
||||
);
|
||||
final parent1 = Commit.lookup(repo: repo, oid: tip);
|
||||
final parent2 = Commit.lookup(repo: repo, oid: repo['fc38877']);
|
||||
|
||||
final oid = Commit.create(
|
||||
updateRef: 'HEAD',
|
||||
|
@ -217,7 +206,7 @@ Some description.
|
|||
parents: [parent1, parent2],
|
||||
);
|
||||
|
||||
final commit = repo.lookupCommit(oid);
|
||||
final commit = Commit.lookup(repo: repo, oid: oid);
|
||||
|
||||
expect(commit.oid, oid);
|
||||
expect(commit.message, message);
|
||||
|
@ -236,11 +225,12 @@ Some description.
|
|||
});
|
||||
|
||||
test('throws when trying to create commit and error occurs', () {
|
||||
final parent = repo.lookupCommit(tip);
|
||||
final parent = Commit.lookup(repo: repo, oid: tip);
|
||||
final nullRepo = Repository(nullptr);
|
||||
|
||||
expect(
|
||||
() => nullRepo.createCommit(
|
||||
() => Commit.create(
|
||||
repo: nullRepo,
|
||||
updateRef: 'HEAD',
|
||||
message: message,
|
||||
author: author,
|
||||
|
@ -256,7 +246,7 @@ Some description.
|
|||
|
||||
test('throws when trying to write commit into a buffer and error occurs',
|
||||
() {
|
||||
final parent = repo.lookupCommit(tip);
|
||||
final parent = Commit.lookup(repo: repo, oid: tip);
|
||||
final nullRepo = Repository(nullptr);
|
||||
|
||||
expect(
|
||||
|
@ -277,15 +267,16 @@ Some description.
|
|||
|
||||
test('amends commit with default arguments', () {
|
||||
final oldHead = repo.head;
|
||||
final commit = repo.lookupCommit(repo['821ed6e']);
|
||||
final commit = Commit.lookup(repo: repo, oid: repo['821ed6e']);
|
||||
expect(commit.oid, oldHead.target);
|
||||
|
||||
final amendedOid = repo.amendCommit(
|
||||
final amendedOid = Commit.amend(
|
||||
repo: repo,
|
||||
commit: commit,
|
||||
message: 'amended commit\n',
|
||||
updateRef: 'HEAD',
|
||||
);
|
||||
final amendedCommit = repo.lookupCommit(amendedOid);
|
||||
final amendedCommit = Commit.lookup(repo: repo, oid: amendedOid);
|
||||
final newHead = repo.head;
|
||||
|
||||
expect(amendedCommit.oid, newHead.target);
|
||||
|
@ -303,10 +294,11 @@ Some description.
|
|||
|
||||
test('amends commit with provided arguments', () {
|
||||
final oldHead = repo.head;
|
||||
final commit = repo.lookupCommit(repo['821ed6e']);
|
||||
final commit = Commit.lookup(repo: repo, oid: repo['821ed6e']);
|
||||
expect(commit.oid, oldHead.target);
|
||||
|
||||
final amendedOid = repo.amendCommit(
|
||||
final amendedOid = Commit.amend(
|
||||
repo: repo,
|
||||
commit: commit,
|
||||
message: 'amended commit\n',
|
||||
updateRef: 'HEAD',
|
||||
|
@ -314,7 +306,7 @@ Some description.
|
|||
committer: committer,
|
||||
tree: tree,
|
||||
);
|
||||
final amendedCommit = repo.lookupCommit(amendedOid);
|
||||
final amendedCommit = Commit.lookup(repo: repo, oid: amendedOid);
|
||||
final newHead = repo.head;
|
||||
|
||||
expect(amendedCommit.oid, newHead.target);
|
||||
|
@ -332,11 +324,12 @@ Some description.
|
|||
|
||||
test('amends commit that is not the tip of the branch', () {
|
||||
final head = repo.head;
|
||||
final commit = repo.lookupCommit(repo['78b8bf1']);
|
||||
final commit = Commit.lookup(repo: repo, oid: repo['78b8bf1']);
|
||||
expect(commit.oid, isNot(head.target));
|
||||
|
||||
expect(
|
||||
() => repo.amendCommit(
|
||||
() => Commit.amend(
|
||||
repo: repo,
|
||||
updateRef: null,
|
||||
commit: commit,
|
||||
message: 'amended commit\n',
|
||||
|
@ -352,11 +345,12 @@ Some description.
|
|||
'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 = repo.lookupCommit(repo['78b8bf1']);
|
||||
final commit = Commit.lookup(repo: repo, oid: repo['78b8bf1']);
|
||||
expect(commit.oid, isNot(head.target));
|
||||
|
||||
expect(
|
||||
() => repo.amendCommit(
|
||||
() => Commit.amend(
|
||||
repo: repo,
|
||||
commit: commit,
|
||||
message: 'amended commit\n',
|
||||
updateRef: 'HEAD',
|
||||
|
@ -369,7 +363,7 @@ Some description.
|
|||
});
|
||||
|
||||
test('creates an in-memory copy of a commit', () {
|
||||
final commit = repo.lookupCommit(tip);
|
||||
final commit = Commit.lookup(repo: repo, oid: tip);
|
||||
final dupCommit = commit.duplicate();
|
||||
|
||||
expect(dupCommit.oid, commit.oid);
|
||||
|
@ -379,7 +373,7 @@ Some description.
|
|||
});
|
||||
|
||||
test('returns header field', () {
|
||||
final commit = repo.lookupCommit(tip);
|
||||
final commit = Commit.lookup(repo: repo, oid: tip);
|
||||
expect(
|
||||
commit.headerField('parent'),
|
||||
'78b8bf123e3952c970ae5c1ce0a3ea1d1336f6e8',
|
||||
|
@ -388,7 +382,7 @@ Some description.
|
|||
});
|
||||
|
||||
test('throws when header field not found', () {
|
||||
final commit = repo.lookupCommit(tip);
|
||||
final commit = Commit.lookup(repo: repo, oid: tip);
|
||||
expect(
|
||||
() => commit.headerField('not-there'),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
|
@ -397,7 +391,7 @@ Some description.
|
|||
});
|
||||
|
||||
test('returns nth generation ancestor commit', () {
|
||||
final commit = repo.lookupCommit(tip);
|
||||
final commit = Commit.lookup(repo: repo, oid: tip);
|
||||
final ancestor = commit.nthGenAncestor(3);
|
||||
|
||||
expect(ancestor.oid.sha, 'f17d0d48eae3aa08cecf29128a35e310c97b3521');
|
||||
|
@ -408,15 +402,13 @@ Some description.
|
|||
|
||||
test('throws when trying to get nth generation ancestor and none exists',
|
||||
() {
|
||||
final commit = repo.lookupCommit(tip);
|
||||
final commit = Commit.lookup(repo: repo, oid: tip);
|
||||
expect(() => commit.nthGenAncestor(10), throwsA(isA<LibGit2Error>()));
|
||||
commit.free();
|
||||
});
|
||||
|
||||
test('returns parent at specified position', () {
|
||||
final commit = repo.lookupCommit(
|
||||
repo['78b8bf123e3952c970ae5c1ce0a3ea1d1336f6e8'],
|
||||
);
|
||||
final commit = Commit.lookup(repo: repo, oid: repo['78b8bf1']);
|
||||
final firstParent = commit.parent(0);
|
||||
final secondParent = commit.parent(1);
|
||||
|
||||
|
@ -429,13 +421,13 @@ Some description.
|
|||
});
|
||||
|
||||
test('throws when trying to get the parent at invalid position', () {
|
||||
final commit = repo.lookupCommit(tip);
|
||||
final commit = Commit.lookup(repo: repo, oid: tip);
|
||||
expect(() => commit.parent(10), throwsA(isA<LibGit2Error>()));
|
||||
commit.free();
|
||||
});
|
||||
|
||||
test('returns string representation of Commit object', () {
|
||||
final commit = repo.lookupCommit(tip);
|
||||
final commit = Commit.lookup(repo: repo, oid: tip);
|
||||
expect(commit.toString(), contains('Commit{'));
|
||||
commit.free();
|
||||
});
|
||||
|
|
|
@ -120,7 +120,7 @@ index e69de29..c217c63 100644
|
|||
group('Diff', () {
|
||||
test('returns diff between index and workdir', () {
|
||||
final index = repo.index;
|
||||
final diff = repo.diff();
|
||||
final diff = Diff.indexToWorkdir(repo: repo, index: index);
|
||||
|
||||
expect(diff.length, 8);
|
||||
for (var i = 0; i < diff.deltas.length; i++) {
|
||||
|
@ -134,34 +134,27 @@ index e69de29..c217c63 100644
|
|||
test('returns diff between index and tree', () {
|
||||
final index = repo.index;
|
||||
final head = repo.head;
|
||||
final commit = repo.lookupCommit(head.target);
|
||||
final commit = Commit.lookup(repo: repo, oid: head.target);
|
||||
final tree = commit.tree;
|
||||
final diff1 = index.diffToTree(tree: tree);
|
||||
final diff2 = tree.diffToIndex(index: index);
|
||||
final diff = Diff.treeToIndex(repo: repo, tree: tree, index: index);
|
||||
|
||||
expect(diff1.length, 8);
|
||||
for (var i = 0; i < diff1.deltas.length; i++) {
|
||||
expect(diff1.deltas[i].newFile.path, indexToTree[i]);
|
||||
}
|
||||
|
||||
expect(diff2.length, 8);
|
||||
for (var i = 0; i < diff2.deltas.length; i++) {
|
||||
expect(diff2.deltas[i].newFile.path, indexToTree[i]);
|
||||
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();
|
||||
diff1.free();
|
||||
diff2.free();
|
||||
diff.free();
|
||||
index.free();
|
||||
});
|
||||
|
||||
test('returns diff between tree and workdir', () {
|
||||
final head = repo.head;
|
||||
final commit = repo.lookupCommit(head.target);
|
||||
final commit = Commit.lookup(repo: repo, oid: head.target);
|
||||
final tree = commit.tree;
|
||||
final diff = repo.diff(a: tree);
|
||||
final diff = Diff.treeToWorkdir(repo: repo, tree: tree);
|
||||
|
||||
expect(diff.length, 9);
|
||||
for (var i = 0; i < diff.deltas.length; i++) {
|
||||
|
@ -176,65 +169,12 @@ index e69de29..c217c63 100644
|
|||
|
||||
test('throws when trying to diff between tree and workdir and error occurs',
|
||||
() {
|
||||
final nullRepo = Repository(nullptr);
|
||||
final nullTree = Tree(nullptr);
|
||||
expect(() => nullRepo.diff(a: nullTree), throwsA(isA<LibGit2Error>()));
|
||||
});
|
||||
|
||||
test('returns diff between tree and index', () {
|
||||
final index = repo.index;
|
||||
final head = repo.head;
|
||||
final commit = repo.lookupCommit(head.target);
|
||||
final tree = commit.tree;
|
||||
final diff = repo.diff(a: tree, cached: true);
|
||||
|
||||
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 tree and tree', () {
|
||||
final head = repo.head;
|
||||
final commit = repo.lookupCommit(head.target);
|
||||
final tree1 = commit.tree;
|
||||
final tree2 = repo.lookupTree(repo['b85d53c']);
|
||||
final diff = repo.diff(a: tree1, b: tree2);
|
||||
|
||||
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('throws when trying to diff between tree and tree and error occurs',
|
||||
() {
|
||||
final nullRepo = Repository(nullptr);
|
||||
final nullTree = Tree(nullptr);
|
||||
expect(
|
||||
() => nullRepo.diff(a: nullTree, b: nullTree),
|
||||
() => Diff.treeToWorkdir(repo: Repository(nullptr), tree: null),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
});
|
||||
|
||||
test('throws when trying to diff between null and tree', () {
|
||||
final tree = repo.lookupTree(repo['b85d53c']);
|
||||
expect(() => repo.diff(b: tree), throwsA(isA<ArgumentError>()));
|
||||
tree.free();
|
||||
});
|
||||
|
||||
test('returns diff between tree and workdir with index', () {
|
||||
final head = repo.head;
|
||||
final commit = repo.lookupCommit(head.target);
|
||||
|
@ -264,11 +204,54 @@ 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);
|
||||
|
||||
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('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,
|
||||
),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
});
|
||||
|
||||
test('throws when trying to diff between two null trees', () {
|
||||
expect(
|
||||
() => Diff.treeToTree(repo: repo, oldTree: null, newTree: null),
|
||||
throwsA(isA<ArgumentError>()),
|
||||
);
|
||||
});
|
||||
|
||||
test('returns diff between index and index', () {
|
||||
final index = repo.index;
|
||||
final emptyIndex = Index.newInMemory();
|
||||
|
||||
final diff = index.diffToIndex(index: emptyIndex);
|
||||
final diff = Diff.indexToIndex(
|
||||
repo: repo,
|
||||
oldIndex: index,
|
||||
newIndex: emptyIndex,
|
||||
);
|
||||
|
||||
expect(diff.length, 12);
|
||||
for (var i = 0; i < diff.deltas.length; i++) {
|
||||
|
@ -284,7 +267,11 @@ index e69de29..c217c63 100644
|
|||
final index = repo.index;
|
||||
|
||||
expect(
|
||||
() => index.diffToIndex(index: Index(nullptr)),
|
||||
() => Diff.indexToIndex(
|
||||
repo: repo,
|
||||
oldIndex: index,
|
||||
newIndex: Index(nullptr),
|
||||
),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
|
||||
|
@ -293,13 +280,11 @@ index e69de29..c217c63 100644
|
|||
|
||||
test('merges diffs', () {
|
||||
final head = repo.head;
|
||||
final commit = repo.lookupCommit(head.target);
|
||||
final commit = Commit.lookup(repo: repo, oid: head.target);
|
||||
final tree1 = commit.tree;
|
||||
final tree2 = repo.lookupTree(
|
||||
repo['b85d53c9236e89aff2b62558adaa885fd1d6ff1c'],
|
||||
);
|
||||
final diff1 = tree1.diffToTree(tree: tree2);
|
||||
final diff2 = tree1.diffToWorkdir();
|
||||
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);
|
||||
|
||||
expect(diff1.length, 10);
|
||||
expect(diff2.length, 9);
|
||||
|
@ -330,28 +315,31 @@ index e69de29..c217c63 100644
|
|||
|
||||
group('apply', () {
|
||||
test('checks if diff can be applied to repository', () {
|
||||
final diff1 = repo.diff();
|
||||
final index = repo.index;
|
||||
final diff1 = Diff.indexToWorkdir(repo: repo, index: index);
|
||||
expect(
|
||||
repo.applies(diff: diff1, location: GitApplyLocation.both),
|
||||
diff1.applies(repo: repo, location: GitApplyLocation.both),
|
||||
false,
|
||||
);
|
||||
|
||||
final diff2 = Diff.parse(patchText);
|
||||
repo.checkout(target: 'HEAD', strategy: {GitCheckout.force});
|
||||
expect(
|
||||
repo.applies(diff: diff2, location: GitApplyLocation.both),
|
||||
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 diff1 = repo.diff();
|
||||
final index = repo.index;
|
||||
final diff1 = Diff.indexToWorkdir(repo: repo, index: index);
|
||||
expect(
|
||||
repo.applies(diff: diff1, location: GitApplyLocation.both),
|
||||
diff1.applies(repo: repo, location: GitApplyLocation.both),
|
||||
false,
|
||||
);
|
||||
|
||||
|
@ -359,8 +347,8 @@ index e69de29..c217c63 100644
|
|||
final hunk = diff2.patches.first.hunks.first;
|
||||
repo.checkout(target: 'HEAD', strategy: {GitCheckout.force});
|
||||
expect(
|
||||
repo.applies(
|
||||
diff: diff2,
|
||||
diff2.applies(
|
||||
repo: repo,
|
||||
hunkIndex: hunk.index,
|
||||
location: GitApplyLocation.both,
|
||||
),
|
||||
|
@ -369,6 +357,7 @@ index e69de29..c217c63 100644
|
|||
|
||||
diff1.free();
|
||||
diff2.free();
|
||||
index.free();
|
||||
});
|
||||
|
||||
test('applies diff to repository', () {
|
||||
|
@ -378,15 +367,17 @@ index e69de29..c217c63 100644
|
|||
repo.checkout(target: 'HEAD', strategy: {GitCheckout.force});
|
||||
expect(file.readAsStringSync(), '');
|
||||
|
||||
repo.apply(diff: diff);
|
||||
diff.apply(repo: repo);
|
||||
expect(file.readAsStringSync(), 'Modified content\n');
|
||||
|
||||
diff.free();
|
||||
});
|
||||
|
||||
test('throws when trying to apply diff and error occurs', () {
|
||||
final nullDiff = Diff(nullptr);
|
||||
expect(() => repo.apply(diff: nullDiff), throwsA(isA<LibGit2Error>()));
|
||||
expect(
|
||||
() => Diff(nullptr).apply(repo: repo),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
});
|
||||
|
||||
test('creates patch from entry index in diff', () {
|
||||
|
@ -408,7 +399,7 @@ index e69de29..c217c63 100644
|
|||
repo.checkout(target: 'HEAD', strategy: {GitCheckout.force});
|
||||
expect(file.readAsStringSync(), '');
|
||||
|
||||
repo.apply(diff: diff, hunkIndex: hunk.index);
|
||||
diff.apply(repo: repo, hunkIndex: hunk.index);
|
||||
expect(file.readAsStringSync(), 'Modified content\n');
|
||||
|
||||
diff.free();
|
||||
|
@ -419,15 +410,21 @@ index e69de29..c217c63 100644
|
|||
|
||||
repo.checkout(target: 'HEAD', strategy: {GitCheckout.force});
|
||||
final head = repo.head;
|
||||
final commit = repo.lookupCommit(head.target);
|
||||
final commit = Commit.lookup(repo: repo, oid: head.target);
|
||||
final tree = commit.tree;
|
||||
|
||||
final oldIndex = repo.index;
|
||||
final oldBlob = repo.lookupBlob(oldIndex['subdir/modified_file'].oid);
|
||||
final oldBlob = Blob.lookup(
|
||||
repo: repo,
|
||||
oid: oldIndex['subdir/modified_file'].oid,
|
||||
);
|
||||
expect(oldBlob.content, '');
|
||||
|
||||
final newIndex = repo.applyToTree(diff: diff, tree: tree);
|
||||
final newBlob = repo.lookupBlob(newIndex['subdir/modified_file'].oid);
|
||||
final newIndex = diff.applyToTree(repo: repo, tree: tree);
|
||||
final newBlob = Blob.lookup(
|
||||
repo: repo,
|
||||
oid: newIndex['subdir/modified_file'].oid,
|
||||
);
|
||||
expect(newBlob.content, 'Modified content\n');
|
||||
|
||||
oldBlob.free();
|
||||
|
@ -446,19 +443,25 @@ index e69de29..c217c63 100644
|
|||
|
||||
repo.checkout(target: 'HEAD', strategy: {GitCheckout.force});
|
||||
final head = repo.head;
|
||||
final commit = repo.lookupCommit(head.target);
|
||||
final commit = Commit.lookup(repo: repo, oid: head.target);
|
||||
final tree = commit.tree;
|
||||
|
||||
final oldIndex = repo.index;
|
||||
final oldBlob = repo.lookupBlob(oldIndex['subdir/modified_file'].oid);
|
||||
final oldBlob = Blob.lookup(
|
||||
repo: repo,
|
||||
oid: oldIndex['subdir/modified_file'].oid,
|
||||
);
|
||||
expect(oldBlob.content, '');
|
||||
|
||||
final newIndex = repo.applyToTree(
|
||||
diff: diff,
|
||||
final newIndex = diff.applyToTree(
|
||||
repo: repo,
|
||||
tree: tree,
|
||||
hunkIndex: hunk.index,
|
||||
);
|
||||
final newBlob = repo.lookupBlob(newIndex['subdir/modified_file'].oid);
|
||||
final newBlob = Blob.lookup(
|
||||
repo: repo,
|
||||
oid: newIndex['subdir/modified_file'].oid,
|
||||
);
|
||||
expect(newBlob.content, 'Modified content\n');
|
||||
|
||||
oldBlob.free();
|
||||
|
@ -474,7 +477,7 @@ index e69de29..c217c63 100644
|
|||
test('throws when trying to apply diff to tree and error occurs', () {
|
||||
final diff = Diff.parse(patchText);
|
||||
expect(
|
||||
() => repo.applyToTree(diff: diff, tree: Tree(nullptr)),
|
||||
() => diff.applyToTree(repo: repo, tree: Tree(nullptr)),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
});
|
||||
|
@ -483,11 +486,15 @@ index e69de29..c217c63 100644
|
|||
test('finds similar entries', () {
|
||||
final index = repo.index;
|
||||
final head = repo.head;
|
||||
final commit = repo.lookupCommit(head.target);
|
||||
final commit = Commit.lookup(repo: repo, oid: head.target);
|
||||
final oldTree = commit.tree;
|
||||
final newTree = repo.lookupTree(index.writeTree());
|
||||
final newTree = Tree.lookup(repo: repo, oid: index.writeTree());
|
||||
|
||||
final diff = oldTree.diffToTree(tree: newTree);
|
||||
final diff = Diff.treeToTree(
|
||||
repo: repo,
|
||||
oldTree: oldTree,
|
||||
newTree: newTree,
|
||||
);
|
||||
expect(
|
||||
diff.deltas.singleWhere((e) => e.newFile.path == 'staged_new').status,
|
||||
GitDelta.added,
|
||||
|
@ -519,7 +526,7 @@ index e69de29..c217c63 100644
|
|||
|
||||
test('returns deltas', () {
|
||||
final index = repo.index;
|
||||
final diff = index.diffToWorkdir();
|
||||
final diff = Diff.indexToWorkdir(repo: repo, index: index);
|
||||
|
||||
expect(diff.deltas[0].numberOfFiles, 1);
|
||||
expect(diff.deltas[0].status, GitDelta.deleted);
|
||||
|
@ -553,7 +560,7 @@ index e69de29..c217c63 100644
|
|||
|
||||
test('throws when trying to get delta with invalid index', () {
|
||||
final index = repo.index;
|
||||
final diff = index.diffToWorkdir();
|
||||
final diff = Diff.indexToWorkdir(repo: repo, index: index);
|
||||
|
||||
expect(() => diff.deltas[-1], throwsA(isA<RangeError>()));
|
||||
|
||||
|
@ -563,7 +570,7 @@ index e69de29..c217c63 100644
|
|||
|
||||
test('returns patches', () {
|
||||
final index = repo.index;
|
||||
final diff = index.diffToWorkdir();
|
||||
final diff = Diff.indexToWorkdir(repo: repo, index: index);
|
||||
final patches = diff.patches;
|
||||
|
||||
expect(patches.length, 8);
|
||||
|
@ -578,7 +585,7 @@ index e69de29..c217c63 100644
|
|||
|
||||
test('returns stats', () {
|
||||
final index = repo.index;
|
||||
final diff = index.diffToWorkdir();
|
||||
final diff = Diff.indexToWorkdir(repo: repo, index: index);
|
||||
final stats = diff.stats;
|
||||
|
||||
expect(stats.insertions, 4);
|
||||
|
|
|
@ -35,7 +35,7 @@ void main() {
|
|||
|
||||
group('Note', () {
|
||||
test('returns list of notes', () {
|
||||
final notes = repo.notes;
|
||||
final notes = Note.list(repo);
|
||||
|
||||
expect(notes.length, 2);
|
||||
|
||||
|
@ -49,12 +49,12 @@ void main() {
|
|||
|
||||
test('throws when trying to get list of notes and error occurs', () {
|
||||
Directory(p.join(repo.path, 'refs', 'notes')).deleteSync(recursive: true);
|
||||
expect(() => repo.notes, throwsA(isA<LibGit2Error>()));
|
||||
expect(() => Note.list(repo), throwsA(isA<LibGit2Error>()));
|
||||
});
|
||||
|
||||
test('lookups note', () {
|
||||
final head = repo.head;
|
||||
final note = repo.lookupNote(annotatedOid: head.target);
|
||||
final note = Note.lookup(repo: repo, annotatedOid: head.target);
|
||||
|
||||
expect(note.oid.sha, notesExpected[1]['oid']);
|
||||
expect(note.message, notesExpected[1]['message']);
|
||||
|
@ -71,14 +71,15 @@ void main() {
|
|||
time: 1234,
|
||||
);
|
||||
final head = repo.head;
|
||||
final noteOid = repo.createNote(
|
||||
final noteOid = Note.create(
|
||||
repo: repo,
|
||||
author: signature,
|
||||
committer: signature,
|
||||
annotatedOid: head.target,
|
||||
note: 'New note for HEAD',
|
||||
force: true,
|
||||
);
|
||||
final noteBlob = repo.lookupBlob(noteOid);
|
||||
final noteBlob = Blob.lookup(repo: repo, oid: noteOid);
|
||||
|
||||
expect(noteOid.sha, 'ffd6e2ceaf91c00ea6d29e2e897f906da720529f');
|
||||
expect(noteBlob.content, 'New note for HEAD');
|
||||
|
@ -90,7 +91,8 @@ void main() {
|
|||
|
||||
test('throws when trying to create note and error occurs', () {
|
||||
expect(
|
||||
() => Repository(nullptr).createNote(
|
||||
() => Note.create(
|
||||
repo: Repository(nullptr),
|
||||
author: Signature(nullptr),
|
||||
committer: Signature(nullptr),
|
||||
annotatedOid: repo['0' * 40],
|
||||
|
@ -108,14 +110,15 @@ void main() {
|
|||
);
|
||||
final head = repo.head;
|
||||
|
||||
repo.deleteNote(
|
||||
Note.delete(
|
||||
repo: repo,
|
||||
annotatedOid: repo.head.target,
|
||||
author: signature,
|
||||
committer: signature,
|
||||
);
|
||||
|
||||
expect(
|
||||
() => repo.lookupNote(annotatedOid: head.target),
|
||||
() => Note.lookup(repo: repo, annotatedOid: head.target),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
|
||||
|
@ -125,7 +128,8 @@ void main() {
|
|||
|
||||
test('throws when trying to delete note and error occurs', () {
|
||||
expect(
|
||||
() => Repository(nullptr).deleteNote(
|
||||
() => Note.delete(
|
||||
repo: Repository(nullptr),
|
||||
author: Signature(nullptr),
|
||||
committer: Signature(nullptr),
|
||||
annotatedOid: repo['0' * 40],
|
||||
|
@ -135,7 +139,7 @@ void main() {
|
|||
});
|
||||
|
||||
test('returns string representation of Note object', () {
|
||||
final note = repo.lookupNote(annotatedOid: repo['821ed6e']);
|
||||
final note = Note.lookup(repo: repo, annotatedOid: repo['821ed6e']);
|
||||
expect(note.toString(), contains('Note{'));
|
||||
note.free();
|
||||
});
|
||||
|
|
|
@ -188,10 +188,14 @@ void main() {
|
|||
|
||||
test('packs with provided packDelegate', () {
|
||||
Directory(packDirPath).createSync();
|
||||
|
||||
void packDelegate(PackBuilder packBuilder) {
|
||||
final branches = repo.branchesLocal;
|
||||
for (final branch in branches) {
|
||||
final ref = repo.lookupReference('refs/heads/${branch.name}');
|
||||
final ref = Reference.lookup(
|
||||
repo: repo,
|
||||
name: 'refs/heads/${branch.name}',
|
||||
);
|
||||
for (final commit in repo.log(oid: ref.target)) {
|
||||
packBuilder.addRecursively(commit.oid);
|
||||
commit.free();
|
||||
|
|
|
@ -96,8 +96,8 @@ index e69de29..0000000
|
|||
});
|
||||
|
||||
test('creates from blobs', () {
|
||||
final a = repo.lookupBlob(oldBlobOid);
|
||||
final b = repo.lookupBlob(newBlobOid);
|
||||
final a = Blob.lookup(repo: repo, oid: oldBlobOid);
|
||||
final b = Blob.lookup(repo: repo, oid: newBlobOid);
|
||||
final patch = Patch.create(
|
||||
a: a,
|
||||
b: b,
|
||||
|
@ -111,7 +111,7 @@ index e69de29..0000000
|
|||
});
|
||||
|
||||
test('creates from one blob (add)', () {
|
||||
final b = repo.lookupBlob(newBlobOid);
|
||||
final b = Blob.lookup(repo: repo, oid: newBlobOid);
|
||||
final patch = Patch.create(
|
||||
a: null,
|
||||
b: b,
|
||||
|
@ -125,7 +125,7 @@ index e69de29..0000000
|
|||
});
|
||||
|
||||
test('creates from one blob (delete)', () {
|
||||
final a = repo.lookupBlob(oldBlobOid);
|
||||
final a = Blob.lookup(repo: repo, oid: oldBlobOid);
|
||||
final patch = Patch.create(
|
||||
a: a,
|
||||
b: null,
|
||||
|
@ -139,7 +139,7 @@ index e69de29..0000000
|
|||
});
|
||||
|
||||
test('creates from blob and buffer', () {
|
||||
final a = repo.lookupBlob(oldBlobOid);
|
||||
final a = Blob.lookup(repo: repo, oid: oldBlobOid);
|
||||
final patch = Patch.create(
|
||||
a: a,
|
||||
b: newBlob,
|
||||
|
@ -153,9 +153,8 @@ index e69de29..0000000
|
|||
});
|
||||
|
||||
test('throws when argument is not Blob or String', () {
|
||||
final commit = repo.lookupCommit(
|
||||
repo['fc38877b2552ab554752d9a77e1f48f738cca79b'],
|
||||
);
|
||||
final commit = Commit.lookup(repo: repo, oid: repo['fc38877']);
|
||||
|
||||
expect(
|
||||
() => Patch.create(
|
||||
a: commit,
|
||||
|
|
|
@ -32,12 +32,12 @@ void main() {
|
|||
email: 'author@email.com',
|
||||
time: 1234,
|
||||
);
|
||||
final master = repo.lookupReference('refs/heads/master');
|
||||
final master = Reference.lookup(repo: repo, name: 'refs/heads/master');
|
||||
final branchHead = AnnotatedCommit.fromReference(
|
||||
repo: repo,
|
||||
reference: master,
|
||||
);
|
||||
final feature = repo.lookupReference('refs/heads/feature');
|
||||
final feature = Reference.lookup(repo: repo, name: 'refs/heads/feature');
|
||||
final ontoHead = AnnotatedCommit.fromReference(
|
||||
repo: repo,
|
||||
reference: feature,
|
||||
|
@ -90,7 +90,7 @@ void main() {
|
|||
email: 'author@email.com',
|
||||
time: 1234,
|
||||
);
|
||||
final feature = repo.lookupReference('refs/heads/feature');
|
||||
final feature = Reference.lookup(repo: repo, name: 'refs/heads/feature');
|
||||
final ontoHead = AnnotatedCommit.lookup(repo: repo, oid: feature.target);
|
||||
|
||||
final rebase = Rebase.init(
|
||||
|
@ -136,9 +136,9 @@ void main() {
|
|||
email: 'author@email.com',
|
||||
time: 1234,
|
||||
);
|
||||
final master = repo.lookupReference('refs/heads/master');
|
||||
final master = Reference.lookup(repo: repo, name: 'refs/heads/master');
|
||||
final branchHead = AnnotatedCommit.lookup(repo: repo, oid: master.target);
|
||||
final feature = repo.lookupReference('refs/heads/feature');
|
||||
final feature = Reference.lookup(repo: repo, name: 'refs/heads/feature');
|
||||
final upstream = AnnotatedCommit.lookup(repo: repo, oid: repo[shas[1]]);
|
||||
|
||||
repo.checkout(target: feature.name);
|
||||
|
@ -189,9 +189,12 @@ void main() {
|
|||
email: 'author@email.com',
|
||||
time: 1234,
|
||||
);
|
||||
final master = repo.lookupReference('refs/heads/master');
|
||||
final master = Reference.lookup(repo: repo, name: 'refs/heads/master');
|
||||
final branchHead = AnnotatedCommit.lookup(repo: repo, oid: master.target);
|
||||
final conflict = repo.lookupReference('refs/heads/conflict-branch');
|
||||
final conflict = Reference.lookup(
|
||||
repo: repo,
|
||||
name: 'refs/heads/conflict-branch',
|
||||
);
|
||||
final ontoHead = AnnotatedCommit.lookup(repo: repo, oid: conflict.target);
|
||||
|
||||
repo.checkout(target: conflict.name);
|
||||
|
@ -226,9 +229,12 @@ void main() {
|
|||
email: 'author@email.com',
|
||||
time: 1234,
|
||||
);
|
||||
final master = repo.lookupReference('refs/heads/master');
|
||||
final master = Reference.lookup(repo: repo, name: 'refs/heads/master');
|
||||
final branchHead = AnnotatedCommit.lookup(repo: repo, oid: master.target);
|
||||
final conflict = repo.lookupReference('refs/heads/conflict-branch');
|
||||
final conflict = Reference.lookup(
|
||||
repo: repo,
|
||||
name: 'refs/heads/conflict-branch',
|
||||
);
|
||||
final ontoHead = AnnotatedCommit.lookup(repo: repo, oid: conflict.target);
|
||||
|
||||
repo.checkout(target: conflict.name);
|
||||
|
@ -252,9 +258,12 @@ void main() {
|
|||
});
|
||||
|
||||
test('aborts rebase in progress', () {
|
||||
final master = repo.lookupReference('refs/heads/master');
|
||||
final master = Reference.lookup(repo: repo, name: 'refs/heads/master');
|
||||
final branchHead = AnnotatedCommit.lookup(repo: repo, oid: master.target);
|
||||
final conflict = repo.lookupReference('refs/heads/conflict-branch');
|
||||
final conflict = Reference.lookup(
|
||||
repo: repo,
|
||||
name: 'refs/heads/conflict-branch',
|
||||
);
|
||||
final ontoHead = AnnotatedCommit.lookup(repo: repo, oid: conflict.target);
|
||||
|
||||
repo.checkout(target: conflict.name);
|
||||
|
@ -282,7 +291,7 @@ void main() {
|
|||
});
|
||||
|
||||
test('opens an existing rebase', () {
|
||||
final feature = repo.lookupReference('refs/heads/feature');
|
||||
final feature = Reference.lookup(repo: repo, name: 'refs/heads/feature');
|
||||
final ontoHead = AnnotatedCommit.lookup(repo: repo, oid: feature.target);
|
||||
|
||||
final rebase = Rebase.init(
|
||||
|
|
|
@ -26,7 +26,7 @@ void main() {
|
|||
group('Reference', () {
|
||||
test('returns a list', () {
|
||||
expect(
|
||||
repo.references,
|
||||
Reference.list(repo),
|
||||
[
|
||||
'refs/heads/feature',
|
||||
'refs/heads/master',
|
||||
|
@ -40,7 +40,7 @@ void main() {
|
|||
|
||||
test('throws when trying to get a list of references and error occurs', () {
|
||||
expect(
|
||||
() => Repository(nullptr).references,
|
||||
() => Reference.list(Repository(nullptr)),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
});
|
||||
|
@ -50,7 +50,7 @@ void main() {
|
|||
expect(head.type, ReferenceType.direct);
|
||||
head.free();
|
||||
|
||||
final ref = repo.lookupReference('HEAD');
|
||||
final ref = Reference.lookup(repo: repo, name: 'HEAD');
|
||||
expect(ref.type, ReferenceType.symbolic);
|
||||
ref.free();
|
||||
});
|
||||
|
@ -62,7 +62,7 @@ void main() {
|
|||
});
|
||||
|
||||
test('returns SHA hex of symbolic reference', () {
|
||||
final ref = repo.lookupReference('HEAD');
|
||||
final ref = Reference.lookup(repo: repo, name: 'HEAD');
|
||||
expect(ref.target.sha, lastCommit);
|
||||
ref.free();
|
||||
});
|
||||
|
@ -81,7 +81,8 @@ void main() {
|
|||
});
|
||||
|
||||
test('returns the short name', () {
|
||||
final ref = repo.createReference(
|
||||
final ref = Reference.create(
|
||||
repo: repo,
|
||||
name: 'refs/remotes/origin/upstream',
|
||||
target: repo[lastCommit],
|
||||
);
|
||||
|
@ -96,34 +97,37 @@ void main() {
|
|||
});
|
||||
|
||||
test('checks if reference is a local branch', () {
|
||||
final ref = repo.lookupReference('refs/heads/feature');
|
||||
final ref = Reference.lookup(repo: repo, name: 'refs/heads/feature');
|
||||
expect(ref.isBranch, true);
|
||||
ref.free();
|
||||
});
|
||||
|
||||
test('checks if reference is a note', () {
|
||||
final ref = repo.lookupReference('refs/heads/master');
|
||||
final ref = Reference.lookup(repo: repo, name: 'refs/heads/master');
|
||||
expect(ref.isNote, false);
|
||||
ref.free();
|
||||
});
|
||||
|
||||
test('checks if reference is a remote branch', () {
|
||||
final ref = repo.lookupReference('refs/remotes/origin/master');
|
||||
final ref = Reference.lookup(
|
||||
repo: repo,
|
||||
name: 'refs/remotes/origin/master',
|
||||
);
|
||||
expect(ref.isRemote, true);
|
||||
ref.free();
|
||||
});
|
||||
|
||||
test('checks if reference is a tag', () {
|
||||
final ref = repo.lookupReference('refs/tags/v0.1');
|
||||
final ref = Reference.lookup(repo: repo, name: 'refs/tags/v0.1');
|
||||
expect(ref.isTag, true);
|
||||
ref.free();
|
||||
});
|
||||
|
||||
test('checks if reflog exists for the reference', () {
|
||||
var ref = repo.lookupReference('refs/heads/master');
|
||||
var ref = Reference.lookup(repo: repo, name: 'refs/heads/master');
|
||||
expect(ref.hasLog, true);
|
||||
|
||||
ref = repo.lookupReference('refs/tags/v0.1');
|
||||
ref = Reference.lookup(repo: repo, name: 'refs/tags/v0.1');
|
||||
expect(ref.hasLog, false);
|
||||
|
||||
ref.free();
|
||||
|
@ -132,7 +136,8 @@ void main() {
|
|||
test('ensures updates to the reference will append to its log', () {
|
||||
Reference.ensureLog(repo: repo, refName: 'refs/tags/tag');
|
||||
|
||||
final ref = repo.createReference(
|
||||
final ref = Reference.create(
|
||||
repo: repo,
|
||||
name: 'refs/tags/tag',
|
||||
target: repo[lastCommit],
|
||||
);
|
||||
|
@ -157,7 +162,7 @@ void main() {
|
|||
test('duplicates existing reference', () {
|
||||
expect(repo.references.length, 6);
|
||||
|
||||
final ref = repo.lookupReference('refs/heads/master');
|
||||
final ref = Reference.lookup(repo: repo, name: 'refs/heads/master');
|
||||
final duplicate = ref.duplicate();
|
||||
|
||||
expect(repo.references.length, 6);
|
||||
|
@ -169,8 +174,9 @@ void main() {
|
|||
|
||||
group('create direct', () {
|
||||
test('creates with oid as target', () {
|
||||
final ref = repo.lookupReference('refs/heads/master');
|
||||
final refFromOid = repo.createReference(
|
||||
final ref = Reference.lookup(repo: repo, name: 'refs/heads/master');
|
||||
final refFromOid = Reference.create(
|
||||
repo: repo,
|
||||
name: 'refs/tags/from.oid',
|
||||
target: ref.target,
|
||||
);
|
||||
|
@ -183,7 +189,8 @@ void main() {
|
|||
|
||||
test('creates with log message', () {
|
||||
repo.setIdentity(name: 'name', email: 'email');
|
||||
final ref = repo.createReference(
|
||||
final ref = Reference.create(
|
||||
repo: repo,
|
||||
name: 'refs/heads/log.message',
|
||||
target: repo[lastCommit],
|
||||
logMessage: 'log message',
|
||||
|
@ -202,7 +209,8 @@ void main() {
|
|||
|
||||
test('throws if target is not valid', () {
|
||||
expect(
|
||||
() => repo.createReference(
|
||||
() => Reference.create(
|
||||
repo: repo,
|
||||
name: 'refs/tags/invalid',
|
||||
target: '78b',
|
||||
),
|
||||
|
@ -210,7 +218,8 @@ void main() {
|
|||
);
|
||||
|
||||
expect(
|
||||
() => repo.createReference(
|
||||
() => Reference.create(
|
||||
repo: repo,
|
||||
name: 'refs/tags/invalid',
|
||||
target: 0,
|
||||
),
|
||||
|
@ -220,7 +229,8 @@ void main() {
|
|||
|
||||
test('throws if name is not valid', () {
|
||||
expect(
|
||||
() => repo.createReference(
|
||||
() => Reference.create(
|
||||
repo: repo,
|
||||
name: 'refs/tags/invalid~',
|
||||
target: repo[lastCommit],
|
||||
),
|
||||
|
@ -229,12 +239,14 @@ void main() {
|
|||
});
|
||||
|
||||
test('creates with force flag if name already exists', () {
|
||||
final ref = repo.createReference(
|
||||
final ref = Reference.create(
|
||||
repo: repo,
|
||||
name: 'refs/tags/test',
|
||||
target: repo[lastCommit],
|
||||
);
|
||||
|
||||
final forceRef = repo.createReference(
|
||||
final forceRef = Reference.create(
|
||||
repo: repo,
|
||||
name: 'refs/tags/test',
|
||||
target: repo[lastCommit],
|
||||
force: true,
|
||||
|
@ -247,13 +259,15 @@ void main() {
|
|||
});
|
||||
|
||||
test('throws if name already exists', () {
|
||||
final ref = repo.createReference(
|
||||
final ref = Reference.create(
|
||||
repo: repo,
|
||||
name: 'refs/tags/test',
|
||||
target: repo[lastCommit],
|
||||
);
|
||||
|
||||
expect(
|
||||
() => repo.createReference(
|
||||
() => Reference.create(
|
||||
repo: repo,
|
||||
name: 'refs/tags/test',
|
||||
target: repo[lastCommit],
|
||||
),
|
||||
|
@ -266,7 +280,8 @@ void main() {
|
|||
|
||||
group('create symbolic', () {
|
||||
test('creates with valid target', () {
|
||||
final ref = repo.createReference(
|
||||
final ref = Reference.create(
|
||||
repo: repo,
|
||||
name: 'refs/tags/symbolic',
|
||||
target: 'refs/heads/master',
|
||||
);
|
||||
|
@ -278,12 +293,14 @@ void main() {
|
|||
});
|
||||
|
||||
test('creates with force flag if name already exists', () {
|
||||
final ref = repo.createReference(
|
||||
final ref = Reference.create(
|
||||
repo: repo,
|
||||
name: 'refs/tags/test',
|
||||
target: 'refs/heads/master',
|
||||
);
|
||||
|
||||
final forceRef = repo.createReference(
|
||||
final forceRef = Reference.create(
|
||||
repo: repo,
|
||||
name: 'refs/tags/test',
|
||||
target: 'refs/heads/master',
|
||||
force: true,
|
||||
|
@ -297,13 +314,15 @@ void main() {
|
|||
});
|
||||
|
||||
test('throws if name already exists', () {
|
||||
final ref = repo.createReference(
|
||||
final ref = Reference.create(
|
||||
repo: repo,
|
||||
name: 'refs/tags/exists',
|
||||
target: 'refs/heads/master',
|
||||
);
|
||||
|
||||
expect(
|
||||
() => repo.createReference(
|
||||
() => Reference.create(
|
||||
repo: repo,
|
||||
name: 'refs/tags/exists',
|
||||
target: 'refs/heads/master',
|
||||
),
|
||||
|
@ -315,7 +334,8 @@ void main() {
|
|||
|
||||
test('throws if name is not valid', () {
|
||||
expect(
|
||||
() => repo.createReference(
|
||||
() => Reference.create(
|
||||
repo: repo,
|
||||
name: 'refs/tags/invalid~',
|
||||
target: 'refs/heads/master',
|
||||
),
|
||||
|
@ -325,7 +345,8 @@ void main() {
|
|||
|
||||
test('creates with log message', () {
|
||||
repo.setIdentity(name: 'name', email: 'email');
|
||||
final ref = repo.createReference(
|
||||
final ref = Reference.create(
|
||||
repo: repo,
|
||||
name: 'HEAD',
|
||||
target: 'refs/heads/feature',
|
||||
force: true,
|
||||
|
@ -347,27 +368,27 @@ void main() {
|
|||
test('deletes reference', () {
|
||||
expect(repo.references, contains('refs/tags/v0.1'));
|
||||
|
||||
repo.deleteReference('refs/tags/v0.1');
|
||||
Reference.delete(repo: repo, name: 'refs/tags/v0.1');
|
||||
expect(repo.references, isNot(contains('refs/tags/v0.1')));
|
||||
});
|
||||
|
||||
group('finds', () {
|
||||
test('with provided name', () {
|
||||
final ref = repo.lookupReference('refs/heads/master');
|
||||
final ref = Reference.lookup(repo: repo, name: 'refs/heads/master');
|
||||
expect(ref.target.sha, lastCommit);
|
||||
ref.free();
|
||||
});
|
||||
|
||||
test('throws when error occured', () {
|
||||
expect(
|
||||
() => repo.lookupReference('refs/heads/not/there'),
|
||||
() => Reference.lookup(repo: repo, name: 'refs/heads/not/there'),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
test('returns log for reference', () {
|
||||
final ref = repo.lookupReference('refs/heads/master');
|
||||
final ref = Reference.lookup(repo: repo, name: 'refs/heads/master');
|
||||
final reflog = ref.log;
|
||||
expect(reflog.last.message, 'commit (initial): init');
|
||||
|
||||
|
@ -377,7 +398,7 @@ void main() {
|
|||
|
||||
group('set target', () {
|
||||
test('sets direct reference with provided oid target', () {
|
||||
final ref = repo.lookupReference('refs/heads/master');
|
||||
final ref = Reference.lookup(repo: repo, name: 'refs/heads/master');
|
||||
ref.setTarget(target: repo[newCommit]);
|
||||
expect(ref.target.sha, newCommit);
|
||||
|
||||
|
@ -385,7 +406,7 @@ void main() {
|
|||
});
|
||||
|
||||
test('sets symbolic target with provided reference name', () {
|
||||
final ref = repo.lookupReference('HEAD');
|
||||
final ref = Reference.lookup(repo: repo, name: 'HEAD');
|
||||
expect(ref.target.sha, lastCommit);
|
||||
|
||||
ref.setTarget(target: 'refs/heads/feature');
|
||||
|
@ -395,7 +416,7 @@ void main() {
|
|||
});
|
||||
|
||||
test('sets target with log message', () {
|
||||
final ref = repo.lookupReference('HEAD');
|
||||
final ref = Reference.lookup(repo: repo, name: 'HEAD');
|
||||
expect(ref.target.sha, lastCommit);
|
||||
|
||||
repo.setIdentity(name: 'name', email: 'email');
|
||||
|
@ -411,7 +432,7 @@ void main() {
|
|||
});
|
||||
|
||||
test('throws on invalid target', () {
|
||||
final ref = repo.lookupReference('HEAD');
|
||||
final ref = Reference.lookup(repo: repo, name: 'HEAD');
|
||||
expect(
|
||||
() => ref.setTarget(target: 'refs/heads/invalid~'),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
|
@ -430,7 +451,8 @@ void main() {
|
|||
|
||||
group('rename', () {
|
||||
test('renames reference', () {
|
||||
repo.renameReference(
|
||||
Reference.rename(
|
||||
repo: repo,
|
||||
oldName: 'refs/tags/v0.1',
|
||||
newName: 'refs/tags/renamed',
|
||||
);
|
||||
|
@ -441,7 +463,8 @@ void main() {
|
|||
|
||||
test('throws on invalid name', () {
|
||||
expect(
|
||||
() => repo.renameReference(
|
||||
() => Reference.rename(
|
||||
repo: repo,
|
||||
oldName: 'refs/tags/v0.1',
|
||||
newName: 'refs/tags/invalid~',
|
||||
),
|
||||
|
@ -451,7 +474,8 @@ void main() {
|
|||
|
||||
test('throws if name already exists', () {
|
||||
expect(
|
||||
() => repo.renameReference(
|
||||
() => Reference.rename(
|
||||
repo: repo,
|
||||
oldName: 'refs/tags/v0.1',
|
||||
newName: 'refs/tags/v0.2',
|
||||
),
|
||||
|
@ -460,20 +484,24 @@ void main() {
|
|||
});
|
||||
|
||||
test('renames with force flag set to true', () {
|
||||
final ref1 = repo.lookupReference('refs/tags/v0.1');
|
||||
final ref2 = repo.lookupReference('refs/tags/v0.2');
|
||||
final ref1 = Reference.lookup(repo: repo, name: 'refs/tags/v0.1');
|
||||
final ref2 = Reference.lookup(repo: repo, name: 'refs/tags/v0.2');
|
||||
|
||||
expect(ref1.target.sha, '78b8bf123e3952c970ae5c1ce0a3ea1d1336f6e8');
|
||||
expect(ref2.target.sha, 'f0fdbf506397e9f58c59b88dfdd72778ec06cc0c');
|
||||
expect(repo.references.length, 6);
|
||||
|
||||
repo.renameReference(
|
||||
Reference.rename(
|
||||
repo: repo,
|
||||
oldName: 'refs/tags/v0.1',
|
||||
newName: 'refs/tags/v0.2',
|
||||
force: true,
|
||||
);
|
||||
|
||||
final updatedRef1 = repo.lookupReference('refs/tags/v0.2');
|
||||
final updatedRef1 = Reference.lookup(
|
||||
repo: repo,
|
||||
name: 'refs/tags/v0.2',
|
||||
);
|
||||
expect(
|
||||
updatedRef1.target.sha,
|
||||
'78b8bf123e3952c970ae5c1ce0a3ea1d1336f6e8',
|
||||
|
@ -487,9 +515,9 @@ void main() {
|
|||
});
|
||||
|
||||
test('checks equality', () {
|
||||
final ref1 = repo.lookupReference('refs/heads/master');
|
||||
final ref2 = repo.lookupReference('refs/heads/master');
|
||||
final ref3 = repo.lookupReference('refs/heads/feature');
|
||||
final ref1 = Reference.lookup(repo: repo, name: 'refs/heads/master');
|
||||
final ref2 = Reference.lookup(repo: repo, name: 'refs/heads/master');
|
||||
final ref3 = Reference.lookup(repo: repo, name: 'refs/heads/feature');
|
||||
|
||||
expect(ref1 == ref2, true);
|
||||
expect(ref1 != ref2, false);
|
||||
|
@ -502,8 +530,8 @@ void main() {
|
|||
});
|
||||
|
||||
test('peels to non-tag object when no type is provided', () {
|
||||
final ref = repo.lookupReference('refs/heads/master');
|
||||
final commit = repo.lookupCommit(ref.target);
|
||||
final ref = Reference.lookup(repo: repo, name: 'refs/heads/master');
|
||||
final commit = Commit.lookup(repo: repo, oid: ref.target);
|
||||
final peeled = ref.peel() as Commit;
|
||||
|
||||
expect(peeled.oid, commit.oid);
|
||||
|
@ -514,14 +542,15 @@ void main() {
|
|||
});
|
||||
|
||||
test('peels to object of provided type', () {
|
||||
final ref = repo.lookupReference('refs/heads/master');
|
||||
final blob = repo.lookupBlob(repo['9c78c21']);
|
||||
final blobRef = repo.createReference(
|
||||
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,
|
||||
);
|
||||
final tagRef = repo.lookupReference('refs/tags/v0.2');
|
||||
final commit = repo.lookupCommit(ref.target);
|
||||
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;
|
||||
|
@ -570,7 +599,7 @@ void main() {
|
|||
});
|
||||
|
||||
test('returns string representation of Reference object', () {
|
||||
final ref = repo.lookupReference('refs/heads/master');
|
||||
final ref = Reference.lookup(repo: repo, name: 'refs/heads/master');
|
||||
expect(ref.toString(), contains('Reference{'));
|
||||
ref.free();
|
||||
});
|
||||
|
|
|
@ -24,11 +24,11 @@ void main() {
|
|||
|
||||
group('Remote', () {
|
||||
test('returns list of remotes', () {
|
||||
expect(repo.remotes, ['origin']);
|
||||
expect(Remote.list(repo), ['origin']);
|
||||
});
|
||||
|
||||
test('lookups remote for provided name', () {
|
||||
final remote = repo.lookupRemote('origin');
|
||||
final remote = Remote.lookup(repo: repo, name: 'origin');
|
||||
|
||||
expect(remote.name, remoteName);
|
||||
expect(remote.url, remoteUrl);
|
||||
|
@ -39,11 +39,18 @@ void main() {
|
|||
});
|
||||
|
||||
test('throws when provided name for lookup is not found', () {
|
||||
expect(() => repo.lookupRemote('upstream'), throwsA(isA<LibGit2Error>()));
|
||||
expect(
|
||||
() => Remote.lookup(repo: repo, name: 'upstream'),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
});
|
||||
|
||||
test('creates without fetchspec', () {
|
||||
final remote = repo.createRemote(name: 'upstream', url: remoteUrl);
|
||||
final remote = Remote.create(
|
||||
repo: repo,
|
||||
name: 'upstream',
|
||||
url: remoteUrl,
|
||||
);
|
||||
|
||||
expect(repo.remotes.length, 2);
|
||||
expect(remote.name, 'upstream');
|
||||
|
@ -55,7 +62,8 @@ void main() {
|
|||
|
||||
test('creates with provided fetchspec', () {
|
||||
const spec = '+refs/*:refs/*';
|
||||
final remote = repo.createRemote(
|
||||
final remote = Remote.create(
|
||||
repo: repo,
|
||||
name: 'upstream',
|
||||
url: remoteUrl,
|
||||
fetch: spec,
|
||||
|
@ -73,7 +81,8 @@ void main() {
|
|||
test('throws when trying to create with fetchspec with invalid remote name',
|
||||
() {
|
||||
expect(
|
||||
() => repo.createRemote(
|
||||
() => Remote.create(
|
||||
repo: repo,
|
||||
name: '',
|
||||
url: '',
|
||||
fetch: '',
|
||||
|
@ -83,10 +92,14 @@ void main() {
|
|||
});
|
||||
|
||||
test('deletes remote', () {
|
||||
final remote = repo.createRemote(name: 'upstream', url: remoteUrl);
|
||||
final remote = Remote.create(
|
||||
repo: repo,
|
||||
name: 'upstream',
|
||||
url: remoteUrl,
|
||||
);
|
||||
expect(repo.remotes.length, 2);
|
||||
|
||||
repo.deleteRemote(remote.name);
|
||||
Remote.delete(repo: repo, name: remote.name);
|
||||
expect(repo.remotes.length, 1);
|
||||
|
||||
remote.free();
|
||||
|
@ -94,19 +107,23 @@ void main() {
|
|||
|
||||
test('throws when trying to delete non existing remote', () {
|
||||
expect(
|
||||
() => repo.deleteRemote('not/there'),
|
||||
() => Remote.delete(repo: repo, name: 'not/there'),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
});
|
||||
|
||||
test('renames remote', () {
|
||||
final remote = repo.lookupRemote(remoteName);
|
||||
final remote = Remote.lookup(repo: repo, name: remoteName);
|
||||
|
||||
final problems = repo.renameRemote(oldName: remoteName, newName: 'new');
|
||||
final problems = Remote.rename(
|
||||
repo: repo,
|
||||
oldName: remoteName,
|
||||
newName: 'new',
|
||||
);
|
||||
expect(problems, isEmpty);
|
||||
expect(remote.name, isNot('new'));
|
||||
|
||||
final newRemote = repo.lookupRemote('new');
|
||||
final newRemote = Remote.lookup(repo: repo, name: 'new');
|
||||
expect(newRemote.name, 'new');
|
||||
|
||||
newRemote.free();
|
||||
|
@ -114,14 +131,15 @@ void main() {
|
|||
});
|
||||
|
||||
test('returns list of non-default refspecs that cannot be renamed', () {
|
||||
final remote = repo.createRemote(
|
||||
final remote = Remote.create(
|
||||
repo: repo,
|
||||
name: 'upstream',
|
||||
url: remoteUrl,
|
||||
fetch: '+refs/*:refs/*',
|
||||
);
|
||||
|
||||
expect(
|
||||
repo.renameRemote(oldName: remote.name, newName: 'renamed'),
|
||||
Remote.rename(repo: repo, oldName: remote.name, newName: 'renamed'),
|
||||
['+refs/*:refs/*'],
|
||||
);
|
||||
|
||||
|
@ -130,19 +148,19 @@ void main() {
|
|||
|
||||
test('throws when renaming with invalid names', () {
|
||||
expect(
|
||||
() => repo.renameRemote(oldName: '', newName: ''),
|
||||
() => Remote.rename(repo: repo, oldName: '', newName: ''),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
});
|
||||
|
||||
test('sets url', () {
|
||||
final remote = repo.lookupRemote(remoteName);
|
||||
final remote = Remote.lookup(repo: repo, name: remoteName);
|
||||
expect(remote.url, remoteUrl);
|
||||
|
||||
const newUrl = 'git://new/url.git';
|
||||
Remote.setUrl(repo: repo, remote: remoteName, url: newUrl);
|
||||
|
||||
final newRemote = repo.lookupRemote(remoteName);
|
||||
final newRemote = Remote.lookup(repo: repo, name: remoteName);
|
||||
expect(newRemote.url, newUrl);
|
||||
|
||||
newRemote.free();
|
||||
|
@ -160,7 +178,7 @@ void main() {
|
|||
const newUrl = 'git://new/url.git';
|
||||
Remote.setPushUrl(repo: repo, remote: remoteName, url: newUrl);
|
||||
|
||||
final remote = repo.lookupRemote(remoteName);
|
||||
final remote = Remote.lookup(repo: repo, name: remoteName);
|
||||
expect(remote.pushUrl, newUrl);
|
||||
|
||||
remote.free();
|
||||
|
@ -174,7 +192,7 @@ void main() {
|
|||
});
|
||||
|
||||
test('returns refspec', () {
|
||||
final remote = repo.lookupRemote('origin');
|
||||
final remote = Remote.lookup(repo: repo, name: 'origin');
|
||||
expect(remote.refspecCount, 1);
|
||||
|
||||
final refspec = remote.getRefspec(0);
|
||||
|
@ -203,7 +221,7 @@ void main() {
|
|||
|
||||
test('throws when trying to transform refspec with invalid reference name',
|
||||
() {
|
||||
final remote = repo.lookupRemote('origin');
|
||||
final remote = Remote.lookup(repo: repo, name: 'origin');
|
||||
final refspec = remote.getRefspec(0);
|
||||
|
||||
expect(
|
||||
|
@ -225,7 +243,7 @@ void main() {
|
|||
remote: 'origin',
|
||||
refspec: '+refs/test/*:refs/test/remotes/*',
|
||||
);
|
||||
final remote = repo.lookupRemote('origin');
|
||||
final remote = Remote.lookup(repo: repo, name: 'origin');
|
||||
expect(remote.fetchRefspecs.length, 2);
|
||||
expect(
|
||||
remote.fetchRefspecs,
|
||||
|
@ -255,7 +273,7 @@ void main() {
|
|||
remote: 'origin',
|
||||
refspec: '+refs/test/*:refs/test/remotes/*',
|
||||
);
|
||||
final remote = repo.lookupRemote('origin');
|
||||
final remote = Remote.lookup(repo: repo, name: 'origin');
|
||||
expect(remote.pushRefspecs.length, 1);
|
||||
expect(remote.pushRefspecs, ['+refs/test/*:refs/test/remotes/*']);
|
||||
|
||||
|
@ -279,7 +297,7 @@ void main() {
|
|||
remote: 'libgit2',
|
||||
url: 'https://github.com/libgit2/TestGitRepository',
|
||||
);
|
||||
final remote = repo.lookupRemote('libgit2');
|
||||
final remote = Remote.lookup(repo: repo, name: 'libgit2');
|
||||
|
||||
final refs = remote.ls();
|
||||
expect(refs.first['local'], false);
|
||||
|
@ -298,7 +316,7 @@ void main() {
|
|||
"throws when trying to get remote repo's reference list with "
|
||||
"invalid url", () {
|
||||
Remote.setUrl(repo: repo, remote: 'libgit2', url: 'invalid');
|
||||
final remote = repo.lookupRemote('libgit2');
|
||||
final remote = Remote.lookup(repo: repo, name: 'libgit2');
|
||||
|
||||
expect(() => remote.ls(), throwsA(isA<LibGit2Error>()));
|
||||
|
||||
|
@ -318,7 +336,7 @@ void main() {
|
|||
remote: 'libgit2',
|
||||
refspec: '+refs/heads/*:refs/remotes/origin/*',
|
||||
);
|
||||
final remote = repo.lookupRemote('libgit2');
|
||||
final remote = Remote.lookup(repo: repo, name: 'libgit2');
|
||||
|
||||
final stats = remote.fetch(
|
||||
refspecs: ['+refs/heads/*:refs/remotes/origin/*'],
|
||||
|
@ -351,7 +369,7 @@ void main() {
|
|||
remote: 'libgit2',
|
||||
refspec: '+refs/heads/*:refs/remotes/origin/*',
|
||||
);
|
||||
final remote = repo.lookupRemote('libgit2');
|
||||
final remote = Remote.lookup(repo: repo, name: 'libgit2');
|
||||
|
||||
final stats = remote.fetch(
|
||||
refspecs: ['+refs/heads/*:refs/remotes/origin/*'],
|
||||
|
@ -385,7 +403,7 @@ void main() {
|
|||
remote: 'libgit2',
|
||||
refspec: '+refs/heads/*:refs/remotes/origin/*',
|
||||
);
|
||||
final remote = repo.lookupRemote('libgit2');
|
||||
final remote = Remote.lookup(repo: repo, name: 'libgit2');
|
||||
|
||||
expect(
|
||||
() => remote.fetch(
|
||||
|
@ -402,7 +420,7 @@ void main() {
|
|||
|
||||
test('throws when trying to fetch data with invalid url', () {
|
||||
Remote.setUrl(repo: repo, remote: 'libgit2', url: 'https://wrong.url');
|
||||
final remote = repo.lookupRemote('libgit2');
|
||||
final remote = Remote.lookup(repo: repo, name: 'libgit2');
|
||||
|
||||
expect(
|
||||
() => remote.fetch(),
|
||||
|
@ -420,7 +438,7 @@ void main() {
|
|||
remote: 'libgit2',
|
||||
url: 'https://github.com/libgit2/TestGitRepository',
|
||||
);
|
||||
final remote = repo.lookupRemote('libgit2');
|
||||
final remote = Remote.lookup(repo: repo, name: 'libgit2');
|
||||
|
||||
TransferProgress? callbackStats;
|
||||
void tp(TransferProgress stats) => callbackStats = stats;
|
||||
|
@ -454,7 +472,7 @@ Total 69 (delta 0), reused 1 (delta 0), pack-reused 68
|
|||
remote: 'libgit2',
|
||||
url: 'https://github.com/libgit2/TestGitRepository',
|
||||
);
|
||||
final remote = repo.lookupRemote('libgit2');
|
||||
final remote = Remote.lookup(repo: repo, name: 'libgit2');
|
||||
|
||||
final sidebandOutput = StringBuffer();
|
||||
void sideband(String message) {
|
||||
|
@ -479,7 +497,7 @@ Total 69 (delta 0), reused 1 (delta 0), pack-reused 68
|
|||
remote: 'libgit2',
|
||||
url: 'https://github.com/libgit2/TestGitRepository',
|
||||
);
|
||||
final remote = repo.lookupRemote('libgit2');
|
||||
final remote = Remote.lookup(repo: repo, name: 'libgit2');
|
||||
final tipsExpected = [
|
||||
{
|
||||
'refname': 'refs/tags/annotated_tag',
|
||||
|
@ -531,8 +549,8 @@ Total 69 (delta 0), reused 1 (delta 0), pack-reused 68
|
|||
);
|
||||
final originRepo = Repository.open(originDir.path);
|
||||
|
||||
repo.createRemote(name: 'local', url: originDir.path);
|
||||
final remote = repo.lookupRemote('local');
|
||||
Remote.create(repo: repo, name: 'local', url: originDir.path);
|
||||
final remote = Remote.lookup(repo: repo, name: 'local');
|
||||
|
||||
final updateRefOutput = <String, String>{};
|
||||
void updateRef(String refname, String message) {
|
||||
|
@ -543,7 +561,7 @@ Total 69 (delta 0), reused 1 (delta 0), pack-reused 68
|
|||
|
||||
remote.push(refspecs: ['refs/heads/master'], callbacks: callbacks);
|
||||
expect(
|
||||
originRepo.lookupCommit(originRepo.head.target).oid.sha,
|
||||
Commit.lookup(repo: originRepo, oid: originRepo.head.target).oid.sha,
|
||||
'821ed6e80627b8769d170a293862f9fc60825226',
|
||||
);
|
||||
expect(updateRefOutput, {'refs/heads/master': ''});
|
||||
|
@ -555,7 +573,7 @@ Total 69 (delta 0), reused 1 (delta 0), pack-reused 68
|
|||
|
||||
test('throws when trying to push to invalid url', () {
|
||||
Remote.setUrl(repo: repo, remote: 'libgit2', url: 'https://wrong.url');
|
||||
final remote = repo.lookupRemote('libgit2');
|
||||
final remote = Remote.lookup(repo: repo, name: 'libgit2');
|
||||
|
||||
expect(
|
||||
() => remote.push(refspecs: ['refs/heads/master']),
|
||||
|
|
|
@ -42,7 +42,7 @@ void main() {
|
|||
expect(contents, 'Feature edit\n');
|
||||
|
||||
final index = repo.index;
|
||||
final diff = index.diffToWorkdir();
|
||||
final diff = Diff.indexToWorkdir(repo: repo, index: index);
|
||||
expect(diff.deltas, isEmpty);
|
||||
|
||||
index.free();
|
||||
|
@ -57,7 +57,7 @@ void main() {
|
|||
expect(contents, 'Feature edit\n');
|
||||
|
||||
final index = repo.index;
|
||||
final diff = index.diffToWorkdir();
|
||||
final diff = Diff.indexToWorkdir(repo: repo, index: index);
|
||||
expect(diff.deltas.length, 1);
|
||||
|
||||
index.free();
|
||||
|
|
|
@ -24,13 +24,13 @@ void main() {
|
|||
|
||||
group('revParse', () {
|
||||
test('.single() returns commit with different spec strings', () {
|
||||
final headCommit = repo.revParseSingle('HEAD');
|
||||
final headCommit = RevParse.single(repo: repo, spec: 'HEAD');
|
||||
expect(headCommit.oid.sha, headSHA);
|
||||
|
||||
final parentCommit = repo.revParseSingle('HEAD^');
|
||||
final parentCommit = RevParse.single(repo: repo, spec: 'HEAD^');
|
||||
expect(parentCommit.oid.sha, parentSHA);
|
||||
|
||||
final initCommit = repo.revParseSingle('@{-1}');
|
||||
final initCommit = RevParse.single(repo: repo, spec: '@{-1}');
|
||||
expect(initCommit.oid.sha, '5aecfa0fb97eadaac050ccb99f03c3fb65460ad4');
|
||||
|
||||
headCommit.free();
|
||||
|
@ -40,15 +40,18 @@ void main() {
|
|||
|
||||
test('.single() throws when spec string not found or invalid', () {
|
||||
expect(
|
||||
() => repo.revParseSingle('invalid'),
|
||||
() => RevParse.single(repo: repo, spec: 'invalid'),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
expect(
|
||||
() => RevParse.single(repo: repo, spec: ''),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
expect(() => repo.revParseSingle(''), throwsA(isA<LibGit2Error>()));
|
||||
});
|
||||
|
||||
test('.ext() returns commit and reference', () {
|
||||
final masterRef = repo.lookupReference('refs/heads/master');
|
||||
var headParse = repo.revParseExt('master');
|
||||
final masterRef = Reference.lookup(repo: repo, name: 'refs/heads/master');
|
||||
var headParse = RevParse.ext(repo: repo, spec: 'master');
|
||||
|
||||
expect(headParse.object.oid.sha, headSHA);
|
||||
expect(headParse.reference, masterRef);
|
||||
|
@ -58,8 +61,11 @@ void main() {
|
|||
headParse.object.free();
|
||||
headParse.reference?.free();
|
||||
|
||||
final featureRef = repo.lookupReference('refs/heads/feature');
|
||||
headParse = repo.revParseExt('feature');
|
||||
final featureRef = Reference.lookup(
|
||||
repo: repo,
|
||||
name: 'refs/heads/feature',
|
||||
);
|
||||
headParse = RevParse.ext(repo: repo, spec: 'feature');
|
||||
|
||||
expect(
|
||||
headParse.object.oid.sha,
|
||||
|
@ -73,7 +79,7 @@ void main() {
|
|||
});
|
||||
|
||||
test('.ext() returns only commit when no intermidiate reference found', () {
|
||||
final headParse = repo.revParseExt('HEAD^');
|
||||
final headParse = RevParse.ext(repo: repo, spec: 'HEAD^');
|
||||
|
||||
expect(headParse.object.oid.sha, parentSHA);
|
||||
expect(headParse.reference, isNull);
|
||||
|
@ -83,16 +89,19 @@ void main() {
|
|||
|
||||
test('.ext() throws when spec string not found or invalid', () {
|
||||
expect(
|
||||
() => repo.revParseExt('invalid'),
|
||||
() => RevParse.ext(repo: repo, spec: 'invalid'),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
expect(
|
||||
() => RevParse.ext(repo: repo, spec: ''),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
expect(() => repo.revParseExt(''), throwsA(isA<LibGit2Error>()));
|
||||
});
|
||||
|
||||
test(
|
||||
'.range returns revspec with correct fields values based on '
|
||||
'provided spec', () {
|
||||
var revspec = repo.revParse('master');
|
||||
var revspec = RevParse.range(repo: repo, spec: 'master');
|
||||
|
||||
expect(revspec.from.oid.sha, headSHA);
|
||||
expect(revspec.to, isNull);
|
||||
|
@ -101,7 +110,7 @@ void main() {
|
|||
|
||||
revspec.from.free();
|
||||
|
||||
revspec = repo.revParse('HEAD^1..5aecfa');
|
||||
revspec = RevParse.range(repo: repo, spec: 'HEAD^1..5aecfa');
|
||||
|
||||
expect(revspec.from.oid.sha, parentSHA);
|
||||
expect(revspec.to?.oid.sha, '5aecfa0fb97eadaac050ccb99f03c3fb65460ad4');
|
||||
|
@ -110,7 +119,7 @@ void main() {
|
|||
revspec.from.free();
|
||||
revspec.to?.free();
|
||||
|
||||
revspec = repo.revParse('HEAD...feature');
|
||||
revspec = RevParse.range(repo: repo, spec: 'HEAD...feature');
|
||||
|
||||
expect(revspec.from.oid.sha, headSHA);
|
||||
expect(revspec.to?.oid.sha, '5aecfa0fb97eadaac050ccb99f03c3fb65460ad4');
|
||||
|
@ -126,11 +135,11 @@ void main() {
|
|||
|
||||
test('throws on invalid range spec', () {
|
||||
expect(
|
||||
() => repo.revParse('invalid..5aecfa'),
|
||||
() => RevParse.range(repo: repo, spec: 'invalid..5aecfa'),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
expect(
|
||||
() => repo.revParse('master.......5aecfa'),
|
||||
() => RevParse.range(repo: repo, spec: 'master.......5aecfa'),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
});
|
||||
|
|
|
@ -33,13 +33,13 @@ void main() {
|
|||
test('saves changes to stash', () {
|
||||
File(filePath).writeAsStringSync('edit', mode: FileMode.append);
|
||||
|
||||
repo.createStash(stasher: stasher);
|
||||
Stash.create(repo: repo, stasher: stasher);
|
||||
expect(repo.status.isEmpty, true);
|
||||
});
|
||||
|
||||
test('throws when trying to save and error occurs', () {
|
||||
expect(
|
||||
() => Repository(nullptr).createStash(stasher: stasher),
|
||||
() => Stash.create(repo: Repository(nullptr), stasher: stasher),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
});
|
||||
|
@ -48,7 +48,8 @@ void main() {
|
|||
final swpPath = File(p.join(repo.workdir, 'some.swp'));
|
||||
swpPath.writeAsStringSync('ignored');
|
||||
|
||||
repo.createStash(
|
||||
Stash.create(
|
||||
repo: repo,
|
||||
stasher: stasher,
|
||||
flags: {GitStash.includeUntracked, GitStash.includeIgnored},
|
||||
);
|
||||
|
@ -64,7 +65,7 @@ void main() {
|
|||
final index = repo.index;
|
||||
index.add('file');
|
||||
|
||||
repo.createStash(stasher: stasher, flags: {GitStash.keepIndex});
|
||||
Stash.create(repo: repo, stasher: stasher, flags: {GitStash.keepIndex});
|
||||
expect(repo.status.isEmpty, false);
|
||||
expect(repo.stashes.length, 1);
|
||||
|
||||
|
@ -74,20 +75,20 @@ void main() {
|
|||
test('applies changes from stash', () {
|
||||
File(filePath).writeAsStringSync('edit', mode: FileMode.append);
|
||||
|
||||
repo.createStash(stasher: stasher);
|
||||
Stash.create(repo: repo, stasher: stasher);
|
||||
expect(repo.status.isEmpty, true);
|
||||
|
||||
repo.applyStash();
|
||||
Stash.apply(repo: repo);
|
||||
expect(repo.status, contains('file'));
|
||||
});
|
||||
|
||||
test('applies changes from stash with paths provided', () {
|
||||
File(filePath).writeAsStringSync('edit', mode: FileMode.append);
|
||||
|
||||
repo.createStash(stasher: stasher);
|
||||
Stash.create(repo: repo, stasher: stasher);
|
||||
expect(repo.status.isEmpty, true);
|
||||
|
||||
repo.applyStash(paths: ['file']);
|
||||
Stash.apply(repo: repo, paths: ['file']);
|
||||
expect(repo.status, contains('file'));
|
||||
});
|
||||
|
||||
|
@ -97,11 +98,15 @@ void main() {
|
|||
index.add('stash.this');
|
||||
expect(index.find('stash.this'), true);
|
||||
|
||||
repo.createStash(stasher: stasher, flags: {GitStash.includeUntracked});
|
||||
Stash.create(
|
||||
repo: repo,
|
||||
stasher: stasher,
|
||||
flags: {GitStash.includeUntracked},
|
||||
);
|
||||
expect(repo.status.isEmpty, true);
|
||||
expect(index.find('stash.this'), false);
|
||||
|
||||
repo.applyStash(reinstateIndex: true);
|
||||
Stash.apply(repo: repo, reinstateIndex: true);
|
||||
expect(repo.status, contains('stash.this'));
|
||||
expect(index.find('stash.this'), true);
|
||||
|
||||
|
@ -111,17 +116,20 @@ void main() {
|
|||
test('throws when trying to apply with wrong index', () {
|
||||
File(filePath).writeAsStringSync('edit', mode: FileMode.append);
|
||||
|
||||
repo.createStash(stasher: stasher);
|
||||
Stash.create(repo: repo, stasher: stasher);
|
||||
|
||||
expect(() => repo.applyStash(index: 10), throwsA(isA<LibGit2Error>()));
|
||||
expect(
|
||||
() => Stash.apply(repo: repo, index: 10),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
});
|
||||
|
||||
test('drops stash', () {
|
||||
File(filePath).writeAsStringSync('edit', mode: FileMode.append);
|
||||
|
||||
repo.createStash(stasher: stasher);
|
||||
Stash.create(repo: repo, stasher: stasher);
|
||||
final stash = repo.stashes.first;
|
||||
repo.dropStash(index: stash.index);
|
||||
Stash.drop(repo: repo, index: stash.index);
|
||||
|
||||
expect(() => repo.applyStash(), throwsA(isA<LibGit2Error>()));
|
||||
});
|
||||
|
@ -129,29 +137,32 @@ void main() {
|
|||
test('throws when trying to drop with wrong index', () {
|
||||
File(filePath).writeAsStringSync('edit', mode: FileMode.append);
|
||||
|
||||
repo.createStash(stasher: stasher);
|
||||
Stash.create(repo: repo, stasher: stasher);
|
||||
|
||||
expect(() => repo.dropStash(index: 10), throwsA(isA<LibGit2Error>()));
|
||||
expect(
|
||||
() => Stash.drop(repo: repo, index: 10),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
});
|
||||
|
||||
test('pops from stash', () {
|
||||
File(filePath).writeAsStringSync('edit', mode: FileMode.append);
|
||||
|
||||
repo.createStash(stasher: stasher);
|
||||
repo.popStash();
|
||||
Stash.create(repo: repo, stasher: stasher);
|
||||
Stash.pop(repo: repo);
|
||||
|
||||
expect(repo.status, contains('file'));
|
||||
expect(() => repo.applyStash(), throwsA(isA<LibGit2Error>()));
|
||||
expect(() => Stash.apply(repo: repo), throwsA(isA<LibGit2Error>()));
|
||||
});
|
||||
|
||||
test('pops from stash with provided path', () {
|
||||
File(filePath).writeAsStringSync('edit', mode: FileMode.append);
|
||||
|
||||
repo.createStash(stasher: stasher);
|
||||
repo.popStash(paths: ['file']);
|
||||
Stash.create(repo: repo, stasher: stasher);
|
||||
Stash.pop(repo: repo, paths: ['file']);
|
||||
|
||||
expect(repo.status, contains('file'));
|
||||
expect(() => repo.applyStash(), throwsA(isA<LibGit2Error>()));
|
||||
expect(() => Stash.apply(repo: repo), throwsA(isA<LibGit2Error>()));
|
||||
});
|
||||
|
||||
test('pops from stash including index changes', () {
|
||||
|
@ -160,11 +171,15 @@ void main() {
|
|||
index.add('stash.this');
|
||||
expect(index.find('stash.this'), true);
|
||||
|
||||
repo.createStash(stasher: stasher, flags: {GitStash.includeUntracked});
|
||||
Stash.create(
|
||||
repo: repo,
|
||||
stasher: stasher,
|
||||
flags: {GitStash.includeUntracked},
|
||||
);
|
||||
expect(repo.status.isEmpty, true);
|
||||
expect(index.find('stash.this'), false);
|
||||
|
||||
repo.popStash(reinstateIndex: true);
|
||||
Stash.pop(repo: repo, reinstateIndex: true);
|
||||
expect(repo.status, contains('stash.this'));
|
||||
expect(index.find('stash.this'), true);
|
||||
|
||||
|
@ -174,17 +189,20 @@ void main() {
|
|||
test('throws when trying to pop with wrong index', () {
|
||||
File(filePath).writeAsStringSync('edit', mode: FileMode.append);
|
||||
|
||||
repo.createStash(stasher: stasher);
|
||||
Stash.create(repo: repo, stasher: stasher);
|
||||
|
||||
expect(() => repo.popStash(index: 10), throwsA(isA<LibGit2Error>()));
|
||||
expect(
|
||||
() => Stash.pop(repo: repo, index: 10),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
});
|
||||
|
||||
test('returns list of stashes', () {
|
||||
File(filePath).writeAsStringSync('edit', mode: FileMode.append);
|
||||
|
||||
repo.createStash(stasher: stasher, message: 'WIP');
|
||||
Stash.create(repo: repo, stasher: stasher, message: 'WIP');
|
||||
|
||||
final stash = repo.stashes.first;
|
||||
final stash = Stash.list(repo).first;
|
||||
|
||||
expect(repo.stashes.length, 1);
|
||||
expect(stash.index, 0);
|
||||
|
@ -194,7 +212,11 @@ void main() {
|
|||
test('returns string representation of Stash object', () {
|
||||
File(p.join(repo.workdir, 'stash.this')).writeAsStringSync('stash');
|
||||
|
||||
repo.createStash(stasher: stasher, flags: {GitStash.includeUntracked});
|
||||
Stash.create(
|
||||
repo: repo,
|
||||
stasher: stasher,
|
||||
flags: {GitStash.includeUntracked},
|
||||
);
|
||||
|
||||
expect(repo.stashes[0].toString(), contains('Stash{'));
|
||||
});
|
||||
|
|
|
@ -30,12 +30,12 @@ void main() {
|
|||
|
||||
group('Submodule', () {
|
||||
test('returns list of all submodules paths', () {
|
||||
expect(repo.submodules.length, 1);
|
||||
expect(Submodule.list(repo).length, 1);
|
||||
expect(repo.submodules.first, testSubmodule);
|
||||
});
|
||||
|
||||
test('finds submodule with provided name/path', () {
|
||||
final submodule = repo.lookupSubmodule(testSubmodule);
|
||||
final submodule = Submodule.lookup(repo: repo, name: testSubmodule);
|
||||
|
||||
expect(submodule.name, testSubmodule);
|
||||
expect(submodule.path, testSubmodule);
|
||||
|
@ -53,7 +53,7 @@ void main() {
|
|||
|
||||
test('throws when trying to lookup and submodule not found', () {
|
||||
expect(
|
||||
() => repo.lookupSubmodule('not/there'),
|
||||
() => Submodule.lookup(repo: repo, name: 'not/there'),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
});
|
||||
|
@ -63,8 +63,8 @@ void main() {
|
|||
p.join(repo.workdir, testSubmodule, 'master.txt');
|
||||
expect(File(submoduleFilePath).existsSync(), false);
|
||||
|
||||
repo.initSubmodule(submodule: testSubmodule);
|
||||
repo.updateSubmodule(submodule: testSubmodule);
|
||||
Submodule.init(repo: repo, name: testSubmodule);
|
||||
Submodule.update(repo: repo, name: testSubmodule);
|
||||
|
||||
expect(File(submoduleFilePath).existsSync(), true);
|
||||
});
|
||||
|
@ -74,22 +74,22 @@ void main() {
|
|||
p.join(repo.workdir, testSubmodule, 'master.txt');
|
||||
expect(File(submoduleFilePath).existsSync(), false);
|
||||
|
||||
repo.updateSubmodule(submodule: testSubmodule, init: true);
|
||||
Submodule.update(repo: repo, name: testSubmodule, init: true);
|
||||
|
||||
expect(File(submoduleFilePath).existsSync(), true);
|
||||
});
|
||||
|
||||
test('throws when trying to update not initialized submodule', () {
|
||||
expect(
|
||||
() => repo.updateSubmodule(submodule: testSubmodule),
|
||||
() => Submodule.update(repo: repo, name: testSubmodule),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
});
|
||||
|
||||
test('opens repository for a submodule', () {
|
||||
final submodule = repo.lookupSubmodule(testSubmodule);
|
||||
repo.initSubmodule(submodule: testSubmodule);
|
||||
repo.updateSubmodule(submodule: testSubmodule);
|
||||
final submodule = Submodule.lookup(repo: repo, name: testSubmodule);
|
||||
Submodule.init(repo: repo, name: testSubmodule);
|
||||
Submodule.update(repo: repo, name: testSubmodule);
|
||||
|
||||
final submoduleRepo = submodule.open();
|
||||
final subHead = submoduleRepo.head;
|
||||
|
@ -107,13 +107,14 @@ void main() {
|
|||
|
||||
test('throws when trying to open repository for not initialized submodule',
|
||||
() {
|
||||
final submodule = repo.lookupSubmodule(testSubmodule);
|
||||
final submodule = Submodule.lookup(repo: repo, name: testSubmodule);
|
||||
expect(() => submodule.open(), throwsA(isA<LibGit2Error>()));
|
||||
submodule.free();
|
||||
});
|
||||
|
||||
test('adds submodule', () {
|
||||
final submodule = repo.addSubmodule(
|
||||
final submodule = Submodule.add(
|
||||
repo: repo,
|
||||
url: submoduleUrl,
|
||||
path: 'test',
|
||||
);
|
||||
|
@ -129,7 +130,8 @@ void main() {
|
|||
|
||||
test('throws when trying to add submodule with wrong url', () {
|
||||
expect(
|
||||
() => repo.addSubmodule(
|
||||
() => Submodule.add(
|
||||
repo: repo,
|
||||
url: 'https://wrong.url/',
|
||||
path: 'test',
|
||||
),
|
||||
|
@ -139,7 +141,8 @@ void main() {
|
|||
|
||||
test('throws when trying to add submodule and error occurs', () {
|
||||
expect(
|
||||
() => Repository(nullptr).addSubmodule(
|
||||
() => Submodule.add(
|
||||
repo: Repository(nullptr),
|
||||
url: 'https://wrong.url/',
|
||||
path: 'test',
|
||||
),
|
||||
|
@ -148,7 +151,7 @@ void main() {
|
|||
});
|
||||
|
||||
test('sets configuration values', () {
|
||||
final submodule = repo.lookupSubmodule(testSubmodule);
|
||||
final submodule = Submodule.lookup(repo: repo, name: testSubmodule);
|
||||
expect(submodule.url, submoduleUrl);
|
||||
expect(submodule.branch, '');
|
||||
expect(submodule.ignore, GitSubmoduleIgnore.none);
|
||||
|
@ -159,7 +162,10 @@ void main() {
|
|||
submodule.ignore = GitSubmoduleIgnore.all;
|
||||
submodule.updateRule = GitSubmoduleUpdate.rebase;
|
||||
|
||||
final updatedSubmodule = repo.lookupSubmodule(testSubmodule);
|
||||
final updatedSubmodule = Submodule.lookup(
|
||||
repo: repo,
|
||||
name: testSubmodule,
|
||||
);
|
||||
expect(updatedSubmodule.url, 'updated');
|
||||
expect(updatedSubmodule.branch, 'updated');
|
||||
expect(updatedSubmodule.ignore, GitSubmoduleIgnore.all);
|
||||
|
@ -170,8 +176,8 @@ void main() {
|
|||
});
|
||||
|
||||
test('syncs', () {
|
||||
repo.updateSubmodule(submodule: testSubmodule, init: true);
|
||||
final submodule = repo.lookupSubmodule(testSubmodule);
|
||||
Submodule.update(repo: repo, name: testSubmodule, init: true);
|
||||
final submodule = Submodule.lookup(repo: repo, name: testSubmodule);
|
||||
final submRepo = submodule.open();
|
||||
final repoConfig = repo.config;
|
||||
final submRepoConfig = submRepo.config;
|
||||
|
@ -182,7 +188,10 @@ void main() {
|
|||
submodule.url = 'https://updated.com/';
|
||||
submodule.branch = 'updated';
|
||||
|
||||
final updatedSubmodule = repo.lookupSubmodule(testSubmodule);
|
||||
final updatedSubmodule = Submodule.lookup(
|
||||
repo: repo,
|
||||
name: testSubmodule,
|
||||
);
|
||||
updatedSubmodule.sync();
|
||||
final updatedSubmRepo = updatedSubmodule.open();
|
||||
final updatedSubmRepoConfig = updatedSubmRepo.config;
|
||||
|
@ -206,7 +215,7 @@ void main() {
|
|||
});
|
||||
|
||||
test('reloads info', () {
|
||||
final submodule = repo.lookupSubmodule(testSubmodule);
|
||||
final submodule = Submodule.lookup(repo: repo, name: testSubmodule);
|
||||
expect(submodule.url, submoduleUrl);
|
||||
|
||||
submodule.url = 'updated';
|
||||
|
@ -218,7 +227,7 @@ void main() {
|
|||
});
|
||||
|
||||
test('returns status for a submodule', () {
|
||||
final submodule = repo.lookupSubmodule(testSubmodule);
|
||||
final submodule = Submodule.lookup(repo: repo, name: testSubmodule);
|
||||
expect(
|
||||
submodule.status(),
|
||||
{
|
||||
|
@ -229,7 +238,7 @@ void main() {
|
|||
},
|
||||
);
|
||||
|
||||
repo.updateSubmodule(submodule: testSubmodule, init: true);
|
||||
Submodule.update(repo: repo, name: testSubmodule, init: true);
|
||||
expect(
|
||||
submodule.status(),
|
||||
{
|
||||
|
|
|
@ -17,7 +17,7 @@ void main() {
|
|||
tmpDir = setupRepo(Directory(p.join('test', 'assets', 'test_repo')));
|
||||
repo = Repository.open(tmpDir.path);
|
||||
tagOid = repo['f0fdbf506397e9f58c59b88dfdd72778ec06cc0c'];
|
||||
tag = repo.lookupTag(tagOid);
|
||||
tag = Tag.lookup(repo: repo, oid: tagOid);
|
||||
});
|
||||
|
||||
tearDown(() {
|
||||
|
@ -33,7 +33,7 @@ void main() {
|
|||
|
||||
test('throws when trying to lookup tag for invalid oid', () {
|
||||
expect(
|
||||
() => repo.lookupTag(repo['0' * 40]),
|
||||
() => Tag.lookup(repo: repo, oid: repo['0' * 40]),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
});
|
||||
|
@ -84,7 +84,7 @@ void main() {
|
|||
message: message,
|
||||
);
|
||||
|
||||
final newTag = repo.lookupTag(oid);
|
||||
final newTag = Tag.lookup(repo: repo, oid: oid);
|
||||
final tagger = newTag.tagger;
|
||||
final newTagTarget = newTag.target as Commit;
|
||||
|
||||
|
@ -111,7 +111,7 @@ void main() {
|
|||
targetType: GitObject.commit,
|
||||
);
|
||||
|
||||
final newTag = repo.lookupReference('refs/tags/$tagName');
|
||||
final newTag = Reference.lookup(repo: repo, name: 'refs/tags/$tagName');
|
||||
|
||||
expect(newTag.shorthand, tagName);
|
||||
expect(newTag.target, target);
|
||||
|
@ -138,7 +138,7 @@ void main() {
|
|||
message: message,
|
||||
);
|
||||
|
||||
final newTag = repo.lookupTag(oid);
|
||||
final newTag = Tag.lookup(repo: repo, oid: oid);
|
||||
final tagger = newTag.tagger;
|
||||
final newTagTarget = newTag.target as Tree;
|
||||
|
||||
|
@ -164,7 +164,7 @@ void main() {
|
|||
targetType: GitObject.tree,
|
||||
);
|
||||
|
||||
final newTag = repo.lookupReference('refs/tags/$tagName');
|
||||
final newTag = Reference.lookup(repo: repo, name: 'refs/tags/$tagName');
|
||||
|
||||
expect(newTag.shorthand, tagName);
|
||||
expect(newTag.target, target);
|
||||
|
@ -191,7 +191,7 @@ void main() {
|
|||
message: message,
|
||||
);
|
||||
|
||||
final newTag = repo.lookupTag(oid);
|
||||
final newTag = Tag.lookup(repo: repo, oid: oid);
|
||||
final tagger = newTag.tagger;
|
||||
final newTagTarget = newTag.target as Blob;
|
||||
|
||||
|
@ -217,7 +217,7 @@ void main() {
|
|||
targetType: GitObject.blob,
|
||||
);
|
||||
|
||||
final newTag = repo.lookupReference('refs/tags/$tagName');
|
||||
final newTag = Reference.lookup(repo: repo, name: 'refs/tags/$tagName');
|
||||
|
||||
expect(newTag.shorthand, tagName);
|
||||
expect(newTag.target, target);
|
||||
|
@ -243,7 +243,7 @@ void main() {
|
|||
message: message,
|
||||
);
|
||||
|
||||
final newTag = repo.lookupTag(oid);
|
||||
final newTag = Tag.lookup(repo: repo, oid: oid);
|
||||
final tagger = newTag.tagger;
|
||||
final newTagTarget = newTag.target as Tag;
|
||||
|
||||
|
@ -268,7 +268,7 @@ void main() {
|
|||
targetType: GitObject.tag,
|
||||
);
|
||||
|
||||
final newTag = repo.lookupReference('refs/tags/$tagName');
|
||||
final newTag = Reference.lookup(repo: repo, name: 'refs/tags/$tagName');
|
||||
|
||||
expect(newTag.shorthand, tagName);
|
||||
expect(newTag.target, tag.oid);
|
||||
|
@ -302,7 +302,7 @@ void main() {
|
|||
force: true,
|
||||
);
|
||||
|
||||
final newTag = repo.lookupTag(oid);
|
||||
final newTag = Tag.lookup(repo: repo, oid: oid);
|
||||
final tagger = newTag.tagger;
|
||||
final newTagTarget = newTag.target as Commit;
|
||||
|
||||
|
@ -337,7 +337,7 @@ void main() {
|
|||
force: true,
|
||||
);
|
||||
|
||||
final newTag = repo.lookupReference('refs/tags/$tagName');
|
||||
final newTag = Reference.lookup(repo: repo, name: 'refs/tags/$tagName');
|
||||
|
||||
expect(newTag.shorthand, tagName);
|
||||
expect(newTag.target, target);
|
||||
|
@ -408,14 +408,17 @@ void main() {
|
|||
});
|
||||
|
||||
test('deletes tag', () {
|
||||
expect(repo.tags, ['v0.1', 'v0.2']);
|
||||
expect(Tag.list(repo), ['v0.1', 'v0.2']);
|
||||
|
||||
repo.deleteTag('v0.2');
|
||||
expect(repo.tags, ['v0.1']);
|
||||
Tag.delete(repo: repo, name: 'v0.2');
|
||||
expect(Tag.list(repo), ['v0.1']);
|
||||
});
|
||||
|
||||
test('throws when trying to delete non existing tag', () {
|
||||
expect(() => repo.deleteTag('not.there'), throwsA(isA<LibGit2Error>()));
|
||||
expect(
|
||||
() => Tag.delete(repo: repo, name: 'not.there'),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -15,9 +15,7 @@ void main() {
|
|||
setUp(() {
|
||||
tmpDir = setupRepo(Directory(p.join('test', 'assets', 'test_repo')));
|
||||
repo = Repository.open(tmpDir.path);
|
||||
tree = repo.lookupTree(
|
||||
repo['a8ae3dd59e6e1802c6f78e05e301bfd57c9f334f'],
|
||||
);
|
||||
tree = Tree.lookup(repo: repo, oid: repo['a8ae3dd']);
|
||||
});
|
||||
|
||||
tearDown(() {
|
||||
|
@ -34,7 +32,7 @@ void main() {
|
|||
|
||||
test('throws when looking up tree for invalid oid', () {
|
||||
expect(
|
||||
() => repo.lookupTree(repo['0' * 40]),
|
||||
() => Tree.lookup(repo: repo, oid: repo['0' * 40]),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
});
|
||||
|
@ -79,7 +77,7 @@ void main() {
|
|||
});
|
||||
|
||||
test('creates tree', () {
|
||||
final fileOid = repo.createBlob('blob content');
|
||||
final fileOid = Blob.create(repo: repo, content: 'blob content');
|
||||
final builder = TreeBuilder(repo: repo);
|
||||
|
||||
builder.add(
|
||||
|
@ -87,7 +85,7 @@ void main() {
|
|||
oid: fileOid,
|
||||
filemode: GitFilemode.blob,
|
||||
);
|
||||
final newTree = repo.lookupTree(builder.write());
|
||||
final newTree = Tree.lookup(repo: repo, oid: builder.write());
|
||||
|
||||
final entry = newTree['filename'];
|
||||
expect(newTree.length, 1);
|
||||
|
|
|
@ -15,7 +15,7 @@ void main() {
|
|||
setUp(() {
|
||||
tmpDir = setupRepo(Directory(p.join('test', 'assets', 'test_repo')));
|
||||
repo = Repository.open(tmpDir.path);
|
||||
tree = repo.lookupTree(repo['a8ae3dd59e6e1802c6f78e05e301bfd57c9f334f']);
|
||||
tree = Tree.lookup(repo: repo, oid: repo['a8ae3dd']);
|
||||
});
|
||||
|
||||
tearDown(() {
|
||||
|
|
|
@ -31,9 +31,10 @@ void main() {
|
|||
|
||||
group('Worktree', () {
|
||||
test('creates worktree at provided path', () {
|
||||
expect(repo.worktrees, <String>[]);
|
||||
expect(Worktree.list(repo), <String>[]);
|
||||
|
||||
final worktree = repo.createWorktree(
|
||||
final worktree = Worktree.create(
|
||||
repo: repo,
|
||||
name: worktreeName,
|
||||
path: worktreeDir.path,
|
||||
);
|
||||
|
@ -54,17 +55,22 @@ void main() {
|
|||
});
|
||||
|
||||
test('creates worktree at provided path from provided reference', () {
|
||||
final head = repo.revParseSingle('HEAD');
|
||||
final worktreeBranch = repo.createBranch(name: 'v1', target: head);
|
||||
final ref = repo.lookupReference('refs/heads/v1');
|
||||
final head = RevParse.single(repo: repo, spec: 'HEAD');
|
||||
final worktreeBranch = Branch.create(
|
||||
repo: repo,
|
||||
name: 'v1',
|
||||
target: head,
|
||||
);
|
||||
final ref = Reference.lookup(repo: repo, name: 'refs/heads/v1');
|
||||
expect(repo.worktrees, <String>[]);
|
||||
|
||||
final worktree = repo.createWorktree(
|
||||
final worktree = Worktree.create(
|
||||
repo: repo,
|
||||
name: worktreeName,
|
||||
path: worktreeDir.path,
|
||||
ref: ref,
|
||||
);
|
||||
final branches = repo.branches;
|
||||
final branches = Branch.list(repo: repo);
|
||||
|
||||
expect(repo.worktrees, [worktreeName]);
|
||||
expect(branches.any((branch) => branch.name == 'v1'), true);
|
||||
|
@ -89,14 +95,16 @@ void main() {
|
|||
|
||||
test('throws when trying to create worktree with invalid name or path', () {
|
||||
expect(
|
||||
() => repo.createWorktree(
|
||||
() => Worktree.create(
|
||||
repo: repo,
|
||||
name: '',
|
||||
path: worktreeDir.path,
|
||||
),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
expect(
|
||||
() => repo.createWorktree(
|
||||
() => Worktree.create(
|
||||
repo: repo,
|
||||
name: 'name',
|
||||
path: '',
|
||||
),
|
||||
|
@ -105,11 +113,12 @@ void main() {
|
|||
});
|
||||
|
||||
test('lookups worktree', () {
|
||||
final worktree = repo.createWorktree(
|
||||
final worktree = Worktree.create(
|
||||
repo: repo,
|
||||
name: worktreeName,
|
||||
path: worktreeDir.path,
|
||||
);
|
||||
final lookedupWorktree = repo.lookupWorktree(worktreeName);
|
||||
final lookedupWorktree = Worktree.lookup(repo: repo, name: worktreeName);
|
||||
|
||||
expect(lookedupWorktree.name, worktreeName);
|
||||
expect(lookedupWorktree.path, contains('worktree'));
|
||||
|
@ -127,7 +136,8 @@ void main() {
|
|||
});
|
||||
|
||||
test('locks and unlocks worktree', () {
|
||||
final worktree = repo.createWorktree(
|
||||
final worktree = Worktree.create(
|
||||
repo: repo,
|
||||
name: worktreeName,
|
||||
path: worktreeDir.path,
|
||||
);
|
||||
|
@ -145,7 +155,8 @@ void main() {
|
|||
test('prunes worktree', () {
|
||||
expect(repo.worktrees, <String>[]);
|
||||
|
||||
final worktree = repo.createWorktree(
|
||||
final worktree = Worktree.create(
|
||||
repo: repo,
|
||||
name: worktreeName,
|
||||
path: worktreeDir.path,
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue