Skip to content

Commit 5afd124

Browse files
author
Ben Chatelain
committed
Add commit count expectations
1 parent 96b6365 commit 5afd124

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

ObjectiveGitTests/GTRemotePushSpec.m

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
__block NSURL *remoteRepoFileURL;
2323
__block NSURL *localRepoURL;
2424
__block GTBranch *masterBranch;
25+
__block GTBranch *remoteMasterBranch;
2526

2627
beforeEach(^{
2728
NSError *error = nil;
@@ -39,6 +40,14 @@
3940
expect(remoteRepo).notTo(beNil());
4041
expect(@(remoteRepo.isBare)).to(beTruthy()); // that's better
4142

43+
NSArray *remoteBranches = [remoteRepo localBranchesWithError:&error];
44+
expect(error).to(beNil());
45+
expect(remoteBranches).notTo(beNil());
46+
expect(@(remoteBranches.count)).to(beGreaterThanOrEqualTo(@1));
47+
48+
remoteMasterBranch = remoteBranches[0];
49+
expect(@([remoteMasterBranch numberOfCommitsWithError:NULL])).to(equal(@3));
50+
4251
NSURL *remoteRepoFileURL = remoteRepo.gitDirectoryURL;
4352
expect(remoteRepoFileURL).notTo(beNil());
4453
NSURL *localRepoURL = [remoteRepoFileURL.URLByDeletingLastPathComponent URLByAppendingPathComponent:@"localpushrepo"];
@@ -62,13 +71,14 @@
6271
remote = configuration.remotes[0];
6372
expect(remote.name).to(equal(@"origin"));
6473

65-
// TODO: Verify tracking between local and remote branches
66-
NSArray *branches = [localRepo allBranchesWithError:&error];
74+
NSArray *branches = [localRepo localBranchesWithError:&error];
6775
expect(error).to(beNil());
6876
expect(branches).notTo(beNil());
77+
expect(@(branches.count)).to(beGreaterThanOrEqualTo(@1));
6978

7079
masterBranch = branches[0];
7180
expect(masterBranch.shortName).to(equal(@"master"));
81+
expect(@([masterBranch numberOfCommitsWithError:NULL])).to(equal(@3));
7282
});
7383

7484
afterEach(^{
@@ -101,13 +111,18 @@
101111
it(@"pushes nothing when the branch on local and remote are in sync", ^{
102112
NSError *error = nil;
103113

114+
expect(@([remoteMasterBranch numberOfCommitsWithError:NULL])).to(equal(@3));
115+
104116
__block BOOL transferProgressed = NO;
105117
BOOL result = [localRepo pushBranch:masterBranch toRemote:remote withOptions:nil error:&error progress:^(unsigned int current, unsigned int total, size_t bytes, BOOL *stop) {
106118
transferProgressed = YES;
107119
}];
108120
expect(error).to(beNil());
109121
expect(@(result)).to(beTruthy());
110122
expect(@(transferProgressed)).to(beFalse()); // Local transport doesn't currently call progress callbacks
123+
124+
// Same number of commits after push
125+
expect(@([remoteMasterBranch numberOfCommitsWithError:NULL])).to(equal(@3));
111126
});
112127

113128
it(@"pushes a new local commit to the remote", ^{
@@ -119,6 +134,13 @@
119134
GTCommit *testCommit = createCommitInRepository(@"Test commit", [testData dataUsingEncoding:NSUTF8StringEncoding], fileName, localRepo);
120135
expect(testCommit).notTo(beNil());
121136

137+
// Refetch master branch to ensure the commit count is accurate
138+
masterBranch = [localRepo localBranchesWithError:NULL][0];
139+
expect(@([masterBranch numberOfCommitsWithError:NULL])).to(equal(@4));
140+
141+
// Number of commits on remote before push
142+
expect(@([remoteMasterBranch numberOfCommitsWithError:NULL])).to(equal(@3));
143+
122144
// Push
123145
__block BOOL transferProgressed = NO;
124146
BOOL result = [localRepo pushBranch:masterBranch toRemote:remote withOptions:nil error:&error progress:^(unsigned int current, unsigned int total, size_t bytes, BOOL *stop) {
@@ -128,6 +150,12 @@
128150
expect(@(result)).to(beTruthy());
129151
expect(@(transferProgressed)).to(beFalse()); // Local transport doesn't currently call progress callbacks
130152

153+
// Refetch master branch to ensure the commit count is accurate
154+
remoteMasterBranch = [remoteRepo localBranchesWithError:NULL][0];
155+
156+
// Number of commits on remote after push
157+
expect(@([remoteMasterBranch numberOfCommitsWithError:NULL])).to(equal(@4));
158+
131159
// Verify commit is in remote
132160
GTCommit *pushedCommit = [remoteRepo lookUpObjectByOID:testCommit.OID objectType:GTObjectTypeCommit error:&error];
133161
expect(error).to(beNil());

0 commit comments

Comments
 (0)