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.
This commit is contained in:
parent
3c353fb3e5
commit
d2cdff0d68
@ -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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user