@@ -153,6 +153,9 @@ type HostkeyCertificate struct {
153
153
}
154
154
155
155
type PushOptions struct {
156
+ // Callbacks to use for this push operation
157
+ RemoteCallbacks RemoteCallbacks
158
+
156
159
PbParallelism uint
157
160
}
158
161
@@ -211,7 +214,9 @@ func credentialsCallback(_cred **C.git_cred, _url *C.char, _username_from_url *C
211
214
url := C .GoString (_url )
212
215
username_from_url := C .GoString (_username_from_url )
213
216
ret , cred := callbacks .CredentialsCallback (url , username_from_url , (CredType )(allowed_types ))
214
- * _cred = cred .ptr
217
+ if cred != nil {
218
+ * _cred = cred .ptr
219
+ }
215
220
return int (ret )
216
221
}
217
222
@@ -591,6 +596,17 @@ func populateFetchOptions(options *C.git_fetch_options, opts *FetchOptions) {
591
596
options .download_tags = C .git_remote_autotag_option_t (opts .DownloadTags )
592
597
}
593
598
599
+ func populatePushOptions (options * C.git_push_options , opts * PushOptions ) {
600
+ C .git_push_init_options (options , C .GIT_PUSH_OPTIONS_VERSION )
601
+ if opts == nil {
602
+ return
603
+ }
604
+
605
+ options .pb_parallelism = C .uint (opts .PbParallelism )
606
+
607
+ populateRemoteCallbacks (& options .callbacks , & opts .RemoteCallbacks )
608
+ }
609
+
594
610
// Fetch performs a fetch operation. refspecs specifies which refspecs
595
611
// to use for this fetch, use an empty list to use the refspecs from
596
612
// the configuration; msg specifies what to use for the reflog
@@ -689,22 +705,19 @@ func (o *Remote) Ls(filterRefs ...string) ([]RemoteHead, error) {
689
705
}
690
706
691
707
func (o * Remote ) Push (refspecs []string , opts * PushOptions ) error {
692
- var copts C.git_push_options
693
- C .git_push_init_options (& copts , C .GIT_PUSH_OPTIONS_VERSION )
694
- if opts != nil {
695
- copts .pb_parallelism = C .uint (opts .PbParallelism )
696
- }
697
-
698
708
crefspecs := C.git_strarray {}
699
709
crefspecs .count = C .size_t (len (refspecs ))
700
710
crefspecs .strings = makeCStringsFromStrings (refspecs )
701
711
defer freeStrarray (& crefspecs )
702
712
713
+ var coptions C.git_push_options
714
+ populatePushOptions (& coptions , opts )
715
+ defer untrackCalbacksPayload (& coptions .callbacks )
716
+
703
717
runtime .LockOSThread ()
704
718
defer runtime .UnlockOSThread ()
705
- defer untrackCalbacksPayload (& copts .callbacks )
706
719
707
- ret := C .git_remote_push (o .ptr , & crefspecs , & copts )
720
+ ret := C .git_remote_push (o .ptr , & crefspecs , & coptions )
708
721
if ret < 0 {
709
722
return MakeGitError (ret )
710
723
}
0 commit comments