merge_check: exit 2 when git cannot be run (MERGE-CHECK-GIT-MISSING) #610
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
missing claim
needs rebase
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/ubiquitarianism--leonida!610
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/610/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@TuroYT on GitHub · 2026-11-24 09:54 UTC · original
TuroYT:fix/merge-check-git-missing→main· +31 −1 · 2 files · 1 commits · merged 2026-11-24 12:44 UTCClaimed in the coordination issue as: MERGE-CHECK-GIT-MISSING (#14)
The docstring of
scripts/merge_check.py(line 21) says exit 2 on a usage or git error. Butgit()(line 45) callssubprocess.runwith no handling for a missing executable. With git not on PATH, that raisesFileNotFoundError.maincatches onlyGitError, so the script printed a traceback and exited 1.The change:
git()turns theOSErrorfromsubprocess.runintoGitError("cannot run git: <strerror>").mainalready prints aGitErrorto stderr and returns 2.git()is the only place the script runs git, so this covers every caller (prior_merges,cherry,merged_tree,rev_tree,duplicates).Before:
env PATH=/nonexistent /usr/bin/python3 -I scripts/merge_check.py 1=HEADprinted a traceback and exited 1.After: it prints
merge_check: cannot run git: No such file or directoryand exits 2.Tests added to
tests/test_merge_check.py:subprocess.runpatched to raiseFileNotFoundError; asserts exit 2, the exact message on stderr, no traceback.PATHset toos.devnull; same assertions.The first two fail on the unfixed script with 2 errors (
FileNotFoundError).Overlap with #242 and #300: both change
scripts/merge_check.pyoutsidegit(). #242 edits lines 65, 110-113 and 132 (argument order forlog,diff,show). #300 edits line 66 (splitlinestosplit). This PR changes lines 44-51 only, so the hunks do not overlap. I did not check thetests/test_merge_check.pyhunks of #242 and #300. This PR appends tests aftertest_usage_errors; if either of them also appends at the end of the class, that one will need a rebase.Tested:
python3 -m compileall -q scripts tests: exit 0.python3 -I tests/test_merge_check.py: Ran 23 tests, OK.scripts/merge_check.pyfrom origin/main: 2 errors, bothFileNotFoundError, as expected.env PATH=/nonexistent /usr/bin/python3 -I scripts/merge_check.py 1=HEAD:merge_check: cannot run git: No such file or directory, exit 2 (was a traceback and exit 1).python3 -I scripts/merge_check.pywith no arguments: argparse usage message, exit 2.python3 -I scripts/merge_check.py --repo /tmp 1=HEAD: git reports "not a git repository", exit 2.env -u PATH /usr/bin/python3 -I scripts/merge_check.py 1=HEAD: git is still found through the default search path, exit 1. This is not a missing-git case; the empty-PATH test covers that.python3 -I tests/test_text_write_line_endings.py: Ran 3 tests, OK.python3 -I scripts/check_no_game_data.py scripts/merge_check.py tests/test_merge_check.py: exit 0.Not tested: Windows (the mocked test does not depend on the platform, but the empty-PATH test checks only the message prefix there); CI on other Python versions; this branch together with #242 and #300.
AI-assisted (Claude Code).
@Dezmonius on GitHub · 2026-11-24 10:24 UTC · original
Independent Windows 10 22H2 check at
5abe553against main21625bc, using CPython 3.14.7 and Git for Windows 2.56.0.windows.4. All 23test_merge_check.pytests passed.I also ran the CLI with
--jsonin separate Python processes:merge_check: cannot run git:git.exemerge_check: cannot run git:The PR leaves stdout empty in all three failure cases and emits no traceback. I also combined the test change from #621 locally: all 23 tests still passed with
docs/in the isolated profile's global ignore file.Synthetic repositories and fixture only. AI-assisted (Codex).
@madvillain91 on GitHub · 2026-11-24 10:24 UTC · original · reviewed
Tested locally on Windows 11 — all 23 tests in \ ests/test_merge_check.py\ pass (including \ est_git_missing_from_an_empty_path_is_a_git_error\ with \PATH=os.devnull). The \OSError\ handling in \git()\ and the --json\ empty-stdout check look clean. LGTM.