Remote Refinements

- Fixed credentialsCallback return value for missing callback
- Added Remote Rename
- Added Remote Disconnect
This commit is contained in:
Mirko Nosenzo 2016-05-29 14:44:29 +02:00
parent 8eaae73f85
commit 393098522c
1 changed files with 27 additions and 1 deletions

View File

@ -215,7 +215,7 @@ func completionCallback(completion_type C.git_remote_completion_type, data unsaf
func credentialsCallback(_cred **C.git_cred, _url *C.char, _username_from_url *C.char, allowed_types uint, data unsafe.Pointer) int { func credentialsCallback(_cred **C.git_cred, _url *C.char, _username_from_url *C.char, allowed_types uint, data unsafe.Pointer) int {
callbacks, _ := pointerHandles.Get(data).(*RemoteCallbacks) callbacks, _ := pointerHandles.Get(data).(*RemoteCallbacks)
if callbacks.CredentialsCallback == nil { if callbacks.CredentialsCallback == nil {
return 0 return C.GIT_PASSTHROUGH
} }
url := C.GoString(_url) url := C.GoString(_url)
username_from_url := C.GoString(_username_from_url) username_from_url := C.GoString(_username_from_url)
@ -454,6 +454,25 @@ func (o *Remote) PushUrl() string {
return C.GoString(C.git_remote_pushurl(o.ptr)) return C.GoString(C.git_remote_pushurl(o.ptr))
} }
func (c *RemoteCollection) Rename(remote, newname string) error {
cproblems := C.git_strarray{}
cnewname := C.CString(newname)
defer C.free(unsafe.Pointer(cnewname))
cremote := C.CString(remote)
defer C.free(unsafe.Pointer(cremote))
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_remote_rename(&cproblems, c.repo.ptr, cremote, cnewname)
if ret < 0 {
return MakeGitError(ret)
}
C.git_strarray_free(&cproblems)
return nil
}
func (c *RemoteCollection) SetUrl(remote, url string) error { func (c *RemoteCollection) SetUrl(remote, url string) error {
curl := C.CString(url) curl := C.CString(url)
defer C.free(unsafe.Pointer(curl)) defer C.free(unsafe.Pointer(curl))
@ -687,6 +706,13 @@ func (o *Remote) Connect(direction ConnectDirection, callbacks *RemoteCallbacks,
return nil return nil
} }
func (o *Remote) Disconnect() {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
C.git_remote_disconnect(o.ptr)
}
func (o *Remote) Ls(filterRefs ...string) ([]RemoteHead, error) { func (o *Remote) Ls(filterRefs ...string) ([]RemoteHead, error) {
var refs **C.git_remote_head var refs **C.git_remote_head