diff options
author | Paulo Gomes <pjbgf@linux.com> | 2023-05-20 21:36:18 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-20 21:36:18 +0100 |
commit | ce08ae04c6fb0cbea350e31b329e8187185ec868 (patch) | |
tree | 2e6b1b16e4cee85f78f32a8b159a7a2de2e05ec7 /remote.go | |
parent | 4ff2213cc5422d3300cf9828ea0781820888d32d (diff) | |
parent | f47bb2d633347913d5575a42e25872c38569a4a3 (diff) | |
download | go-git-ce08ae04c6fb0cbea350e31b329e8187185ec868.tar.gz |
Merge pull request #753 from andrewpollock/add_list_timeout
git: remote, add support for a configurable timeout.
Diffstat (limited to 'remote.go')
-rw-r--r-- | remote.go | 10 |
1 files changed, 9 insertions, 1 deletions
@@ -1254,7 +1254,15 @@ func (r *Remote) ListContext(ctx context.Context, o *ListOptions) (rfs []*plumbi } func (r *Remote) List(o *ListOptions) (rfs []*plumbing.Reference, err error) { - ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + timeout := o.Timeout + // Default to the old hardcoded 10s value if a timeout is not explicitly set. + if timeout == 0 { + timeout = 10 + } + if timeout < 0 { + return nil, fmt.Errorf("invalid timeout: %d", timeout) + } + ctx, cancel := context.WithTimeout(context.Background(), time.Duration(timeout)*time.Second) defer cancel() return r.ListContext(ctx, o) } |