Fixes: #836
Changes:
* adding a weak bool param for Remote
* create a new remote in the smartTransportCallback incase one is not found
(cherry picked from commit 0e8009f00a
)
Co-authored-by: Yashodhan Ghadge <codexetreme@users.noreply.github.com>
Co-authored-by: lhchavez <lhchavez@lhchavez.com>
This commit is contained in:
parent
0ff1486249
commit
90af2ae3f3
|
@ -2,6 +2,7 @@ package git
|
|||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
|
@ -76,3 +77,17 @@ func TestCloneWithCallback(t *testing.T) {
|
|||
}
|
||||
defer remote.Free()
|
||||
}
|
||||
|
||||
// TestCloneWithExternalHTTPUrl
|
||||
func TestCloneWithExternalHTTPUrl(t *testing.T) {
|
||||
|
||||
path, err := ioutil.TempDir("", "git2go")
|
||||
defer os.RemoveAll(path)
|
||||
|
||||
// clone the repo
|
||||
url := "https://github.com/libgit2/TestGitRepository"
|
||||
_, err = Clone(url, path, &CloneOptions{})
|
||||
if err != nil {
|
||||
t.Fatal("cannot clone remote repo via https, error: ", err)
|
||||
}
|
||||
}
|
||||
|
|
15
remote.go
15
remote.go
|
@ -182,6 +182,9 @@ type Remote struct {
|
|||
ptr *C.git_remote
|
||||
callbacks RemoteCallbacks
|
||||
repo *Repository
|
||||
// weak indicates that a remote is a weak pointer and should not be
|
||||
// freed.
|
||||
weak bool
|
||||
}
|
||||
|
||||
type remotePointerList struct {
|
||||
|
@ -592,6 +595,9 @@ func (r *Remote) free() {
|
|||
// Free releases the resources of the Remote.
|
||||
func (r *Remote) Free() {
|
||||
r.repo.Remotes.untrackRemote(r)
|
||||
if r.weak {
|
||||
return
|
||||
}
|
||||
r.free()
|
||||
}
|
||||
|
||||
|
@ -1221,3 +1227,12 @@ func freeRemoteCreateOptions(ptr *C.git_remote_create_options) {
|
|||
C.free(unsafe.Pointer(ptr.name))
|
||||
C.free(unsafe.Pointer(ptr.fetchspec))
|
||||
}
|
||||
|
||||
// createNewEmptyRemote used to get a new empty object of *Remote
|
||||
func createNewEmptyRemote() *Remote {
|
||||
return &Remote{
|
||||
callbacks: RemoteCallbacks{},
|
||||
repo: nil,
|
||||
weak: false,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,6 @@ void _go_git_setup_smart_subtransport_stream(_go_managed_smart_subtransport_stre
|
|||
*/
|
||||
import "C"
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"reflect"
|
||||
|
@ -296,8 +295,10 @@ func smartTransportCallback(
|
|||
registeredSmartTransport := pointerHandles.Get(handle).(*RegisteredSmartTransport)
|
||||
remote, ok := remotePointers.get(owner)
|
||||
if !ok {
|
||||
err := errors.New("remote pointer not found")
|
||||
return setCallbackError(errorMessage, err)
|
||||
// create a new empty remote and set it
|
||||
// as a weak pointer, so that control stays in golang
|
||||
remote = createNewEmptyRemote()
|
||||
remote.weak = true
|
||||
}
|
||||
|
||||
managed := &managedSmartSubtransport{
|
||||
|
|
Loading…
Reference in New Issue