Repository: conan-io/conan

Issue:
conan export-pkg with --package-folder does not set the metadata info
When an export-pkg command is used with the ``--package-folder``, the *metadata.json* is not updated with the package ID and package revision.

Then, when the user tries to upload the package ir errors with:
```
ERROR: Binary package hello/1.0@user/testing:5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9 not found
```

Here is a test reproducing the issue:

```
    def upload_export_pkg_test(self):
        """
        Package metadata is created when doing an export-pkg and then uploading the package
        """
        server1 = TestServer([("*/*@*/*", "*")], [("*/*@*/*", "*")], users={"lasote": "mypass"})
        servers = OrderedDict()
        servers["server1"] = server1
        client = TestClient(servers=servers)
        client.save({"release/kk.lib": ""})
        client.run("user lasote -r server1 -p mypass")
        client.run("new hello/1.0 --header")
        client.run("export-pkg . user/testing -pf release")
        client.run("upload hello/1.0@user/testing --all -r server1")
```

The original issue comes from #4768


Discussion:

Resolving patch:
diff --git a/conans/client/cmd/export_pkg.py b/conans/client/cmd/export_pkg.py
--- a/conans/client/cmd/export_pkg.py
+++ b/conans/client/cmd/export_pkg.py
@@ -50,9 +50,9 @@ def export_pkg(cache, graph_manager, hook_manager, recorder, output,
         packager.create_package(conanfile, package_id, source_folder, build_folder,
                                 dest_package_folder, install_folder, hook_manager, conan_file_path,
                                 ref, local=True)
-        with cache.package_layout(ref).update_metadata() as metadata:
-            readed_manifest = FileTreeManifest.load(dest_package_folder)
-            metadata.packages[package_id].revision = readed_manifest.summary_hash
-            metadata.packages[package_id].recipe_revision = metadata.recipe.revision
+    with cache.package_layout(ref).update_metadata() as metadata:
+        readed_manifest = FileTreeManifest.load(dest_package_folder)
+        metadata.packages[package_id].revision = readed_manifest.summary_hash
+        metadata.packages[package_id].recipe_revision = metadata.recipe.revision
 
     recorder.package_exported(pref)


Test patch:
diff --git a/conans/test/functional/command/upload_test.py b/conans/test/functional/command/upload_test.py
--- a/conans/test/functional/command/upload_test.py
+++ b/conans/test/functional/command/upload_test.py
@@ -572,3 +572,23 @@ def upload_key_error_test(self):
         client.run("remote remove server1")
         client.run("upload Hello0/1.2.1@user/testing --all -r server2")
         self.assertNotIn("ERROR: 'server1'", client.out)
+
+    def upload_export_pkg_test(self):
+        """
+        Package metadata created when doing an export-pkg and then uploading the package works
+        """
+        server1 = TestServer([("*/*@*/*", "*")], [("*/*@*/*", "*")], users={"lasote": "mypass"})
+        servers = OrderedDict()
+        servers["server1"] = server1
+        client = TestClient(servers=servers)
+        client.save({"release/kk.lib": ""})
+        client.run("user lasote -r server1 -p mypass")
+        client.run("new hello/1.0 --header")
+        client.run("export-pkg . user/testing -pf release")
+        client.run("upload hello/1.0@user/testing --all -r server1")
+        self.assertNotIn("Binary package hello/1.0@user/testing:5%s not found" %
+                         NO_SETTINGS_PACKAGE_ID, client.out)
+        ref = ConanFileReference("hello", "1.0", "user", "testing")
+        metadata = client.cache.package_layout(ref).load_metadata()
+        self.assertIn(NO_SETTINGS_PACKAGE_ID, metadata.packages)
+        self.assertTrue(metadata.packages[NO_SETTINGS_PACKAGE_ID].revision)