@@ -179,14 +179,21 @@ - (BOOL)rename:(NSString *)name force:(BOOL)force error:(NSError **)error {
179179 return NO ;
180180 }
181181
182- _reference = [[GTReference alloc ] initWithGitReference: git_ref repository: self .repository];
182+ GTReference *renamedRef = [[GTReference alloc ] initWithGitReference: git_ref repository: self .repository];
183+ NSAssert (renamedRef, @" Unable to allocate renamed ref" );
184+ _reference = renamedRef;
183185
184186 return YES ;
185187}
186188
187189- (GTBranch *)trackingBranchWithError : (NSError **)error success : (BOOL *)success {
190+ BOOL underSuccess = NO ;
191+ if (success == NULL ) {
192+ success = &underSuccess;
193+ }
194+
188195 if (self.branchType == GTBranchTypeRemote) {
189- if (success != NULL ) *success = YES ;
196+ *success = YES ;
190197 return self;
191198 }
192199
@@ -195,25 +202,32 @@ - (GTBranch *)trackingBranchWithError:(NSError **)error success:(BOOL *)success
195202
196203 // GIT_ENOTFOUND means no tracking branch found.
197204 if (gitError == GIT_ENOTFOUND) {
198- if (success != NULL ) *success = YES ;
205+ *success = YES ;
199206 return nil ;
200207 }
201208
202209 if (gitError != GIT_OK) {
203- if (success != NULL ) *success = NO ;
210+ *success = NO ;
204211 if (error != NULL ) *error = [NSError git_errorFor: gitError description: @" Failed to create reference to tracking branch from %@ " , self ];
205212 return nil ;
206213 }
207214
208215 if (trackingRef == NULL ) {
209- if (success != NULL ) *success = NO ;
216+ *success = NO ;
210217 if (error != NULL ) *error = [NSError git_errorFor: gitError description: @" Got a NULL remote ref for %@ " , self ];
211218 return nil ;
212219 }
213220
214- if (success != NULL ) *success = YES ;
221+ GTReference *upsteamRef = [[GTReference alloc ] initWithGitReference: trackingRef repository: self .repository];
222+ if (upsteamRef == nil ) {
223+ *success = NO ;
224+ if (error != NULL ) *error = [NSError git_errorFor: GIT_ERROR description: @" Failed to allocate upstream ref" ];
225+ return nil ;
226+ }
227+
228+ *success = YES ;
215229
216- return [[self class ] branchWithReference: [[GTReference alloc ] initWithGitReference: trackingRef repository: self .repository] ];
230+ return [[self class ] branchWithReference: upsteamRef ];
217231}
218232
219233- (BOOL )updateTrackingBranch : (GTBranch *)trackingBranch error : (NSError **)error {
0 commit comments