aboutsummaryrefslogtreecommitdiffstats
path: root/remote.go
diff options
context:
space:
mode:
authorPaulo Gomes <pjbgf@linux.com>2023-05-20 21:36:18 +0100
committerGitHub <noreply@github.com>2023-05-20 21:36:18 +0100
commitce08ae04c6fb0cbea350e31b329e8187185ec868 (patch)
tree2e6b1b16e4cee85f78f32a8b159a7a2de2e05ec7 /remote.go
parent4ff2213cc5422d3300cf9828ea0781820888d32d (diff)
parentf47bb2d633347913d5575a42e25872c38569a4a3 (diff)
downloadgo-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.go10
1 files changed, 9 insertions, 1 deletions
diff --git a/remote.go b/remote.go
index dd12f8a..7b2741a 100644
--- a/remote.go
+++ b/remote.go
@@ -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)
}