40 lines
1.2 KiB
Python
40 lines
1.2 KiB
Python
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
import subprocess
|
|
import sys
|
|
import unittest
|
|
from unittest.mock import patch
|
|
|
|
|
|
META_ROOT = Path(__file__).resolve().parents[1]
|
|
RELEASE_TOOLS_ROOT = META_ROOT / "tools" / "release"
|
|
|
|
if str(RELEASE_TOOLS_ROOT) not in sys.path:
|
|
sys.path.insert(0, str(RELEASE_TOOLS_ROOT))
|
|
|
|
from govoplan_release import git_state # noqa: E402
|
|
|
|
|
|
class ReleaseGitStateTests(unittest.TestCase):
|
|
def test_git_trusts_only_the_resolved_repository_for_each_command(self) -> None:
|
|
repository = Path("/workspace/../workspace/govoplan-core")
|
|
completed = subprocess.CompletedProcess([], 0, "", "")
|
|
|
|
with patch.object(git_state.subprocess, "run", return_value=completed) as run:
|
|
result = git_state.git(repository, "status", "--porcelain")
|
|
|
|
self.assertEqual(result.returncode, 0)
|
|
command = run.call_args.args[0]
|
|
self.assertIn(f"safe.directory={repository.resolve()}", command)
|
|
self.assertNotIn("safe.directory=*", command)
|
|
self.assertEqual(run.call_args.kwargs["cwd"], repository)
|
|
self.assertEqual(
|
|
run.call_args.kwargs["env"]["GIT_CONFIG_GLOBAL"],
|
|
"/dev/null",
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|