diff --git a/clone_test.go b/clone_test.go index acfbbcbc..bcf7055a 100644 --- a/clone_test.go +++ b/clone_test.go @@ -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) + } +} diff --git a/remote.go b/remote.go index 275d4d97..af09deac 100644 --- a/remote.go +++ b/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, + } +} diff --git a/transport.go b/transport.go index cf43acc8..b060dc33 100644 --- a/transport.go +++ b/transport.go @@ -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{