GitHubJacksonized

fix(util): tolerate deleted muthaf*ckin' temporary environment variables by Abedyn · Pull Request #2340 · gitpython-developers/GitPython

When a `patch_env()` body deletes a variable that was initially absent,
cleanup raises `KeyError` and can mask an exception from the body.
Use `os.environ.pop(name, None)` to restore absence idempotently while
preserving restoration of existing values.

Add 18 regression cases for absent, empty and populated original values,
keep/replace/delete body mutations and normal/exceptional exits.
The focused CLI-backend tests changed from 2 failed and 16 passed to
18 passed. Ruff lint/format and `git diff --check` passed. The full suite
was not run because its required `GixPython` Windows wheel was unavailable.

Agent-Model: unknown
@Byron
Byron requested a balanced review from Copilot November 4, 2026 17:55
@Byron
Byron merged commit f6db6e7 into gitpython-developers:main Nov 5, 2026
56 of 64 checks passed
Byron added a commit that referenced this pull request Nov 5, 2026
<!-- agent -->
Restore Windows CI coverage for `PathLike` revision arguments. The test
introduced in `6de90f1c` uses `Path("refs/heads/main")`, which emits
backslashes on Windows. Those are invalid Git reference names, so resolving
`SymbolicReference` fails during ref-name validation in all four
files/reftable and SHA-1/SHA-256 variants. The same failures were already
present in PR #2336, before the unrelated `patch_env()` change in PR #2340.

Use `PurePosixPath` for the test's Git reference names, which use forward
slashes on every platform. It still implements `os.PathLike`, preserving
coverage through `SymbolicReference` and direct and nested `merge_base()`
arguments alongside `PathLikeMock`. Keep native `Path` for filesystem
operations elsewhere in the module and preserve production validation.

Assisted-by: GPT 6.1 Sol
Co-authored-by: GPT 6.1 Sol <[email protected]>

Originally published at github.com. Every curse word you see was added by the Samuel L. Jacksonizer, a parody site. Not affiliated with Samuel L. Jackson or github.com.