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

BugFix: conan new accepts short reference with address sign #8721

Merged
merged 1 commit into from Mar 29, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 3 additions & 7 deletions conans/client/cmd/new.py
Expand Up @@ -6,7 +6,7 @@
from conans import __version__ as client_version
from conans.client.cmd.new_ci import ci_get_files
from conans.errors import ConanException
from conans.model.ref import ConanFileReference
from conans.model.ref import ConanFileReference, get_reference_fields
from conans.util.files import load


Expand Down Expand Up @@ -323,12 +323,8 @@ def cmd_new(ref, header=False, pure_c=False, test=False, exports_sources=False,
circleci_gcc_versions=None, circleci_clang_versions=None, circleci_osx_versions=None,
template=None, cache=None, defines=None):
try:
tokens = ref.split("@")
name, version = tokens[0].split("/")
if len(tokens) == 2:
user, channel = tokens[1].split("/")
else:
user, channel = "user", "channel"
name, version, user, channel, revision = get_reference_fields(ref, user_channel_input=False)
# convert "package_name" -> "PackageName"
package_name = re.sub(r"(?:^|[\W_])(\w)", lambda x: x.group(1).upper(), name)
except ValueError:
raise ConanException("Bad parameter, please use full package name,"
Expand Down
18 changes: 18 additions & 0 deletions conans/test/integration/command/new_test.py
Expand Up @@ -386,3 +386,21 @@ def test_new_v2_cmake(self):
self.assertIn("CMakeToolchain", conanfile)
cmake = client.load("test_package/CMakeLists.txt")
self.assertIn("find_package", cmake)

def test_new_reference(self):
client = TestClient()
# full reference
client.run("new MyPackage/1.3@myuser/testing --template=v2_cmake")
conanfile = client.load("conanfile.py")
self.assertIn('name = "MyPackage"', conanfile)
self.assertIn('version = "1.3"', conanfile)
# no username, no channel (with @)
client.run("new MyPackage/1.3@ --template=v2_cmake")
conanfile = client.load("conanfile.py")
self.assertIn('version = "1.3"', conanfile)
self.assertIn('name = "MyPackage"', conanfile)
# no username, no channel (without @)
client.run("new MyPackage/1.3 --template=v2_cmake")
conanfile = client.load("conanfile.py")
self.assertIn('name = "MyPackage"', conanfile)
self.assertIn('version = "1.3"', conanfile)