Repository: conan-io/conan

Issue:
[SCM] Recipe with sources in the same repo copies to the source folder gitignored files
Situation:
I have a `conanfile.py` in a repo with:
```
scm = {
        "type": "git",
        "subfolder": "asdio",
        "url": "auto",
        "revision": "auto"
    }
```
There are some gitignored files such as `.vs`.

Problem:
When using `conan install -pr=...` it uploads *everything* including ignored files to the `source` folder.


Discussion:
Just to make sure, you mean it **copies** files to the source folder, don't you? Those files are not uploaded to any server.
Yep!
Then it is not a big issue, is it? It is just a temporary copy, it is not packaged, it is not uploaded. Copying files or folders like .vs shouldn't have any effect.
Yes, the minor one. It could matter if such temporary files are big, I guess? 
Oh, I forgot. Since `.vs` is not ignored it blocks `conan install` if VS is open, @memsharded ! Still a minor one, but anyway.
@memsharded And I assume here that because of that it's pretty easy to get invalid binaries in cases when we're using `"revision": "auto"`, since we could get different binaries in case of yet to be commited changes. Should it clone at source stage then instead of copying everything? I'm missing something here.
>  we could get different binaries in case of yet to be commited changes. 

I think this is the reason we decided to not clone but copy the sources, while you are developing your library you probably don't want to commit any change to be able to try the conan package and see if your entire project works. 
I will try to get from git the ignored file list to be applied to the copy.
Right. So we would get all changes (not committed yet) but without ignored stuff? Would be good, thanks!
@lasote I'm afraid there is a problem with that feature. It does ignore **files**, but not **folders**.
I will review it. Thanks for reporting.

Resolving patch:
diff --git a/conans/client/tools/scm.py b/conans/client/tools/scm.py
--- a/conans/client/tools/scm.py
+++ b/conans/client/tools/scm.py
@@ -88,11 +88,13 @@ def checkout(self, element, submodule=None):
 
     def excluded_files(self):
         try:
-            file_paths = [os.path.normpath(os.path.join(os.path.relpath(folder, self.folder), f))
-                          for folder, _, fs in os.walk(self.folder) for f in fs]
+
+            file_paths = [os.path.normpath(os.path.join(os.path.relpath(folder, self.folder), el)).replace("\\", "/")
+                          for folder, dirpaths, fs in os.walk(self.folder)
+                          for el in fs + dirpaths]
             p = subprocess.Popen(['git', 'check-ignore', '--stdin'],
                                  stdout=PIPE, stdin=PIPE, stderr=STDOUT, cwd=self.folder)
-            paths = to_file_bytes('\n'.join(file_paths))
+            paths = to_file_bytes("\n".join(file_paths))
             grep_stdout = decode_text(p.communicate(input=paths)[0])
             tmp = grep_stdout.splitlines()
         except CalledProcessError:


Test patch:
diff --git a/conans/test/functional/scm_test.py b/conans/test/functional/scm_test.py
--- a/conans/test/functional/scm_test.py
+++ b/conans/test/functional/scm_test.py
@@ -166,13 +166,20 @@ def test_deleted_source_folder(self):
         self.assertTrue(error)
         self.assertIn("Getting sources from url: '%s'" % path.replace("\\", "/"), self.client.out)
 
-    def test_excluded_repo_fies(self):
+    def test_excluded_repo_files(self):
         conanfile = base.format(url="auto", revision="auto")
         conanfile = conanfile.replace("short_paths = True", "short_paths = False")
         path, commit = create_local_git_repo({"myfile": "contents",
                                               "ignored.pyc": "bin",
-                                              ".gitignore": "*.pyc\n",
+                                              ".gitignore": """
+*.pyc
+my_excluded_folder
+other_folder/excluded_subfolder
+""",
                                               "myfile.txt": "My file!",
+                                              "my_excluded_folder/some_file": "hey Apple!",
+                                              "other_folder/excluded_subfolder/some_file": "hey Apple!",
+                                              "other_folder/valid_file": "!",
                                               "conanfile.py": conanfile}, branch="my_release")
         self.client.current_folder = path
         self._commit_contents()
@@ -186,6 +193,9 @@ def test_excluded_repo_fies(self):
         self.assertTrue(os.path.exists(os.path.join(bf, "myfile")))
         self.assertTrue(os.path.exists(os.path.join(bf, ".git")))
         self.assertFalse(os.path.exists(os.path.join(bf, "ignored.pyc")))
+        self.assertFalse(os.path.exists(os.path.join(bf, "my_excluded_folder")))
+        self.assertTrue(os.path.exists(os.path.join(bf, "other_folder", "valid_file")))
+        self.assertFalse(os.path.exists(os.path.join(bf, "other_folder", "excluded_subfolder")))
 
     def test_local_source(self):
         curdir = self.client.current_folder