* 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
This commit is contained in:
Yashodhan Ghadge 2021-10-15 14:34:35 +05:30
parent c86c835832
commit 4df4cbd5e3
2 changed files with 23 additions and 3 deletions

View File

@ -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)
}
}

View File

@ -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{