Skip to content

Commit

Permalink
do not add same remote multiple times (#13574)
Browse files Browse the repository at this point in the history
  • Loading branch information
memsharded authored Mar 30, 2023
1 parent dc17e1c commit abaa69c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
17 changes: 13 additions & 4 deletions conans/client/cache/remote_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,21 @@ def remove(self, remote_name):
def add(self, new_remote: Remote, index=None, force=False):
assert isinstance(new_remote, Remote)
current = self.get_by_name(new_remote.name)
if current:
if force:
ConanOutput().warning(f"Remote '{new_remote.name}' already exists in remotes")
else:
if current: # same name remote existing!
if not force:
raise ConanException(f"Remote '{new_remote.name}' already exists in remotes "
"(use --force to continue)")

ConanOutput().warning(f"Remote '{new_remote.name}' already exists in remotes")
if current.url != new_remote.url:
ConanOutput().warning("Updating existing remote with new url")
current_index = self._remotes.index(current)
self._remotes.remove(current)
index = index or current_index
self._remotes.insert(index, new_remote)
return

# The remote name doesn't exist
for r in self._remotes:
if r.url == new_remote.url:
msg = f"Remote url already existing in remote '{r.name}'. " \
Expand Down
18 changes: 18 additions & 0 deletions conans/test/integration/command/remote_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,3 +308,21 @@ def test_add_duplicated_url():
c.run("remote list")
assert "remote1" in c.out
assert "remote2" in c.out
# make sure we can remove both
# https://github.com/conan-io/conan/issues/13569
c.run("remote remove *")
c.run("remote list")
assert "remote1" not in c.out
assert "remote2" not in c.out


def test_add_duplicated_name_url():
""" do not add extra remote with same name and same url
# https://github.com/conan-io/conan/issues/13569
"""
c = TestClient()
c.run("remote add remote1 http://url")
c.run("remote add remote1 http://url --force")
assert "WARN: Remote 'remote1' already exists in remotes" in c.out
c.run("remote list")
assert 1 == str(c.out).count("remote1")

0 comments on commit abaa69c

Please sign in to comment.