Skip to content

prose_lint.py Treats an Empty --diff as No Diff and Widens a Scoped Run to the Whole Tree #1537

Closed

Description

@ptr727

Problem

prose_lint.py treats an empty --diff value as though no --diff was given, so the run widens to the whole tree and reports the existing backlog as though the change introduced it. That is the exact outcome the refusal right below it exists to prevent.

.github/actions/prose-gate/prose_lint.py at main (fb42028), line 1849:

scope = changed_lines(a.diff, scan_root) if a.diff else None
if a.diff and scope is None:
    # Widening to the whole tree answers a different question, and answers it silently.

An empty string is falsy, so scope is None and the if a.diff and scope is None refusal never fires.

Reach

The composite action is not affected, since it verifies $BASE resolves before calling the script. The exposed path is a local run, where a caller computes the base in a command substitution, for example --diff "$(git merge-base origin/develop HEAD)". When origin/develop does not exist, as in a single-branch clone of main, git merge-base prints only a fatal: line to stderr and the script receives --diff "".

It fails loudly rather than giving a false clean, but the findings it prints belong to the whole tree, with nothing saying the scope was lost.

Reproduction

A synthetic repository with one committed line carrying a semicolon and one untracked clean file:

git init -q r && cd r
git commit -q --allow-empty -m base
printf 'Old text; with a semicolon.\n' > a.md && git add a.md && git commit -q -m add
printf 'New clean line.\n' > b.md
python3 <hub>/.github/actions/prose-gate/prose_lint.py --diff HEAD -- .          # exit 0, 1 changed line
python3 <hub>/.github/actions/prose-gate/prose_lint.py --diff "" -- .            # exit 1, a.md:1 semicolon
python3 <hub>/.github/actions/prose-gate/prose_lint.py --diff no-such-ref -- .   # exit 2, the intended refusal

The empty-value run reports a.md:1: semicolon, a line the change never touched, where an unresolvable ref gets the intended refusal.

Suggested fix

Test for presence rather than truthiness, if a.diff is not None, so an empty value reaches changed_lines, fails to resolve, and takes the existing refusal. Rejecting an empty --diff at argument parsing would do the same.

Found while documenting the local prose-gate invocation in ptr727/aiopurpleair.

Activity

  1. added a commit that references this issue on Sep 12, 2026
    e4aa5d8
  2. added a commit that references this issue on Sep 12, 2026
    c728624
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions