From d2cdff0d68d97d1f02523b342bae1f4cc63ced77 Mon Sep 17 00:00:00 2001 From: "brian m. carlson" Date: Thu, 26 Oct 2023 18:42:21 +0000 Subject: [PATCH] git: allow validating remote from a cached list Right now, every time we call `ValidateRemote`, we look up the list of remotes by invoking `git remote`. It would be nice if we could cache the list of remotes so we could validate the remote multiple times without the expense of calling Git multiple times, so let's add a function, `ValidateRemoteFromList`, which can take a cached list and perform the same computation. --- git/git.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/git/git.go b/git/git.go index 59e3164e..136e7457 100644 --- a/git/git.go +++ b/git/git.go @@ -531,13 +531,20 @@ func ValidateRemote(remote string) error { if err != nil { return err } + return ValidateRemoteFromList(remotes, remote) +} + +// ValidateRemote checks that a named remote is valid for use given a list from +// RemoteList. This is completely identical to ValidateRemote, except that it +// allows caching the remote list. +func ValidateRemoteFromList(remotes []string, remote string) error { for _, r := range remotes { if r == remote { return nil } } - if err = ValidateRemoteURL(remote); err == nil { + if err := ValidateRemoteURL(remote); err == nil { return nil }