Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow remote add with existing name #13249

Merged
merged 1 commit into from
Feb 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions conans/client/cache/remote_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,11 @@ 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:
raise ConanException("Remote '%s' already exists in remotes (use update to modify)"
% new_remote.name)
if force:
ConanOutput().warning(f"Remote '{new_remote.name}' already exists in remotes")
else:
raise ConanException(f"Remote '{new_remote.name}' already exists in remotes "
"(use --force to continue)")
for r in self._remotes:
if r.url == new_remote.url:
msg = f"Remote url already existing in remote '{r.name}'. " \
Expand Down
12 changes: 9 additions & 3 deletions conans/test/integration/command/remote_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,16 @@ def test_duplicated_error(self):
""" check remote name are not duplicated
"""
self.client.run("remote add remote1 http://otherurl", assert_error=True)
self.assertIn("ERROR: Remote 'remote1' already exists in remotes (use update to modify)",
self.assertIn("ERROR: Remote 'remote1' already exists in remotes (use --force to continue)",
self.client.out)

self.client.run("remote list")
assert "otherurl" not in self.client.out
self.client.run("remote add remote1 http://otherurl --force")
self.assertIn("WARN: Remote 'remote1' already exists in remotes", self.client.out)

self.client.run("remote list")
assert "remote1: http://otherurl" in self.client.out

def test_missing_subarguments(self):
self.client.run("remote", assert_error=True)
Expand All @@ -274,7 +279,7 @@ def test_invalid_url(self):
self.assertIn("pepe.org", self.client.out)


def test_duplicated_url():
def test_add_duplicated_url():
""" allow duplicated URL with --force
"""
c = TestClient()
Expand All @@ -286,5 +291,6 @@ def test_duplicated_url():
assert "remote2" not in c.out
c.run("remote add remote2 http://url --force")
assert "WARN: Remote url already existing in remote 'remote1'." in c.out
c.run("remote list")
assert "remote1" in c.out
assert "remote2" not in c.out
assert "remote2" in c.out