|
13 | 13 | #import "QuickSpec+GTFixtures.h"
|
14 | 14 |
|
15 | 15 | // Helper to quickly create commits
|
16 |
| -GTCommit *(^createCommitInRepository)(NSString *, NSData *, NSString *, GTRepository *) = ^(NSString *message, NSData *fileData, NSString *fileName, GTRepository *repo) { |
| 16 | +GTCommit *(^createCommitInRepository)(NSString *, NSData *, NSString *, GTRepository *) = ^ GTCommit * (NSString *message, NSData *fileData, NSString *fileName, GTRepository *repo) { |
17 | 17 | GTTreeBuilder *treeBuilder = [[GTTreeBuilder alloc] initWithTree:nil error:nil];
|
18 | 18 | [treeBuilder addEntryWithData:fileData fileName:fileName fileMode:GTFileModeBlob error:nil];
|
19 | 19 |
|
|
26 | 26 | [commitEnum pushSHA:[headReference targetSHA] error:nil];
|
27 | 27 | GTCommit *parent = [commitEnum nextObject];
|
28 | 28 |
|
29 |
| - GTCommit *testCommit = [repo createCommitWithTree:testTree message:message parents:@[parent] updatingReferenceNamed:headReference.name error:nil]; |
| 29 | + GTCommit *testCommit = [repo createCommitWithTree:testTree message:message parents:@[ parent ] updatingReferenceNamed:headReference.name error:nil]; |
30 | 30 | expect(testCommit).notTo(beNil());
|
31 | 31 |
|
32 | 32 | return testCommit;
|
33 | 33 | };
|
34 | 34 |
|
| 35 | +GTBranch *(^localBranchWithName)(NSString *, GTRepository *) = ^ GTBranch * (NSString *branchName, GTRepository *repo) { |
| 36 | + NSString *reference = [GTBranch.localNamePrefix stringByAppendingString:branchName]; |
| 37 | + NSArray *branches = [repo branchesWithPrefix:reference error:NULL]; |
| 38 | + expect(branches).notTo(beNil()); |
| 39 | + expect(@(branches.count)).to(equal(@1)); |
| 40 | + expect(((GTBranch *)branches[0]).shortName).to(equal(branchName)); |
| 41 | + |
| 42 | + return branches[0]; |
| 43 | +}; |
| 44 | + |
35 | 45 | #pragma mark - GTRemotePushSpec
|
36 | 46 |
|
37 | 47 | QuickSpecBegin(GTRemotePushSpec)
|
|
43 | 53 | __block GTRemote *remote;
|
44 | 54 | __block NSURL *remoteRepoURL;
|
45 | 55 | __block NSURL *localRepoURL;
|
46 |
| - __block GTBranch *masterBranch; |
47 |
| - __block GTBranch *remoteMasterBranch; |
48 |
| - __block NSError *error = nil; |
| 56 | + __block NSError *error; |
49 | 57 |
|
50 | 58 | beforeEach(^{
|
51 | 59 | // This repo is not really "bare"
|
|
64 | 72 | expect(remoteRepo).notTo(beNil());
|
65 | 73 | expect(@(remoteRepo.isBare)).to(beTruthy()); // that's better
|
66 | 74 |
|
67 |
| - // Get the remote master branch |
68 |
| - NSArray *remoteBranches = [remoteRepo localBranchesWithError:&error]; |
69 |
| - expect(error).to(beNil()); |
70 |
| - expect(remoteBranches).notTo(beNil()); |
71 |
| - expect(@(remoteBranches.count)).to(beGreaterThanOrEqualTo(@1)); |
72 |
| - remoteMasterBranch = remoteBranches[0]; |
73 |
| - expect(@([remoteMasterBranch numberOfCommitsWithError:NULL])).to(equal(@3)); |
74 |
| - |
75 |
| - NSURL *localRepoURL = [remoteRepoURL.URLByDeletingLastPathComponent URLByAppendingPathComponent:@"local_push_repo"]; |
| 75 | + localRepoURL = [remoteRepoURL.URLByDeletingLastPathComponent URLByAppendingPathComponent:@"local_push_repo"]; |
76 | 76 | expect(localRepoURL).notTo(beNil());
|
77 | 77 |
|
78 |
| - // Ensure repo destination is clear before clone |
79 |
| - [NSFileManager.defaultManager removeItemAtURL:localRepoURL error:NULL]; |
80 |
| - |
81 | 78 | // Local clone for testing pushes
|
82 | 79 | localRepo = [GTRepository cloneFromURL:remoteRepoURL toWorkingDirectory:localRepoURL options:nil error:&error transferProgressBlock:NULL checkoutProgressBlock:NULL];
|
83 | 80 |
|
|
92 | 89 |
|
93 | 90 | remote = configuration.remotes[0];
|
94 | 91 | expect(remote.name).to(equal(@"origin"));
|
95 |
| - |
96 |
| - NSArray *branches = [localRepo localBranchesWithError:&error]; |
97 |
| - expect(error).to(beNil()); |
98 |
| - expect(branches).notTo(beNil()); |
99 |
| - expect(@(branches.count)).to(beGreaterThanOrEqualTo(@1)); |
100 |
| - |
101 |
| - masterBranch = branches[0]; |
102 |
| - expect(masterBranch.shortName).to(equal(@"master")); |
103 |
| - expect(@([masterBranch numberOfCommitsWithError:NULL])).to(equal(@3)); |
104 | 92 | });
|
105 | 93 |
|
106 | 94 | afterEach(^{
|
107 | 95 | [NSFileManager.defaultManager removeItemAtURL:remoteRepoURL error:NULL];
|
108 | 96 | [NSFileManager.defaultManager removeItemAtURL:localRepoURL error:NULL];
|
| 97 | + error = NULL; |
109 | 98 | });
|
110 | 99 |
|
111 | 100 | context(@"when the local and remote branches are in sync", ^{
|
112 | 101 | it(@"should push no commits", ^{
|
| 102 | + GTBranch *masterBranch = localBranchWithName(@"master", localRepo); |
| 103 | + expect(@([masterBranch numberOfCommitsWithError:NULL])).to(equal(@3)); |
| 104 | + |
| 105 | + GTBranch *remoteMasterBranch = localBranchWithName(@"master", remoteRepo); |
113 | 106 | expect(@([remoteMasterBranch numberOfCommitsWithError:NULL])).to(equal(@3));
|
114 | 107 |
|
115 | 108 | // Push
|
|
121 | 114 | expect(@(result)).to(beTruthy());
|
122 | 115 | expect(@(transferProgressed)).to(beFalse()); // Local transport doesn't currently call progress callbacks
|
123 | 116 |
|
124 |
| - // Same number of commits after push |
| 117 | + // Same number of commits after push, refresh branch first |
| 118 | + remoteMasterBranch = localBranchWithName(@"master", remoteRepo); |
125 | 119 | expect(@([remoteMasterBranch numberOfCommitsWithError:NULL])).to(equal(@3));
|
126 | 120 | });
|
127 | 121 | });
|
128 | 122 |
|
129 |
| - context(@"when there is a new local commit", ^{ |
130 |
| - it(@"should push one commit", ^{ |
131 |
| - // Create a new commit in the master repo |
132 |
| - NSString *testData = @"Test"; |
133 |
| - NSString *fileName = @"test.txt"; |
134 |
| - GTCommit *testCommit = createCommitInRepository(@"Test commit", [testData dataUsingEncoding:NSUTF8StringEncoding], fileName, localRepo); |
135 |
| - expect(testCommit).notTo(beNil()); |
| 123 | + it(@"can push one commit", ^{ |
| 124 | + // Create a new commit in the master repo |
| 125 | + NSString *testData = @"Test"; |
| 126 | + NSString *fileName = @"test.txt"; |
| 127 | + GTCommit *testCommit = createCommitInRepository(@"Test commit", [testData dataUsingEncoding:NSUTF8StringEncoding], fileName, localRepo); |
| 128 | + expect(testCommit).notTo(beNil()); |
136 | 129 |
|
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)); |
| 130 | + // Refetch master branch to ensure the commit count is accurate |
| 131 | + GTBranch *masterBranch = localBranchWithName(@"master", localRepo); |
| 132 | + expect(@([masterBranch numberOfCommitsWithError:NULL])).to(equal(@4)); |
140 | 133 |
|
141 |
| - // Number of commits on remote before push |
142 |
| - expect(@([remoteMasterBranch numberOfCommitsWithError:NULL])).to(equal(@3)); |
| 134 | + // Number of commits on remote before push |
| 135 | + GTBranch *remoteMasterBranch = localBranchWithName(@"master", remoteRepo); |
| 136 | + expect(@([remoteMasterBranch numberOfCommitsWithError:NULL])).to(equal(@3)); |
143 | 137 |
|
144 |
| - // Push |
145 |
| - __block BOOL transferProgressed = NO; |
146 |
| - BOOL result = [localRepo pushBranch:masterBranch toRemote:remote withOptions:nil error:&error progress:^(unsigned int current, unsigned int total, size_t bytes, BOOL *stop) { |
147 |
| - transferProgressed = YES; |
148 |
| - }]; |
149 |
| - expect(error).to(beNil()); |
150 |
| - expect(@(result)).to(beTruthy()); |
151 |
| - expect(@(transferProgressed)).to(beFalse()); // Local transport doesn't currently call progress callbacks |
| 138 | + // Push |
| 139 | + __block BOOL transferProgressed = NO; |
| 140 | + BOOL result = [localRepo pushBranch:masterBranch toRemote:remote withOptions:nil error:&error progress:^(unsigned int current, unsigned int total, size_t bytes, BOOL *stop) { |
| 141 | + transferProgressed = YES; |
| 142 | + }]; |
| 143 | + expect(error).to(beNil()); |
| 144 | + expect(@(result)).to(beTruthy()); |
| 145 | + expect(@(transferProgressed)).to(beFalse()); // Local transport doesn't currently call progress callbacks |
152 | 146 |
|
153 |
| - // Refetch master branch to ensure the commit count is accurate |
154 |
| - remoteMasterBranch = [remoteRepo localBranchesWithError:NULL][0]; |
| 147 | + // Refetch master branch to ensure the commit count is accurate |
| 148 | + remoteMasterBranch = localBranchWithName(@"master", remoteRepo); |
155 | 149 |
|
156 |
| - // Number of commits on remote after push |
157 |
| - expect(@([remoteMasterBranch numberOfCommitsWithError:NULL])).to(equal(@4)); |
| 150 | + // Number of commits on remote after push |
| 151 | + expect(@([remoteMasterBranch numberOfCommitsWithError:NULL])).to(equal(@4)); |
158 | 152 |
|
159 |
| - // Verify commit is in remote |
160 |
| - GTCommit *pushedCommit = [remoteRepo lookUpObjectByOID:testCommit.OID objectType:GTObjectTypeCommit error:&error]; |
161 |
| - expect(error).to(beNil()); |
162 |
| - expect(pushedCommit).notTo(beNil()); |
163 |
| - expect(pushedCommit.OID).to(equal(testCommit.OID)); |
| 153 | + // Verify commit is in remote |
| 154 | + GTCommit *pushedCommit = [remoteRepo lookUpObjectByOID:testCommit.OID objectType:GTObjectTypeCommit error:&error]; |
| 155 | + expect(error).to(beNil()); |
| 156 | + expect(pushedCommit).notTo(beNil()); |
| 157 | + expect(pushedCommit.OID).to(equal(testCommit.OID)); |
164 | 158 |
|
165 |
| - GTTreeEntry *entry = [[pushedCommit tree] entryWithName:fileName]; |
166 |
| - expect(entry).notTo(beNil()); |
| 159 | + GTTreeEntry *entry = [[pushedCommit tree] entryWithName:fileName]; |
| 160 | + expect(entry).notTo(beNil()); |
167 | 161 |
|
168 |
| - GTBlob *fileData = (GTBlob *)[entry GTObject:&error]; |
169 |
| - expect(error).to(beNil()); |
170 |
| - expect(fileData).notTo(beNil()); |
171 |
| - expect(fileData.content).to(equal(testData)); |
172 |
| - }); |
| 162 | + GTBlob *fileData = (GTBlob *)[entry GTObject:&error]; |
| 163 | + expect(error).to(beNil()); |
| 164 | + expect(fileData).notTo(beNil()); |
| 165 | + expect(fileData.content).to(equal(testData)); |
| 166 | + }); |
| 167 | + |
| 168 | + pending(@"can push two branches", ^{ |
| 169 | + GTBranch *masterBranch = localBranchWithName(@"master", localRepo); |
| 170 | + GTBranch *remoteMasterBranch = localBranchWithName(@"master", remoteRepo); |
| 171 | + expect(@([remoteMasterBranch numberOfCommitsWithError:NULL])).to(equal(@3)); |
| 172 | + |
| 173 | + // Push |
| 174 | + __block BOOL transferProgressed = NO; |
| 175 | + BOOL result = [localRepo pushBranch:masterBranch toRemote:remote withOptions:nil error:&error progress:^(unsigned int current, unsigned int total, size_t bytes, BOOL *stop) { |
| 176 | + transferProgressed = YES; |
| 177 | + }]; |
| 178 | + expect(error).to(beNil()); |
| 179 | + expect(@(result)).to(beTruthy()); |
| 180 | + expect(@(transferProgressed)).to(beFalse()); // Local transport doesn't currently call progress callbacks |
| 181 | + |
| 182 | + // Same number of commits after push |
| 183 | + expect(@([remoteMasterBranch numberOfCommitsWithError:NULL])).to(equal(@3)); |
173 | 184 | });
|
174 | 185 | });
|
175 | 186 |
|
|
0 commit comments