diff --git a/cmd/helm/repo_add.go b/cmd/helm/repo_add.go index 1c2162bfa..bc9016918 100644 --- a/cmd/helm/repo_add.go +++ b/cmd/helm/repo_add.go @@ -116,6 +116,15 @@ func (o *repoAddOptions) run(out io.Writer) error { 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 !o.forceUpdate && f.Has(o.name) { return errors.Errorf("repository name (%s) already exists, please specify a different name", o.name) diff --git a/cmd/helm/repo_add_test.go b/cmd/helm/repo_add_test.go index d358ad970..ae4a3cf1a 100644 --- a/cmd/helm/repo_add_test.go +++ b/cmd/helm/repo_add_test.go @@ -77,6 +77,12 @@ func TestRepoAdd(t *testing.T) { 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) if err != nil { t.Fatal(err)