Skip to content

Commit

Permalink
!squas wip more initial repo copy thing
Browse files Browse the repository at this point in the history
  • Loading branch information
tony committed Oct 11, 2024
1 parent 4444ca8 commit 99fa170
Showing 1 changed file with 65 additions and 8 deletions.
73 changes: 65 additions & 8 deletions src/libvcs/pytest_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,56 @@ def _create_git_remote_repo(
return remote_repo_path


def _create_git_remote_repo_full_path(
remote_repo_path: pathlib.Path,
remote_repo_post_init: Optional[CreateRepoPostInitFn] = None,
init_cmd_args: InitCmdArgs = DEFAULT_GIT_REMOTE_REPO_CMD_ARGS,
) -> pathlib.Path:
if init_cmd_args is None:
init_cmd_args = []
run(
["git", "init", remote_repo_path.stem, *init_cmd_args],
cwd=remote_repo_path.parent,
)

if remote_repo_post_init is not None and callable(remote_repo_post_init):
remote_repo_post_init(remote_repo_path=remote_repo_path)

return remote_repo_path


@pytest.fixture(scope="session")
def libvcs_test_cache_path(tmp_path_factory: pytest.TempPathFactory) -> pathlib.Path:
"""Return temporary directory to use as cache path for libvcs tests."""
return tmp_path_factory.mktemp("libvcs-test-cache")


@pytest.fixture(scope="session")
def empty_git_repo_path(libvcs_test_cache_path: pathlib.Path) -> pathlib.Path:
"""Return temporary directory to use as cache path for libvcs tests."""
return libvcs_test_cache_path / "empty_git_repo"


@pytest.fixture(scope="session")
@skip_if_git_missing
def empty_git_repo(
empty_git_repo_path: pathlib.Path,
) -> pathlib.Path:
"""Return factory to create git remote repo to for clone / push purposes."""
if empty_git_repo_path.exists() and (empty_git_repo_path / ".git").exists():
return empty_git_repo_path

return _create_git_remote_repo_full_path(
remote_repo_path=empty_git_repo_path,
remote_repo_post_init=None,
)


@pytest.fixture
@skip_if_git_missing
def create_git_remote_repo(
remote_repos_path: pathlib.Path,
empty_git_repo: pathlib.Path,
) -> CreateRepoPytestFixtureFn:
"""Return factory to create git remote repo to for clone / push purposes."""

Expand All @@ -268,14 +314,25 @@ def fn(
remote_repo_post_init: Optional[CreateRepoPostInitFn] = None,
init_cmd_args: InitCmdArgs = DEFAULT_GIT_REMOTE_REPO_CMD_ARGS,
) -> pathlib.Path:
return _create_git_remote_repo(
remote_repos_path=remote_repos_path,
remote_repo_name=remote_repo_name
if remote_repo_name is not None
else unique_repo_name(remote_repos_path=remote_repos_path),
remote_repo_post_init=remote_repo_post_init,
init_cmd_args=init_cmd_args,
)
if remote_repo_name is None:
remote_repo_name = unique_repo_name(remote_repos_path=remote_repos_path)
remote_repo_path = remote_repos_path / remote_repo_name

shutil.copytree(empty_git_repo, remote_repo_path)

if remote_repo_post_init is not None and callable(remote_repo_post_init):
remote_repo_post_init(remote_repo_path=remote_repo_path)

return remote_repo_path

# return _create_git_remote_repo(
# remote_repos_path=remote_repos_path,
# remote_repo_name=remote_repo_name
# if remote_repo_name is not None
# else unique_repo_name(remote_repos_path=remote_repos_path),
# remote_repo_post_init=remote_repo_post_init,
# init_cmd_args=init_cmd_args,
# )

return fn

Expand Down

0 comments on commit 99fa170

Please sign in to comment.