@@ -202,6 +202,7 @@ async def _copy_tree(
202
202
"""
203
203
# retrieve commit contents as tar archive
204
204
cmd = ("git" , "archive" , "--format" , "tar" , ref )
205
+ git_init_cmd = ("git" , "init" , "--initial-branch=dummy" )
205
206
with tempfile .SpooledTemporaryFile (max_size = buffer_size ) as f :
206
207
process = await asyncio .create_subprocess_exec (
207
208
* cmd , cwd = repo , stdout = f , stderr = PIPE
@@ -213,6 +214,13 @@ async def _copy_tree(
213
214
f .seek (0 )
214
215
with tarfile .open (fileobj = f ) as tf :
215
216
tf .extractall (str (dest ))
217
+ # initialize dummy git repository in copied directory (required for setuptools-scm)
218
+ process = await asyncio .create_subprocess_exec (
219
+ * git_init_cmd , cwd = str (dest ), stdout = f , stderr = PIPE
220
+ )
221
+ out , err = await process .communicate ()
222
+ if process .returncode :
223
+ raise CalledProcessError (process .returncode , " " .join (cmd ), stderr = err )
216
224
217
225
218
226
async def file_exists (repo : Path , ref : GitRef , file : PurePath ) -> bool :
@@ -250,6 +258,34 @@ async def file_exists(repo: Path, ref: GitRef, file: PurePath) -> bool:
250
258
return rc == 0
251
259
252
260
261
+ async def get_unignored_files (directory : Path ) -> list [Path ]:
262
+ """
263
+ List all unignored files in the directory.
264
+
265
+ Parameters
266
+ ----------
267
+ directory : Path
268
+ Any directory in the repo.
269
+
270
+ Returns
271
+ -------
272
+ Path
273
+ The paths to all un-ignored files in the directory (recursive)
274
+
275
+ """
276
+ cmd = (
277
+ "git" ,
278
+ "ls-files" ,
279
+ "--cached" ,
280
+ "--others" ,
281
+ "--exclude-standard" ,
282
+ )
283
+ process = await asyncio .create_subprocess_exec (* cmd , cwd = directory , stdout = PIPE )
284
+ out , err = await process .communicate ()
285
+ files = out .decode ().split ("\n " )
286
+ return [Path (path .strip ()) for path in files ]
287
+
288
+
253
289
# -- VersionProvider API -----------------------------------------------------
254
290
255
291
0 commit comments