test(project-scanner): tighten git helper env handling

Agent-Logs-Url: https://github.com/MemPalace/mempalace/sessions/3c277c46-20b3-4a43-8eb7-8ee2eb3cb55a

Co-authored-by: igorls <4753812+igorls@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-04-24 03:50:13 +00:00
committed by GitHub
parent 70d4c5471e
commit 851ebebc29
2 changed files with 14 additions and 9 deletions
-3
View File
@@ -296,10 +296,7 @@ def _looks_like_real_name(name: str) -> bool:
def _walk(root: Path, max_depth: int = MAX_DEPTH):
for dirpath, dirs, files in os.walk(root):
dirs[:] = [d for d in dirs if d not in SKIP_DIRS and not d.startswith(".")]
try:
rel = Path(dirpath).relative_to(root)
except ValueError:
continue
depth = 0 if rel == Path(".") else len(rel.parts)
if depth > max_depth:
dirs.clear()
+13 -5
View File
@@ -221,17 +221,25 @@ def _require_git() -> None:
pytest.skip("git executable not available")
def _git_commit(
path: Path, filename: str, content: str, message: str, name: str, email: str
) -> None:
_require_git()
def _git_test_env(name: str, email: str) -> dict[str, str]:
env = {
**os.environ,
"GIT_AUTHOR_NAME": name,
"GIT_AUTHOR_EMAIL": email,
"GIT_COMMITTER_NAME": name,
"GIT_COMMITTER_EMAIL": email,
}
for key in ("PATH", "HOME", "SystemRoot", "ComSpec", "TMPDIR", "TEMP", "TMP"):
value = os.environ.get(key)
if value:
env[key] = value
return env
def _git_commit(
path: Path, filename: str, content: str, message: str, name: str, email: str
) -> None:
_require_git()
env = _git_test_env(name, email)
(path / filename).write_text(content)
subprocess.run(["git", "add", filename], cwd=path, check=True, env=env)
subprocess.run(["git", "commit", "-q", "-m", message], cwd=path, check=True, env=env)