diff --git a/remote.go b/remote.go index 139e71b..a3b4c6c 100644 --- a/remote.go +++ b/remote.go @@ -41,8 +41,8 @@ const ( RemoteCompletionDownload RemoteCompletion = C.GIT_REMOTE_COMPLETION_DOWNLOAD RemoteCompletionIndexing = C.GIT_REMOTE_COMPLETION_INDEXING RemoteCompletionError = C.GIT_REMOTE_COMPLETION_ERROR - - RemoteFetchDirection = C.GIT_DIRECTION_FETCH + RemoteDirectionFetch = C.GIT_DIRECTION_FETCH + RemoteDirectionPush = C.GIT_DIRECTION_PUSH ) type TransportMessageCallback func(str string) int @@ -564,10 +564,25 @@ func (o *Remote) Fetch(refspecs []string, sig *Signature, msg string) error { return nil } -func (o *Remote) Ls(filterRefs ...string) ([]RemoteHead, error) { - if ret := C.git_remote_connect(o.ptr, RemoteFetchDirection); ret != 0 { - return nil, MakeGitError(ret) +func (o *Remote) ConnectFetch() error { + return o.Connect(RemoteDirectionFetch) +} + +func (o *Remote) ConnectPush() error { + return o.Connect(RemoteDirectionPush) +} + +func (o *Remote) Connect(direction C.git_direction) error { + runtime.LockOSThread() + defer runtime.UnlockOSThread() + + if ret := C.git_remote_connect(o.ptr, direction); ret != 0 { + return MakeGitError(ret) } + return nil +} + +func (o *Remote) Ls(filterRefs ...string) ([]RemoteHead, error) { var refs **C.git_remote_head var length C.size_t diff --git a/remote_test.go b/remote_test.go index 70e53ce..6d81df4 100644 --- a/remote_test.go +++ b/remote_test.go @@ -75,6 +75,18 @@ func TestCertificateCheck(t *testing.T) { checkFatal(t, err) } +func TestRemoteConnect(t *testing.T) { + repo := createTestRepo(t) + defer os.RemoveAll(repo.Workdir()) + defer repo.Free() + + remote, err := repo.CreateRemote("origin", "https://github.com/libgit2/TestGitRepository") + checkFatal(t, err) + + err = remote.ConnectFetch() + checkFatal(t, err) +} + func TestRemoteLs(t *testing.T) { repo := createTestRepo(t) defer os.RemoveAll(repo.Workdir()) @@ -83,6 +95,9 @@ func TestRemoteLs(t *testing.T) { remote, err := repo.CreateRemote("origin", "https://github.com/libgit2/TestGitRepository") checkFatal(t, err) + err = remote.ConnectFetch() + checkFatal(t, err) + heads, err := remote.Ls() checkFatal(t, err) @@ -99,6 +114,9 @@ func TestRemoteLsFiltering(t *testing.T) { remote, err := repo.CreateRemote("origin", "https://github.com/libgit2/TestGitRepository") checkFatal(t, err) + err = remote.ConnectFetch() + checkFatal(t, err) + heads, err := remote.Ls("master") checkFatal(t, err)