Repository: conan-io/conan

Issue:
Delete source folder after conan export command
If you export a modified conanfile.py, maybe adding sources, etc, the source folder which is created from a copy of the "export" folder + executing the conanfile.py `source()` method is not deleted.

If not deleted, build uses the old source folder. Thus, the user has to remember to `conan remove` the local storage before each `conan export`



Discussion:

Resolving patch:
diff --git a/conans/client/command.py b/conans/client/command.py
--- a/conans/client/command.py
+++ b/conans/client/command.py
@@ -282,10 +282,14 @@ def export(self, *args):
         parser.add_argument('--path', '-p', default=None,
                             help='Optional. Folder with a %s. Default current directory.'
                             % CONANFILE)
+        parser.add_argument('--keep-source', '-k', default=False, action='store_true',
+                            help='Optional. Do not remove the source folder in local store. '
+                                 'Use for testing purposes only')
         args = parser.parse_args(*args)
 
         current_path = args.path or os.getcwd()
-        self._manager.export(args.user, current_path)
+        keep_source = args.keep_source
+        self._manager.export(args.user, current_path, keep_source)
 
     def remove(self, *args):
         """ Remove any folder from your local/remote store
diff --git a/conans/client/export.py b/conans/client/export.py
--- a/conans/client/export.py
+++ b/conans/client/export.py
@@ -11,7 +11,7 @@
 from conans.model.manifest import FileTreeManifest
 
 
-def export_conanfile(output, paths, file_patterns, origin_folder, conan_ref):
+def export_conanfile(output, paths, file_patterns, origin_folder, conan_ref, keep_source=False):
     destination_folder = paths.export(conan_ref)
 
     previous_digest = _init_export_folder(destination_folder)
@@ -19,15 +19,17 @@ def export_conanfile(output, paths, file_patterns, origin_folder, conan_ref):
     _export(file_patterns, origin_folder, destination_folder)
 
     digest = FileTreeManifest.create(destination_folder)
+    save(os.path.join(destination_folder, CONAN_MANIFEST), str(digest))
 
     if previous_digest and previous_digest.file_sums == digest.file_sums:
         digest = previous_digest
+        output.info("The stored package has not changed")
     else:
         output.success('A new %s version was exported' % CONANFILE)
-
-    save(os.path.join(destination_folder, CONAN_MANIFEST), str(digest))
-    output.success('%s exported to local storage' % CONANFILE)
-    output.success('Folder: %s' % destination_folder)
+        if not keep_source:
+            rmdir(paths.source(conan_ref))
+        output.success('%s exported to local storage' % CONANFILE)
+        output.success('Folder: %s' % destination_folder)
 
 
 def _init_export_folder(destination_folder):
diff --git a/conans/client/manager.py b/conans/client/manager.py
--- a/conans/client/manager.py
+++ b/conans/client/manager.py
@@ -75,7 +75,7 @@ def _loader(self, current_path=None, user_settings_values=None, user_options_val
 
         return ConanFileLoader(self._runner, settings, options=options)
 
-    def export(self, user, conan_file_path):
+    def export(self, user, conan_file_path, keep_source=False):
         """ Export the conans
         param conanfile_path: the original source directory of the user containing a
                            conanfile.py
@@ -99,7 +99,7 @@ def export(self, user, conan_file_path):
         conan_ref = ConanFileReference(conan_file.name, conan_file.version, user_name, channel)
         output = ScopedOutput(str(conan_ref), self._user_io.out)
         export_conanfile(output, self._paths,
-                         conan_file.exports, conan_file_path, conan_ref)
+                         conan_file.exports, conan_file_path, conan_ref, keep_source)
 
     def download(self, reference, package_ids, remote=None):
         """ Download conanfile and specified packages to local repository


Test patch: