@@ -18,6 +18,23 @@ import (
1818 "unsafe"
1919)
2020
21+ // RemoteCreateOptionsFlag is Remote creation options flags
22+ type RemoteCreateOptionsFlag uint
23+
24+ const (
25+ // Ignore the repository apply.insteadOf configuration
26+ RemoteCreateSkipInsteadof RemoteCreateOptionsFlag = C .GIT_REMOTE_CREATE_SKIP_INSTEADOF
27+ // Don't build a fetchspec from the name if none is set
28+ RemoteCreateSkipDefaultFetchspec RemoteCreateOptionsFlag = C .GIT_REMOTE_CREATE_SKIP_DEFAULT_FETCHSPEC
29+ )
30+
31+ // RemoteCreateOptions contains options for creating a remote
32+ type RemoteCreateOptions struct {
33+ Name string
34+ FetchSpec string
35+ Flags RemoteCreateOptionsFlag
36+ }
37+
2138type TransferProgress struct {
2239 TotalObjects uint
2340 IndexedObjects uint
@@ -539,6 +556,28 @@ func (c *RemoteCollection) Create(name string, url string) (*Remote, error) {
539556 return remote , nil
540557}
541558
559+ //CreateWithOptions Creates a repository object with extended options.
560+ func (c * RemoteCollection ) CreateWithOptions (url string , option * RemoteCreateOptions ) (* Remote , error ) {
561+ remote := & Remote {repo : c .repo }
562+
563+ curl := C .CString (url )
564+ defer C .free (unsafe .Pointer (curl ))
565+
566+ runtime .LockOSThread ()
567+ defer runtime .UnlockOSThread ()
568+
569+ copts := populateRemoteCreateOptions (& C.git_remote_create_options {}, option , c .repo )
570+ defer freeRemoteCreateOptions (copts )
571+ ret := C .git_remote_create_with_opts (& remote .ptr , curl , copts )
572+ runtime .KeepAlive (c .repo )
573+ if ret < 0 {
574+ return nil , MakeGitError (ret )
575+ }
576+
577+ runtime .SetFinalizer (remote , (* Remote ).Free )
578+ return remote , nil
579+ }
580+
542581func (c * RemoteCollection ) Delete (name string ) error {
543582 cname := C .CString (name )
544583 defer C .free (unsafe .Pointer (cname ))
@@ -1027,3 +1066,45 @@ func (o *Remote) Prune(callbacks *RemoteCallbacks) error {
10271066 }
10281067 return nil
10291068}
1069+
1070+ // DefaultApplyOptions returns default options for remote create
1071+ func DefaultRemoteCreateOptions () (* RemoteCreateOptions , error ) {
1072+ runtime .LockOSThread ()
1073+ defer runtime .UnlockOSThread ()
1074+
1075+ opts := C.git_remote_create_options {}
1076+ ecode := C .git_remote_create_options_init (& opts , C .GIT_REMOTE_CREATE_OPTIONS_VERSION )
1077+ if ecode < 0 {
1078+ return nil , MakeGitError (ecode )
1079+ }
1080+
1081+ return & RemoteCreateOptions {
1082+ Flags : RemoteCreateOptionsFlag (opts .flags ),
1083+ }, nil
1084+ }
1085+
1086+ func populateRemoteCreateOptions (copts * C.git_remote_create_options , opts * RemoteCreateOptions , repo * Repository ) * C.git_remote_create_options {
1087+ C .git_remote_create_options_init (copts , C .GIT_REMOTE_CREATE_OPTIONS_VERSION )
1088+ if opts == nil {
1089+ return nil
1090+ }
1091+
1092+ var cRepository * C.git_repository
1093+ if repo != nil {
1094+ cRepository = repo .ptr
1095+ }
1096+ copts .repository = cRepository
1097+ copts .name = C .CString (opts .Name )
1098+ copts .fetchspec = C .CString (opts .FetchSpec )
1099+ copts .flags = C .uint (opts .Flags )
1100+
1101+ return copts
1102+ }
1103+
1104+ func freeRemoteCreateOptions (ptr * C.git_remote_create_options ) {
1105+ if ptr == nil {
1106+ return
1107+ }
1108+ C .free (unsafe .Pointer (ptr .name ))
1109+ C .free (unsafe .Pointer (ptr .fetchspec ))
1110+ }
0 commit comments