Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remote: new ListContext function #278

Merged
merged 1 commit into from Apr 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 19 additions & 1 deletion remote.go
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"io"
"time"

"github.com/go-git/go-billy/v5/osfs"
"github.com/go-git/go-git/v5/config"
Expand Down Expand Up @@ -1030,15 +1031,32 @@ func (r *Remote) buildFetchedTags(refs memory.ReferenceStorage) (updated bool, e
}

// List the references on the remote repository.
// The provided Context must be non-nil. If the context expires before the
// operation is complete, an error is returned. The context only affects to the
// transport operations.
func (r *Remote) ListContext(ctx context.Context, o *ListOptions) (rfs []*plumbing.Reference, err error) {
refs, err := r.list(ctx, o)
if err != nil {
return refs, err
}
return refs, nil
}

func (r *Remote) List(o *ListOptions) (rfs []*plumbing.Reference, err error) {
ctx, cancel := context.WithTimeout(context.Background(), 600*time.Millisecond)
defer cancel()
return r.ListContext(ctx, o)
}

func (r *Remote) list(ctx context.Context, o *ListOptions) (rfs []*plumbing.Reference, err error) {
s, err := newUploadPackSession(r.c.URLs[0], o.Auth, o.InsecureSkipTLS, o.CABundle)
if err != nil {
return nil, err
}

defer ioutil.CheckClose(s, &err)

ar, err := s.AdvertisedReferencesContext(context.TODO())
ar, err := s.AdvertisedReferencesContext(ctx)
if err != nil {
return nil, err
}
Expand Down
11 changes: 11 additions & 0 deletions remote_test.go
Expand Up @@ -944,6 +944,17 @@ func (s *RemoteSuite) TestList(c *C) {
}
}

func (s *RemoteSuite) TestListTimeout(c *C) {
remote := NewRemote(memory.NewStorage(), &config.RemoteConfig{
Name: DefaultRemoteName,
URLs: []string{"https://deelay.me/60000/https://httpstat.us/503"},
})

_, err := remote.List(&ListOptions{})

c.Assert(err, NotNil)
}

func (s *RemoteSuite) TestUpdateShallows(c *C) {
hashes := []plumbing.Hash{
plumbing.NewHash("0000000000000000000000000000000000000001"),
Expand Down