diff --git a/cmd/helm/repo_add.go b/cmd/helm/repo_add.go index cd3dc8a62..84912ee78 100644 --- a/cmd/helm/repo_add.go +++ b/cmd/helm/repo_add.go @@ -187,10 +187,8 @@ func (o *repoAddOptions) run(out io.Writer) error { // 2. When the config is different require --force-update if !o.forceUpdate && f.Has(o.name) { existing := f.Get(o.name) - if c != *existing { - - // The input coming in for the name is different from what is already - // configured. Return an error. + // Only fail with an error if the configs are different. + if c.URLWithTrailingSlash() != existing.URLWithTrailingSlash() { return errors.Errorf("repository name (%s) already exists, please specify a different name", o.name) } diff --git a/pkg/repo/chartrepo.go b/pkg/repo/chartrepo.go index 3629bd24b..1abbb28eb 100644 --- a/pkg/repo/chartrepo.go +++ b/pkg/repo/chartrepo.go @@ -347,3 +347,9 @@ func (e *Entry) String() string { } return string(buf) } + +// URLWithTrailingSlash returns the repository URL with a trailing slash. +// If the URL already ends with a slash, it will be returned unchanged. +func (e *Entry) URLWithTrailingSlash() string { + return strings.TrimSuffix(e.URL, "/") + "/" +} diff --git a/pkg/repo/chartrepo_test.go b/pkg/repo/chartrepo_test.go index e3330b8eb..5523f503e 100644 --- a/pkg/repo/chartrepo_test.go +++ b/pkg/repo/chartrepo_test.go @@ -405,3 +405,19 @@ func TestResolveReferenceURL(t *testing.T) { } } } + +func TestEntry_URLWithTrailingSlash(t *testing.T) { + urlWithTrailingSlash := "http://someserver/something/" + e := Entry{URL: urlWithTrailingSlash} + + if e.URLWithTrailingSlash() != urlWithTrailingSlash { + t.Errorf("Expected unchanged repository URL") + } + + urlWithoutTrailingSlash := strings.TrimSuffix(urlWithTrailingSlash, "/") + e = Entry{URL: urlWithoutTrailingSlash} + + if e.URLWithTrailingSlash() != urlWithTrailingSlash { + t.Errorf("Expected repository URL with trailing slash") + } +}