Skip to content

Commit e99a62e

Browse files
committed
Check if notes reference exists before pushing it
1 parent 947058d commit e99a62e

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

ObjectiveGit/GTRepository+RemoteOperations.m

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,11 @@ - (BOOL)pushBranches:(NSArray *)branches toRemote:(GTRemote *)remote withOptions
204204

205205
// Also push the notes reference, if needed.
206206
if (referenceName != nil) {
207-
[refspecs addObject:[NSString stringWithFormat:@"%@:%@", referenceName, referenceName]];
207+
// but check whether the reference exists for the repo, otherwise, our push will fail
208+
GTReference* notesRef = [self lookUpReferenceWithName:referenceName error:nil];
209+
210+
if (notesRef != nil)
211+
[refspecs addObject:[NSString stringWithFormat:@"%@:%@", referenceName, referenceName]];
208212
}
209213

210214
return [self pushRefspecs:refspecs toRemote:remote withOptions:options error:error progress:progressBlock];
@@ -219,6 +223,11 @@ - (BOOL)pushNotes:(NSString *)noteRef toRemote:(GTRemote *)remote withOptions:(N
219223
if (noteRef == nil) return NO;
220224
}
221225

226+
GTReference* notesReference = [self lookUpReferenceWithName:noteRef error:error];
227+
228+
if (notesReference == nil)
229+
return NO; // error will be pre-filled with the lookUpReferenceWithName call
230+
222231
return [self pushRefspecs:@[[NSString stringWithFormat:@"%@:%@", noteRef, noteRef]] toRemote:remote withOptions:options error:error progress:progressBlock];
223232
}
224233

0 commit comments

Comments
 (0)