Skip to content

Commit fe13986

Browse files
committed
Added support for [GTRepository pushNotes:...]
1 parent 47dc0fc commit fe13986

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

ObjectiveGit/GTRepository+RemoteOperations.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,20 @@ typedef NS_ENUM(NSInteger, GTFetchPruneOption) {
9797
/// will point to an error describing what happened).
9898
- (BOOL)pushBranches:(NSArray<GTBranch *> *)branches toRemote:(GTRemote *)remote withOptions:(nullable NSDictionary *)options error:(NSError **)error progress:(nullable void (^)(unsigned int current, unsigned int total, size_t bytes, BOOL *stop))progressBlock;
9999

100+
/// Push a given Git notes reference name to a remote.
101+
///
102+
/// noteRef - Name of the notes reference. If NULL, will default to whatever the default is (e.g. "refs/notes/commits")
103+
/// remote - The remote to push to. Must not be nil.
104+
/// options - Options applied to the push operation. Can be NULL.
105+
/// Recognized options are:
106+
/// `GTRepositoryRemoteOptionsCredentialProvider`
107+
/// error - The error if one occurred. Can be NULL.
108+
/// progressBlock - An optional callback for monitoring progress. May be NULL.
109+
///
110+
/// Returns YES if the push was successful, NO otherwise (and `error`, if provided,
111+
/// will point to an error describing what happened).
112+
- (BOOL)pushNotes:(nullable NSString *)noteRef toRemote:(GTRemote *)remote withOptions:(nullable NSDictionary *)options error:(NSError **)error progress:(nullable void (^)(unsigned int current, unsigned int total, size_t bytes, BOOL *stop))progressBlock;
113+
100114
/// Delete a remote branch
101115
///
102116
/// branch - The branch to push. Must not be nil.

ObjectiveGit/GTRepository+RemoteOperations.m

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
#import "git2/errors.h"
2323
#import "git2/remote.h"
24+
#import "git2/notes.h"
25+
#import "git2/buffer.h"
2426

2527
NSString *const GTRepositoryRemoteOptionsCredentialProvider = @"GTRepositoryRemoteOptionsCredentialProvider";
2628
NSString *const GTRepositoryRemoteOptionsFetchPrune = @"GTRepositoryRemoteOptionsFetchPrune";
@@ -198,6 +200,28 @@ - (BOOL)pushBranches:(NSArray *)branches toRemote:(GTRemote *)remote withOptions
198200
return [self pushRefspecs:refspecs toRemote:remote withOptions:options error:error progress:progressBlock];
199201
}
200202

203+
- (BOOL)pushNotes:(NSString *)noteRef toRemote:(GTRemote *)remote withOptions:(NSDictionary *)options error:(NSError **)error progress:(GTRemotePushTransferProgressBlock)progressBlock {
204+
NSParameterAssert(remote != nil);
205+
206+
if (noteRef == nil) {
207+
git_buf default_ref_name = { 0 };
208+
int gitErr = git_note_default_ref(&default_ref_name, self.git_repository);
209+
if (gitErr != GIT_OK) {
210+
git_buf_free(&default_ref_name);
211+
212+
if (error != NULL) {
213+
*error = [NSError git_errorFor:gitErr description:@"Unable to get default git notes reference name"];
214+
}
215+
216+
return NO;
217+
}
218+
219+
noteRef = [NSString stringWithUTF8String:default_ref_name.ptr];
220+
}
221+
222+
return [self pushRefspecs:@[[NSString stringWithFormat:@"%@:%@", noteRef, noteRef]] toRemote:remote withOptions:options error:error progress:progressBlock];
223+
}
224+
201225
#pragma mark - Deletion (Public)
202226
- (BOOL)deleteBranch:(GTBranch *)branch fromRemote:(GTRemote *)remote withOptions:(NSDictionary *)options error:(NSError **)error {
203227
NSParameterAssert(branch != nil);

0 commit comments

Comments
 (0)