diff --git a/tests/test_workspace_git.py b/tests/test_workspace_git.py index 9d228300..0d4b7dbf 100644 --- a/tests/test_workspace_git.py +++ b/tests/test_workspace_git.py @@ -47,6 +47,20 @@ def _init_repo(path): return path +def _init_bare_repo(path): + init = subprocess.run( + ["git", "init", "--bare", "-b", "master", str(path)], + shell=False, + text=True, + capture_output=True, + timeout=20, + ) + if init.returncode != 0: + _git(path.parent, "init", "--bare", str(path)) + _git(path, "symbolic-ref", "HEAD", "refs/heads/master") + return path + + def _commit_all(path, message="initial"): _git(path, "add", ".") _git(path, "commit", "-m", message) @@ -513,8 +527,7 @@ def test_staged_commit_message_prompt_uses_only_staged_diff(tmp_path): def test_git_fetch_pull_and_push_with_upstream(tmp_path): from api.workspace_git import git_fetch, git_pull, git_push, git_status - remote = tmp_path / "remote.git" - _git(tmp_path, "init", "--bare", str(remote)) + remote = _init_bare_repo(tmp_path / "remote.git") origin = _init_repo(tmp_path / "origin") (origin / "tracked.txt").write_text("one\n", encoding="utf-8") @@ -550,8 +563,7 @@ def test_git_fetch_pull_and_push_with_upstream(tmp_path): def test_git_branches_lists_local_remote_and_upstream(tmp_path): from api.workspace_git import git_branches - remote = tmp_path / "remote.git" - _git(tmp_path, "init", "--bare", str(remote)) + remote = _init_bare_repo(tmp_path / "remote.git") origin = _init_repo(tmp_path / "origin") (origin / "tracked.txt").write_text("one\n", encoding="utf-8") _commit_all(origin) @@ -575,8 +587,7 @@ def test_git_branches_lists_local_remote_and_upstream(tmp_path): def test_git_checkout_local_new_remote_dirty_and_invalid_refs(tmp_path): from api.workspace_git import GitWorkspaceError, git_branches, git_checkout - remote = tmp_path / "remote.git" - _git(tmp_path, "init", "--bare", str(remote)) + remote = _init_bare_repo(tmp_path / "remote.git") origin = _init_repo(tmp_path / "origin") (origin / "tracked.txt").write_text("one\n", encoding="utf-8") _commit_all(origin)