[PR #610] [MERGED] merge_check: exit 2 when git cannot be run (MERGE-CHECK-GIT-MISSING) #650

Closed
opened 2026-11-26 20:18:35 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/610
Author: @TuroYT
Created: 11/24/2026
Status: ✅ Merged
Merged: 11/24/2026
Merged by: @ubiquitarianism

Base: main ← Head: fix/merge-check-git-missing


📝 Commits (1)

  • 5abe553 merge_check: exit 2 when git cannot be run (MERGE-CHECK-GIT-MISSING)

📊 Changes

2 files changed (+31 additions, -1 deletions)

View changed files

📝 scripts/merge_check.py (+4 -1)
📝 tests/test_merge_check.py (+27 -0)

📄 Description

Claimed in the coordination issue as: MERGE-CHECK-GIT-MISSING (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7127995605)

The docstring of scripts/merge_check.py (line 21) says exit 2 on a usage or git error. But git() (line 45) calls subprocess.run with no handling for a missing executable. With git not on PATH, that raises FileNotFoundError. main catches only GitError, so the script printed a traceback and exited 1.

The change: git() turns the OSError from subprocess.run into GitError("cannot run git: <strerror>"). main already prints a GitError to 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=HEAD printed a traceback and exited 1.
After: it prints merge_check: cannot run git: No such file or directory and exits 2.

Tests added to tests/test_merge_check.py:

  • subprocess.run patched to raise FileNotFoundError; asserts exit 2, the exact message on stderr, no traceback.
  • PATH set to os.devnull; same assertions.
  • A folder that is not a repository: git exits 128, and the script still returns 2. This one passes on the unfixed script too; it guards the existing nonzero-exit path.

The first two fail on the unfixed script with 2 errors (FileNotFoundError).

Overlap with #242 and #300: both change scripts/merge_check.py outside git(). #242 edits lines 65, 110-113 and 132 (argument order for log, diff, show). #300 edits line 66 (splitlines to split). This PR changes lines 44-51 only, so the hunks do not overlap. I did not check the tests/test_merge_check.py hunks of #242 and #300. This PR appends tests after test_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.
  • Same test file with scripts/merge_check.py from origin/main: 2 errors, both FileNotFoundError, 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.py with 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).


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/610 **Author:** [@TuroYT](https://github.com/TuroYT) **Created:** 11/24/2026 **Status:** ✅ Merged **Merged:** 11/24/2026 **Merged by:** [@ubiquitarianism](https://github.com/ubiquitarianism) **Base:** `main` ← **Head:** `fix/merge-check-git-missing` --- ### 📝 Commits (1) - [`5abe553`](https://github.com/ubiquitarianism/leonida/commit/5abe553f5fcc1e373ebf4f9e640cf2aec79b69e7) merge_check: exit 2 when git cannot be run (MERGE-CHECK-GIT-MISSING) ### 📊 Changes **2 files changed** (+31 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `scripts/merge_check.py` (+4 -1) 📝 `tests/test_merge_check.py` (+27 -0) </details> ### 📄 Description Claimed in the coordination issue as: MERGE-CHECK-GIT-MISSING (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7127995605) The docstring of `scripts/merge_check.py` (line 21) says exit 2 on a usage or git error. But `git()` (line 45) calls `subprocess.run` with no handling for a missing executable. With git not on PATH, that raises `FileNotFoundError`. `main` catches only `GitError`, so the script printed a traceback and exited 1. The change: `git()` turns the `OSError` from `subprocess.run` into `GitError("cannot run git: <strerror>")`. `main` already prints a `GitError` to 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=HEAD` printed a traceback and exited 1. After: it prints `merge_check: cannot run git: No such file or directory` and exits 2. Tests added to `tests/test_merge_check.py`: - `subprocess.run` patched to raise `FileNotFoundError`; asserts exit 2, the exact message on stderr, no traceback. - `PATH` set to `os.devnull`; same assertions. - A folder that is not a repository: git exits 128, and the script still returns 2. This one passes on the unfixed script too; it guards the existing nonzero-exit path. The first two fail on the unfixed script with 2 errors (`FileNotFoundError`). Overlap with #242 and #300: both change `scripts/merge_check.py` outside `git()`. #242 edits lines 65, 110-113 and 132 (argument order for `log`, `diff`, `show`). #300 edits line 66 (`splitlines` to `split`). This PR changes lines 44-51 only, so the hunks do not overlap. I did not check the `tests/test_merge_check.py` hunks of #242 and #300. This PR appends tests after `test_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. - Same test file with `scripts/merge_check.py` from origin/main: 2 errors, both `FileNotFoundError`, 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.py` with 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). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 20:18:35 +01:00
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#650
No description provided.