return as no-op if repo name/url is identical

Signed-off-by: Matthew Fisher <matt.fisher@microsoft.com>
pull/8778/head
Matthew Fisher 5 years ago
parent 2ebe95a6ff
commit b9473cf3b7
No known key found for this signature in database
GPG Key ID: 92AA783CBAAE8E3B

@ -116,6 +116,15 @@ func (o *repoAddOptions) run(out io.Writer) error {
return err return err
} }
// If the same name and url already exists, return as a no-op.
// fixes https://github.com/helm/helm/issues/8771
if f.Has(o.name) {
e := f.Get(o.name)
if e.URL == o.url {
return nil
}
}
// If the repo exists and --force-update was not specified, error out. // If the repo exists and --force-update was not specified, error out.
if !o.forceUpdate && f.Has(o.name) { if !o.forceUpdate && f.Has(o.name) {
return errors.Errorf("repository name (%s) already exists, please specify a different name", o.name) return errors.Errorf("repository name (%s) already exists, please specify a different name", o.name)

@ -77,6 +77,12 @@ func TestRepoAdd(t *testing.T) {
t.Error(err) t.Error(err)
} }
// try adding the same name and url again; should be a no-op and return
// successful.
if err := o.run(ioutil.Discard); err != nil {
t.Error(err)
}
f, err := repo.LoadFile(repoFile) f, err := repo.LoadFile(repoFile)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)

Loading…
Cancel
Save