2121
2222#import " git2/errors.h"
2323#import " git2/remote.h"
24- #import " git2/push.h"
2524
2625NSString *const GTRepositoryRemoteOptionsCredentialProvider = @" GTRepositoryRemoteOptionsCredentialProvider" ;
2726
@@ -62,10 +61,10 @@ int GTRemotePushTransferProgressCallback(unsigned int current, unsigned int tota
6261 return (stop == YES ? GIT_EUSER : 0 );
6362}
6463
65- #pragma mark -
66- #pragma mark Fetch
64+ #pragma mark - Fetch
6765
6866- (BOOL )fetchRemote : (GTRemote *)remote withOptions : (NSDictionary *)options error : (NSError **)error progress : (GTRemoteFetchTransferProgressBlock)progressBlock {
67+
6968 GTCredentialProvider *credProvider = options[GTRepositoryRemoteOptionsCredentialProvider];
7069 GTRemoteConnectionInfo connectionInfo = {
7170 .credProvider = {credProvider},
@@ -79,14 +78,11 @@ - (BOOL)fetchRemote:(GTRemote *)remote withOptions:(NSDictionary *)options error
7978 .payload = &connectionInfo,
8079 };
8180
82- int gitError = git_remote_set_callbacks (remote.git_remote , &remote_callbacks);
83- if (gitError != GIT_OK) {
84- if (error != NULL ) *error = [NSError git_errorFor: gitError description: @" Failed to set callbacks on remote" ];
85- return NO ;
86- }
81+ git_fetch_options fetchOptions = GIT_FETCH_OPTIONS_INIT;
82+ fetchOptions.callbacks = remote_callbacks;
8783
8884 __block git_strarray refspecs;
89- gitError = git_remote_get_fetch_refspecs (&refspecs, remote.git_remote );
85+ int gitError = git_remote_get_fetch_refspecs (&refspecs, remote.git_remote );
9086 if (gitError != GIT_OK) {
9187 if (error != NULL ) *error = [NSError git_errorFor: gitError description: @" Failed to get fetch refspecs for remote" ];
9288 return NO ;
@@ -96,7 +92,9 @@ - (BOOL)fetchRemote:(GTRemote *)remote withOptions:(NSDictionary *)options error
9692 git_strarray_free (&refspecs);
9793 };
9894
99- gitError = git_remote_fetch (remote.git_remote , &refspecs, NULL );
95+ NSString *reflog_message = [NSString stringWithFormat: @" fetching remote %@ " , remote.name];
96+
97+ gitError = git_remote_fetch (remote.git_remote , &refspecs, &fetchOptions, reflog_message.UTF8String );
10098 if (gitError != GIT_OK) {
10199 if (error != NULL ) *error = [NSError git_errorFor: gitError description: @" Failed to fetch from remote" ];
102100 return NO ;
@@ -105,8 +103,7 @@ - (BOOL)fetchRemote:(GTRemote *)remote withOptions:(NSDictionary *)options error
105103 return YES ;
106104}
107105
108- #pragma mark -
109- #pragma mark Fetch Head enumeration
106+ #pragma mark - Fetch Head Enumeration
110107
111108typedef void (^GTRemoteEnumerateFetchHeadEntryBlock)(GTFetchHeadEntry *entry, BOOL *stop);
112109
@@ -210,6 +207,7 @@ - (BOOL)deleteBranch:(GTBranch *)branch fromRemote:(GTRemote *)remote withOption
210207#pragma mark - Push (Private)
211208
212209- (BOOL )pushRefspecs : (NSArray *)refspecs toRemote : (GTRemote *)remote withOptions : (NSDictionary *)options error : (NSError **)error progress : (GTRemotePushTransferProgressBlock)progressBlock {
210+
213211 int gitError;
214212 GTCredentialProvider *credProvider = options[GTRepositoryRemoteOptionsCredentialProvider];
215213
@@ -224,21 +222,13 @@ - (BOOL)pushRefspecs:(NSArray *)refspecs toRemote:(GTRemote *)remote withOptions
224222 remote_callbacks.transfer_progress = GTRemoteFetchTransferProgressCallback,
225223 remote_callbacks.payload = &connectionInfo,
226224
227- gitError = git_remote_set_callbacks (remote.git_remote , &remote_callbacks);
228- if (gitError != GIT_OK) {
229- if (error != NULL ) *error = [NSError git_errorFor: gitError description: @" Failed to set callbacks on remote" ];
230- return NO ;
231- }
232-
233- gitError = git_remote_connect (remote.git_remote , GIT_DIRECTION_PUSH);
225+ gitError = git_remote_connect (remote.git_remote , GIT_DIRECTION_PUSH, &remote_callbacks);
234226 if (gitError != GIT_OK) {
235227 if (error != NULL ) *error = [NSError git_errorFor: gitError description: @" Failed to connect remote" ];
236228 return NO ;
237229 }
238230 @onExit {
239231 git_remote_disconnect (remote.git_remote );
240- // Clear out callbacks by overwriting with an effectively empty git_remote_callbacks struct
241- git_remote_set_callbacks (remote.git_remote , &((git_remote_callbacks)GIT_REMOTE_CALLBACKS_INIT));
242232 };
243233
244234 git_push_options push_options = GIT_PUSH_OPTIONS_INIT;
@@ -257,7 +247,12 @@ - (BOOL)pushRefspecs:(NSArray *)refspecs toRemote:(GTRemote *)remote withOptions
257247 return NO ;
258248 }
259249
260- gitError = git_remote_update_tips (remote.git_remote , NULL );
250+ int update_fetchhead = 1 ;
251+ // Ignored for push
252+ git_remote_autotag_option_t download_tags = GIT_REMOTE_DOWNLOAD_TAGS_FALLBACK;
253+ NSString *reflog_message = [NSString stringWithFormat: @" pushing remote %@ " , remote.name];
254+
255+ gitError = git_remote_update_tips (remote.git_remote , &remote_callbacks, update_fetchhead, download_tags, reflog_message.UTF8String );
261256 if (gitError != GIT_OK) {
262257 if (error != NULL ) *error = [NSError git_errorFor: gitError description: @" Update tips failed" ];
263258 return NO ;
0 commit comments