From 4df4cbd5e33b202e74367e861ea81560ffdeb677 Mon Sep 17 00:00:00 2001 From: Yashodhan Ghadge Date: Fri, 15 Oct 2021 14:34:35 +0530 Subject: [PATCH] * removing error code and creating a new empty remote instead if the owner remote is not found in the list of tracked remotes * adding a test to check if external clone via HTTPS works --- clone_test.go | 21 +++++++++++++++++++++ transport.go | 5 ++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/clone_test.go b/clone_test.go index 8814dd0..c6ea504 100644 --- a/clone_test.go +++ b/clone_test.go @@ -1,8 +1,11 @@ package git import ( + "fmt" "io/ioutil" + "net" "testing" + "time" ) const ( @@ -70,3 +73,21 @@ func TestCloneWithCallback(t *testing.T) { } defer remote.Free() } + +// TestCloneWithExternalHTTPSUrl warning: this test might be flaky +func TestCloneWithExternalHTTPSUrl(t *testing.T) { + // fail the test, if the URL is not reachable + timeout := 1 * time.Second + _, err := net.DialTimeout("tcp", "github.com:443", timeout) + if err != nil { + t.Fatal("Site unreachable, retry later, error: ", err) + } + + url := "https://github.com/libgit2/git2go.git" + fmt.Println(url) + path, err := ioutil.TempDir("", "git2go") + _, err = Clone(url, path, &CloneOptions{}) + if err != nil { + t.Fatal("cannot clone remote repo via https, error: ", err) + } +} diff --git a/transport.go b/transport.go index 525c704..23514b4 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" @@ -306,10 +305,10 @@ func smartTransportCallback( registeredSmartTransport := pointerHandles.Get(handle).(*RegisteredSmartTransport) remote, ok := remotePointers.get(owner) if !ok { - err := errors.New("remote pointer not found") + // create a new empty remote and set it + // as a weak pointer, so that control stays in golang remote = createNewEmptyRemote() remote.weak = true - return setCallbackError(errorMessage, err) } managed := &managedSmartSubtransport{