Repository: conan-io/conan

Issue:
[bug] exporting/creating a package without user channel when other exists
```bash
$ conan export . pkg/0.1@user/channel
$ conan export . pkg/0.1@  # Fails
```


Discussion:

Resolving patch:
diff --git a/conans/client/cmd/export.py b/conans/client/cmd/export.py
--- a/conans/client/cmd/export.py
+++ b/conans/client/cmd/export.py
@@ -43,7 +43,10 @@ def check_casing_conflict(cache, ref):
     # Check for casing conflict
     # Maybe a platform check could be added, but depends on disk partition
     refs = search_recipes(cache, ref, ignorecase=True)
-    if refs and ref not in [r.copy_clear_rev() for r in refs]:
+    refs2 = [ConanFileReference(r.name, r.version, r.user if ref.user else None,
+                                r.channel if ref.channel else None, validate=False) for r in refs]
+
+    if refs and ref not in refs2:
         raise ConanException("Cannot export package with same name but different case\n"
                              "You exported '%s' but already existing '%s'"
                              % (str(ref), " ".join(str(s) for s in refs)))


Test patch:
diff --git a/conans/test/functional/command/export_test.py b/conans/test/functional/command/export_test.py
--- a/conans/test/functional/command/export_test.py
+++ b/conans/test/functional/command/export_test.py
@@ -9,7 +9,7 @@
 from conans.model.ref import ConanFileReference
 from conans.paths import CONANFILE, CONAN_MANIFEST
 from conans.test.utils.cpp_test_files import cpp_hello_conan_files
-from conans.test.utils.tools import TestClient
+from conans.test.utils.tools import TestClient, GenConanfile
 from conans.test.utils.tools import create_local_git_repo
 from conans.util.files import load, save
 
@@ -464,14 +464,7 @@ def test_revision_mode_invalid(self):
 
     def test_export_no_params(self):
         client = TestClient()
-        conanfile = textwrap.dedent("""
-                        from conans import ConanFile
-
-                        class MyPkg(ConanFile):
-                            name = "lib"
-                            version = "1.0"
-                        """)
-        client.save({"conanfile.py": conanfile})
+        client.save({"conanfile.py": GenConanfile().with_name("lib").with_version("1.0")})
         client.run('export .')
         client.cache.package_layout(ConanFileReference.loads("lib/1.0@")).export()
         self.assertIn("lib/1.0: A new conanfile.py version was exported", client.out)
@@ -482,13 +475,7 @@ class MyPkg(ConanFile):
 
     def export_with_name_and_version_test(self):
         client = TestClient()
-        conanfile = textwrap.dedent("""
-                from conans import ConanFile
-
-                class MyPkg(ConanFile):
-                    pass
-                """)
-        client.save({"conanfile.py": conanfile})
+        client.save({"conanfile.py": GenConanfile()})
 
         client.run('export . lib/1.0@')
         self.assertIn("lib/1.0: A new conanfile.py version was exported", client.out)
@@ -496,14 +483,20 @@ class MyPkg(ConanFile):
     def export_with_only_user_channel_test(self):
         """This should be the recommended way and only from Conan 2.0"""
         client = TestClient()
-        conanfile = textwrap.dedent("""
-                from conans import ConanFile
-
-                class MyPkg(ConanFile):
-                    name = "lib"
-                    version = "1.0"
-                """)
-        client.save({"conanfile.py": conanfile})
+        client.save({"conanfile.py": GenConanfile().with_name("lib").with_version("1.0")})
 
         client.run('export . @user/channel')
         self.assertIn("lib/1.0@user/channel: A new conanfile.py version was exported", client.out)
+
+    def export_conflict_no_user_channel_test(self):
+        client = TestClient()
+        client.save({"conanfile.py": GenConanfile()})
+
+        client.run('export . pkg/0.1@user/channel')
+        self.assertIn("pkg/0.1@user/channel: A new conanfile.py version was exported", client.out)
+        client.run('export . pkg/0.1@other/stable')
+        self.assertIn("pkg/0.1@other/stable: A new conanfile.py version was exported", client.out)
+        client.run('export . pkg/0.1@')
+        self.assertIn("pkg/0.1: A new conanfile.py version was exported", client.out)
+        client.run('export . Pkg/0.1@', assert_error=True)
+        self.assertIn("ERROR: Cannot export package with same name but different case", client.out)