From ad59120ba8fae02ccb8e7e4251d0770022e87b92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20ROBERT?= Date: Sat, 31 Oct 2026 09:23:44 +0100 Subject: [PATCH] fix(garde-fous): le test des verdicts ne touche plus au vrai depot depuis un worktree Lance par le hook de commit, test_verdicts_et_commun_separes.py heritait de GIT_DIR et GIT_INDEX_FILE. Dans un worktree ces chemins sont absolus : le depot jetable du test ecrivait core.bare=true et l'identite de test dans la configuration du vrai depot, et remplacait l'index du worktree. Constate le 2026-10-31. L'assistant _git retire desormais les variables GIT_* de son environnement. --- tests/test_verdicts_et_commun_separes.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/test_verdicts_et_commun_separes.py b/tests/test_verdicts_et_commun_separes.py index 20edf83..b9318a6 100644 --- a/tests/test_verdicts_et_commun_separes.py +++ b/tests/test_verdicts_et_commun_separes.py @@ -14,6 +14,7 @@ from __future__ import annotations +import os import subprocess from pathlib import Path @@ -23,6 +24,17 @@ OUTIL = RACINE / "tests" / "outils" / "verdicts_et_commun_separes.py" +def _env_sans_git() -> dict[str, str]: + # Lance depuis un hook de commit, ce test herite de GIT_DIR et de + # GIT_INDEX_FILE. Dans un worktree, ces chemins sont ABSOLUS et visent le + # vrai depot : `git init`, `git config` et `git add -A` du depot jetable + # ecrivaient alors dans sa configuration (core.bare, identite « Banc ») et + # remplacaient l'index du worktree, et l'outil lisait l'index du worktree + # au lieu de celui du depot jetable. Constate le 2026-10-31. Sans ces + # variables, git ne voit que le depot jetable. + return {k: v for k, v in os.environ.items() if not k.startswith("GIT_")} + + def _git(depot: Path, *args: str) -> subprocess.CompletedProcess[str]: return subprocess.run( ["git", "-C", str(depot), *args], @@ -30,6 +42,7 @@ def _git(depot: Path, *args: str) -> subprocess.CompletedProcess[str]: capture_output=True, text=True, timeout=30, + env=_env_sans_git(), ) @@ -72,6 +85,7 @@ def _jouer(depot: Path) -> subprocess.CompletedProcess[str]: capture_output=True, text=True, timeout=30, + env=_env_sans_git(), )