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