Simplify Entry.URLWithTrailingSlash implementation and usage

Signed-off-by: Dominik Braun <mail@dominikbraun.io>
pull/9095/head
Dominik Braun 5 years ago
parent 2ed0081b92
commit ea119d0dc5

@ -160,14 +160,12 @@ 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 {
// In case of of the repo URLs ends with a trailing slash and the other
// one doesn't, the config is considered to be different even though they
// refer to the same repository.
// Only fail with an error if the configs actually are different.
if c.URLWithTrailingSlash() != existing.URLWithTrailingSlash() {
return errors.Errorf("repository name (%s) already exists, please specify a different name", o.name)
}
// In case of of the repo URLs ends with a trailing slash and the other
// one doesn't, the config is considered to be different even though they
// refer to the same repository.
// Only fail with an error if the configs actually are different.
if c != *existing && c.URLWithTrailingSlash() != existing.URLWithTrailingSlash() {
return errors.Errorf("repository name (%s) already exists, please specify a different name", o.name)
}
// The add is idempotent so do nothing

@ -296,9 +296,5 @@ func (e *Entry) String() string {
// 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 {
if e.URL[len(e.URL)-1:] == "/" {
return e.URL
}
return e.URL + "/"
return strings.TrimSuffix(e.URL, "/") + "/"
}

Loading…
Cancel
Save