diff options
| author | Byoungchan Lee <[email protected]> | 2021-02-04 11:58:31 +0900 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-02-03 18:58:31 -0800 |
| commit | 73d97b9bbe7c9a7747af20aad670baba33b5e390 (patch) | |
| tree | 63f01f310fbe255a5c67978677a75f0a90d04d1f /remote.go | |
| parent | 07147a8ea8ccf216fa490e7ed4ec84e7c5f5d9ee (diff) | |
Support git_remote_create_with_opts (#733)
Closes #645
Diffstat (limited to 'remote.go')
| -rw-r--r-- | remote.go | 81 |
1 files changed, 81 insertions, 0 deletions
@@ -18,6 +18,23 @@ import ( "unsafe" ) +// RemoteCreateOptionsFlag is Remote creation options flags +type RemoteCreateOptionsFlag uint + +const ( + // Ignore the repository apply.insteadOf configuration + RemoteCreateSkipInsteadof RemoteCreateOptionsFlag = C.GIT_REMOTE_CREATE_SKIP_INSTEADOF + // Don't build a fetchspec from the name if none is set + RemoteCreateSkipDefaultFetchspec RemoteCreateOptionsFlag = C.GIT_REMOTE_CREATE_SKIP_DEFAULT_FETCHSPEC +) + +// RemoteCreateOptions contains options for creating a remote +type RemoteCreateOptions struct { + Name string + FetchSpec string + Flags RemoteCreateOptionsFlag +} + type TransferProgress struct { TotalObjects uint IndexedObjects uint @@ -539,6 +556,28 @@ func (c *RemoteCollection) Create(name string, url string) (*Remote, error) { return remote, nil } +//CreateWithOptions Creates a repository object with extended options. +func (c *RemoteCollection) CreateWithOptions(url string, option *RemoteCreateOptions) (*Remote, error) { + remote := &Remote{repo: c.repo} + + curl := C.CString(url) + defer C.free(unsafe.Pointer(curl)) + + runtime.LockOSThread() + defer runtime.UnlockOSThread() + + copts := populateRemoteCreateOptions(&C.git_remote_create_options{}, option, c.repo) + defer freeRemoteCreateOptions(copts) + ret := C.git_remote_create_with_opts(&remote.ptr, curl, copts) + runtime.KeepAlive(c.repo) + if ret < 0 { + return nil, MakeGitError(ret) + } + + runtime.SetFinalizer(remote, (*Remote).Free) + return remote, nil +} + func (c *RemoteCollection) Delete(name string) error { cname := C.CString(name) defer C.free(unsafe.Pointer(cname)) @@ -1027,3 +1066,45 @@ func (o *Remote) Prune(callbacks *RemoteCallbacks) error { } return nil } + +// DefaultApplyOptions returns default options for remote create +func DefaultRemoteCreateOptions() (*RemoteCreateOptions, error) { + runtime.LockOSThread() + defer runtime.UnlockOSThread() + + opts := C.git_remote_create_options{} + ecode := C.git_remote_create_options_init(&opts, C.GIT_REMOTE_CREATE_OPTIONS_VERSION) + if ecode < 0 { + return nil, MakeGitError(ecode) + } + + return &RemoteCreateOptions{ + Flags: RemoteCreateOptionsFlag(opts.flags), + }, nil +} + +func populateRemoteCreateOptions(copts *C.git_remote_create_options, opts *RemoteCreateOptions, repo *Repository) *C.git_remote_create_options { + C.git_remote_create_options_init(copts, C.GIT_REMOTE_CREATE_OPTIONS_VERSION) + if opts == nil { + return nil + } + + var cRepository *C.git_repository + if repo != nil { + cRepository = repo.ptr + } + copts.repository = cRepository + copts.name = C.CString(opts.Name) + copts.fetchspec = C.CString(opts.FetchSpec) + copts.flags = C.uint(opts.Flags) + + return copts +} + +func freeRemoteCreateOptions(ptr *C.git_remote_create_options) { + if ptr == nil { + return + } + C.free(unsafe.Pointer(ptr.name)) + C.free(unsafe.Pointer(ptr.fetchspec)) +} |
