feat(branch): add more bindings and api methods (#13)

This commit is contained in:
Aleksey Kulikov 2021-12-03 11:17:48 +03:00 committed by GitHub
parent a3f2dcc211
commit 33d2750d38
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 356 additions and 17 deletions

View file

@ -26,7 +26,7 @@ void main() {
group('Branch', () {
test('returns a list of all branches', () {
const branchesExpected = ['feature', 'master'];
const branchesExpected = ['feature', 'master', 'origin/master'];
final branches = repo.branches;
for (var i = 0; i < branches.length; i++) {
@ -46,7 +46,13 @@ void main() {
});
test('returns a list of remote branches', () {
expect(repo.branchesRemote, <Branch>[]);
const branchesExpected = ['origin/master'];
final branches = repo.branchesRemote;
for (var i = 0; i < branches.length; i++) {
expect(branches[i].name, branchesExpected[i]);
branches[i].free();
}
});
test('throws when trying to return list and error occurs', () {
@ -121,6 +127,113 @@ void main() {
expect(() => nullBranch.name, throwsA(isA<LibGit2Error>()));
});
test('returns remote name of a remote-tracking branch', () {
final branch = repo.branchesRemote.first;
expect(branch.remoteName, 'origin');
branch.free();
});
test(
'throws when getting remote name of a remote-tracking branch and '
'error occurs', () {
final branch = repo.lookupBranch(name: 'master');
expect(() => branch.remoteName, throwsA(isA<LibGit2Error>()));
});
test('returns upstream of a local branch', () {
final branch = repo.lookupBranch(name: 'master');
final upstream = branch.upstream;
expect(upstream.isRemote, true);
expect(upstream.name, 'refs/remotes/origin/master');
upstream.free();
branch.free();
});
test('throws when trying to get upstream of a remote branch', () {
final branch = repo.branchesRemote.first;
expect(() => branch.upstream, throwsA(isA<LibGit2Error>()));
branch.free();
});
test('successfully sets upstream of a branch', () {
final branch = repo.lookupBranch(name: 'master');
var upstream = branch.upstream;
expect(upstream.name, 'refs/remotes/origin/master');
final ref = repo.createReference(
name: 'refs/remotes/origin/new',
target: 'refs/heads/master',
);
branch.setUpstream(ref.shorthand);
upstream = branch.upstream;
expect(upstream.name, 'refs/remotes/origin/new');
ref.free();
upstream.free();
branch.free();
});
test('successfully unsets upstream of a branch', () {
final branch = repo.lookupBranch(name: 'master');
final upstream = branch.upstream;
expect(upstream.name, 'refs/remotes/origin/master');
branch.setUpstream(null);
expect(() => branch.upstream, throwsA(isA<LibGit2Error>()));
upstream.free();
branch.free();
});
test('throws when trying to set upstream of a branch and error occurs', () {
final branch = repo.lookupBranch(name: 'master');
expect(
() => branch.setUpstream('some/upstream'),
throwsA(isA<LibGit2Error>()),
);
branch.free();
});
test('returns upstream name of a local branch', () {
final branch = repo.lookupBranch(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');
expect(() => branch.upstreamName, throwsA(isA<LibGit2Error>()));
branch.free();
});
test('returns upstream remote of a local branch', () {
final branch = repo.lookupBranch(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;
expect(() => branch.upstreamName, throwsA(isA<LibGit2Error>()));
branch.free();
});
test('returns upstream merge of a local branch', () {
final branch = repo.lookupBranch(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;
expect(() => branch.upstreamMerge, throwsA(isA<LibGit2Error>()));
branch.free();
});
group('create()', () {
test('successfully creates', () {
final commit = repo.lookupCommit(lastCommit);
@ -128,7 +241,7 @@ void main() {
final branch = repo.createBranch(name: 'testing', target: commit);
final branches = repo.branches;
expect(repo.branches.length, 3);
expect(repo.branches.length, 4);
expect(branch.target, lastCommit);
for (final branch in branches) {
@ -194,7 +307,7 @@ void main() {
final branch = repo.lookupBranch(name: 'renamed');
final branches = repo.branches;
expect(branches.length, 2);
expect(branches.length, 3);
expect(
() => repo.lookupBranch(name: 'feature'),
throwsA(isA<LibGit2Error>()),