bugfix: HTTPS Clone fails with remote pointer not found using Go transport (#836) #842

Merged
codexetreme merged 10 commits from bugfix/error_while_cloning into main 2021-10-23 12:33:11 -05:00
2 changed files with 23 additions and 3 deletions
Showing only changes of commit 4df4cbd5e3 - Show all commits

View File

@ -1,8 +1,11 @@
package git package git
import ( import (
"fmt"
"io/ioutil" "io/ioutil"
"net"
"testing" "testing"
"time"
) )
const ( const (
@ -70,3 +73,21 @@ func TestCloneWithCallback(t *testing.T) {
} }
defer remote.Free() 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)
}
lhchavez commented 2021-10-21 08:55:17 -05:00 (Migrated from github.com)
Review
	_, err = Clone("https://github.com/libgit2/TestGitRepository", path, &CloneOptions{})

:'( let's give up in the hermeticity in favor of supporting more Go versions.

```suggestion _, err = Clone("https://github.com/libgit2/TestGitRepository", path, &CloneOptions{}) ``` :'( let's give up in the hermeticity in favor of supporting more Go versions.
codexetreme commented 2021-10-21 09:34:38 -05:00 (Migrated from github.com)
Review

Cool, let me remove that dependency and related code

Cool, let me remove that dependency and related code
codexetreme commented 2021-10-21 09:56:24 -05:00 (Migrated from github.com)
Review

okay I've made the changes

okay I've made the changes
}

View File

@ -22,7 +22,6 @@ void _go_git_setup_smart_subtransport_stream(_go_managed_smart_subtransport_stre
*/ */
import "C" import "C"
import ( import (
"errors"
"fmt" "fmt"
"io" "io"
"reflect" "reflect"
@ -306,10 +305,10 @@ func smartTransportCallback(
registeredSmartTransport := pointerHandles.Get(handle).(*RegisteredSmartTransport) registeredSmartTransport := pointerHandles.Get(handle).(*RegisteredSmartTransport)
remote, ok := remotePointers.get(owner) remote, ok := remotePointers.get(owner)
if !ok { 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 = createNewEmptyRemote()
remote.weak = true remote.weak = true
return setCallbackError(errorMessage, err)
} }
managed := &managedSmartSubtransport{ managed := &managedSmartSubtransport{