Skip to content

Commit

Permalink
Improve conan copy UX (#7741)
Browse files Browse the repository at this point in the history
* #7736 Improve conan copy UX

Signed-off-by: Uilian Ries <uilianries@gmail.com>

* Fix reference counter for conan copy

Signed-off-by: Uilian Ries <uilianries@gmail.com>
  • Loading branch information
uilianries committed Sep 23, 2020
1 parent c7b5b5f commit e37319a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
9 changes: 6 additions & 3 deletions conans/client/cmd/copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,12 @@ def cmd_copy(ref, user_channel, package_ids, cache, user_io, remote_manager, loa

def package_copy(src_ref, user_channel, package_ids, cache, user_io, short_paths=False,
force=False):
dest_ref = ConanFileReference.loads("%s/%s@%s" % (src_ref.name,
src_ref.version,
user_channel))

ref = "%s/%s@%s" % (src_ref.name, src_ref.version, user_channel)
if ref.count('@') > 1:
raise ConanException("Destination must contain user/channel only.")

dest_ref = ConanFileReference.loads(ref)
# Generate metadata
src_layout = cache.package_layout(src_ref, short_paths)
src_metadata = src_layout.load_metadata()
Expand Down
13 changes: 13 additions & 0 deletions conans/test/functional/command/copy_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import unittest
import textwrap

from conans.model.ref import ConanFileReference
from conans.test.utils.tools import TestClient, TestServer
Expand Down Expand Up @@ -102,3 +103,15 @@ def test_copy_with_p_and_all(self):
client.run("copy pkg/0.1@user/channel other/channel -p {} --all".format("mimic"),
assert_error=True)
self.assertIn("Cannot specify both --all and --package", client.out)

def test_copy_full_reference(self):
conanfile = textwrap.dedent("""
from conans import ConanFile
class Pkg(ConanFile):
settings = "os"
""")
client = TestClient()
client.save({"conanfile.py": conanfile})
client.run("export . pkg/0.1@user/channel")
client.run("copy pkg/0.1@user/channel pkg/0.1@other/branch", assert_error=True)
self.assertIn("Destination must contain user/channel only.", client.out)

0 comments on commit e37319a

Please sign in to comment.