pull/9095/merge
Dominik Braun 8 months ago committed by GitHub
commit bbb7567ffe
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -187,10 +187,8 @@ func (o *repoAddOptions) run(out io.Writer) error {
// 2. When the config is different require --force-update // 2. When the config is different require --force-update
if !o.forceUpdate && f.Has(o.name) { if !o.forceUpdate && f.Has(o.name) {
existing := f.Get(o.name) existing := f.Get(o.name)
if c != *existing { // Only fail with an error if the configs are different.
if c.URLWithTrailingSlash() != existing.URLWithTrailingSlash() {
// The input coming in for the name is different from what is already
// configured. Return an error.
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)
} }

@ -347,3 +347,9 @@ func (e *Entry) String() string {
} }
return string(buf) 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, "/") + "/"
}

@ -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")
}
}

Loading…
Cancel
Save