@@ -255,10 +255,56 @@ def _create_git_remote_repo(
255255 return remote_repo_path
256256
257257
258+ def _create_git_remote_repo_full_path (
259+ remote_repo_path : pathlib .Path ,
260+ remote_repo_post_init : Optional [CreateRepoPostInitFn ] = None ,
261+ init_cmd_args : InitCmdArgs = DEFAULT_GIT_REMOTE_REPO_CMD_ARGS ,
262+ ) -> pathlib .Path :
263+ if init_cmd_args is None :
264+ init_cmd_args = []
265+ run (
266+ ["git" , "init" , remote_repo_path .stem , * init_cmd_args ],
267+ cwd = remote_repo_path .parent ,
268+ )
269+
270+ if remote_repo_post_init is not None and callable (remote_repo_post_init ):
271+ remote_repo_post_init (remote_repo_path = remote_repo_path )
272+
273+ return remote_repo_path
274+
275+
276+ @pytest .fixture (scope = "session" )
277+ def libvcs_test_cache_path (tmp_path_factory : pytest .TempPathFactory ) -> pathlib .Path :
278+ """Return temporary directory to use as cache path for libvcs tests."""
279+ return tmp_path_factory .mktemp ("libvcs-test-cache" )
280+
281+
282+ @pytest .fixture (scope = "session" )
283+ def empty_git_repo_path (libvcs_test_cache_path : pathlib .Path ) -> pathlib .Path :
284+ """Return temporary directory to use as cache path for libvcs tests."""
285+ return libvcs_test_cache_path / "empty_git_repo"
286+
287+
288+ @pytest .fixture (scope = "session" )
289+ @skip_if_git_missing
290+ def empty_git_repo (
291+ empty_git_repo_path : pathlib .Path ,
292+ ) -> pathlib .Path :
293+ """Return factory to create git remote repo to for clone / push purposes."""
294+ if empty_git_repo_path .exists () and (empty_git_repo_path / ".git" ).exists ():
295+ return empty_git_repo_path
296+
297+ return _create_git_remote_repo_full_path (
298+ remote_repo_path = empty_git_repo_path ,
299+ remote_repo_post_init = None ,
300+ )
301+
302+
258303@pytest .fixture
259304@skip_if_git_missing
260305def create_git_remote_repo (
261306 remote_repos_path : pathlib .Path ,
307+ empty_git_repo : pathlib .Path ,
262308) -> CreateRepoPytestFixtureFn :
263309 """Return factory to create git remote repo to for clone / push purposes."""
264310
@@ -268,14 +314,25 @@ def fn(
268314 remote_repo_post_init : Optional [CreateRepoPostInitFn ] = None ,
269315 init_cmd_args : InitCmdArgs = DEFAULT_GIT_REMOTE_REPO_CMD_ARGS ,
270316 ) -> pathlib .Path :
271- return _create_git_remote_repo (
272- remote_repos_path = remote_repos_path ,
273- remote_repo_name = remote_repo_name
274- if remote_repo_name is not None
275- else unique_repo_name (remote_repos_path = remote_repos_path ),
276- remote_repo_post_init = remote_repo_post_init ,
277- init_cmd_args = init_cmd_args ,
278- )
317+ if remote_repo_name is None :
318+ remote_repo_name = unique_repo_name (remote_repos_path = remote_repos_path )
319+ remote_repo_path = remote_repos_path / remote_repo_name
320+
321+ shutil .copytree (empty_git_repo , remote_repo_path )
322+
323+ if remote_repo_post_init is not None and callable (remote_repo_post_init ):
324+ remote_repo_post_init (remote_repo_path = remote_repo_path )
325+
326+ return remote_repo_path
327+
328+ # return _create_git_remote_repo(
329+ # remote_repos_path=remote_repos_path,
330+ # remote_repo_name=remote_repo_name
331+ # if remote_repo_name is not None
332+ # else unique_repo_name(remote_repos_path=remote_repos_path),
333+ # remote_repo_post_init=remote_repo_post_init,
334+ # init_cmd_args=init_cmd_args,
335+ # )
279336
280337 return fn
281338
0 commit comments