|
5 | 5 | "errors"
|
6 | 6 | "fmt"
|
7 | 7 | "io"
|
| 8 | + "time" |
8 | 9 |
|
9 | 10 | "github.com/go-git/go-billy/v5/osfs"
|
10 | 11 | "github.com/go-git/go-git/v5/config"
|
@@ -1030,15 +1031,32 @@ func (r *Remote) buildFetchedTags(refs memory.ReferenceStorage) (updated bool, e
|
1030 | 1031 | }
|
1031 | 1032 |
|
1032 | 1033 | // List the references on the remote repository.
|
| 1034 | +// The provided Context must be non-nil. If the context expires before the |
| 1035 | +// operation is complete, an error is returned. The context only affects to the |
| 1036 | +// transport operations. |
| 1037 | +func (r *Remote) ListContext(ctx context.Context, o *ListOptions) (rfs []*plumbing.Reference, err error) { |
| 1038 | + refs, err := r.list(ctx, o) |
| 1039 | + if err != nil { |
| 1040 | + return refs, err |
| 1041 | + } |
| 1042 | + return refs, nil |
| 1043 | +} |
| 1044 | + |
1033 | 1045 | func (r *Remote) List(o *ListOptions) (rfs []*plumbing.Reference, err error) {
|
| 1046 | + ctx, cancel := context.WithTimeout(context.Background(), 600*time.Millisecond) |
| 1047 | + defer cancel() |
| 1048 | + return r.ListContext(ctx, o) |
| 1049 | +} |
| 1050 | + |
| 1051 | +func (r *Remote) list(ctx context.Context, o *ListOptions) (rfs []*plumbing.Reference, err error) { |
1034 | 1052 | s, err := newUploadPackSession(r.c.URLs[0], o.Auth, o.InsecureSkipTLS, o.CABundle)
|
1035 | 1053 | if err != nil {
|
1036 | 1054 | return nil, err
|
1037 | 1055 | }
|
1038 | 1056 |
|
1039 | 1057 | defer ioutil.CheckClose(s, &err)
|
1040 | 1058 |
|
1041 |
| - ar, err := s.AdvertisedReferencesContext(context.TODO()) |
| 1059 | + ar, err := s.AdvertisedReferencesContext(ctx) |
1042 | 1060 | if err != nil {
|
1043 | 1061 | return nil, err
|
1044 | 1062 | }
|
|
0 commit comments