Skip to content

scripts: pr_overlap.py lists the open pull requests that change the same files (PR-OVERLAP-CHECK) - #2349

Draft
syfyra wants to merge 1 commit into
ProjectLeonida:mainfrom
syfyra:feat/pr-overlap-check
Draft

syfyra wants to merge 1 commit into
ProjectLeonida:mainfrom
syfyra:feat/pr-overlap-check

Conversation

@syfyra

@syfyra syfyra commented Nov 26, 2026

Copy link
Copy Markdown

Claimed in the coordination issue as: PR-OVERLAP-CHECK (#1608 (comment))

Depends on: none. It merges cleanly with the two open pull requests that change the same files (#2103 in AGENTS.md, #2151 in AGENTS.md and CONTRIBUTING.md), as the script itself reports.

What and why

There is no working way to find the open pull requests that touch a file. GitHub's search does not match pull requests by path: the VIEWER-HUNT finding in the coordination issue records gh search prs 'path:viewer/' returning nothing while four open pull requests changed those files. With about 1,490 pull requests open, reading them is not an option, so work gets written twice, and the template's Depends on: line (every pull request this one builds on or conflicts with) is filled in from memory.

scripts/pr_overlap.py asks git instead, with no API call and no token:

  • The open pull requests are the ones the remote has a refs/pull/N/merge for. GitHub keeps that ref while a pull request is open: git ls-remote showed 1,485 of them today (of 2,283 pull request heads), against 1,484 open pull requests in the search API, 317 of them labeled needs rebase.
  • Their heads are fetched into refs/pr-overlap/N, a namespace of the tool. Refs of pull requests that are no longer open are deleted, so the namespace is the open set as of the last run and --no-fetch works offline.
  • A pull request's files are those that differ between its head and its merge base with --base (default origin/main), so what main changed since it branched is not counted as its own. A rename counts as both paths.

python -I scripts/pr_overlap.py <file or folder>... lists the open pull requests that change those paths: the check to run before starting on a file. With no argument it takes the branch's own files (committed against the merge base, plus what is modified or untracked in the working tree) and says how the branch stands to each pull request that changes one of them: clean or conflict from git merge-tree, with the conflicting files, same for the branch's own pull request, included for one the branch is built on. --json gives the same as one object.

It writes refs under refs/pr-overlap/ and nothing else: no tags, no FETCH_HEAD, and no pull request code is checked out or run. AGENTS.md and CONTRIBUTING.md name it where they ask to check the open pull requests.

What it found on real branches here:

Tested

Windows 11, Python 3.14.7, git 2.55.0:

  • python -I tests/test_pr_overlap.py: 19 tests on throwaway repositories, an "upstream" with refs/pull/N/head and refs/pull/N/merge laid out as GitHub does and a clone of it. They cover paths and folders, closed pull requests left out, files measured from the merge base, renames, paths relative to the current folder and with spaces and non-ASCII names, the branch mode with committed, modified and untracked files, the four standings, the kept refs following the open set, --no-fetch with the remote gone, a fork as origin, a shallow clone, and the errors.
  • The test file fails on main, where the script does not exist.
  • 43 one-line changes to the script (heads taken from the merge refs, a two-dot diff, a prefix match without the slash, kept tags, and so on) each make at least one test fail.
  • On this repository: a run takes about 5 s for 1,492 open pull requests with 16 git processes at a time, --no-fetch about 4.6 s. The first run fetched 1,487 heads and took 12 s, in a clone that already had most of their objects from an earlier fetch of the pull request refs; a clone without them will take longer.
  • python -I on tests/test_tool_stdout_encoding.py, tests/test_text_write_line_endings.py, tests/test_ci_registration.py, the 13 tests/test_docs_*.py and tests/test_i18n_index.py; python -I scripts/check_no_game_data.py on the four changed files.
  • Not tested: Linux and macOS (the script and its tests use only git and the standard library, but I ran them on Windows), Python 3.12, which CI runs (contextlib.chdir in the test needs 3.11), a git older than 2.55 (2.29 for fetch --stdin and 2.38 for merge-tree --write-tree are from git's release notes, not from a run), and a host other than GitHub (the merge-ref rule is GitHub's).

GPUs tested: n/a

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (No translator rule in this change.)

🤖 Generated with Claude Code

…ame files (PR-OVERLAP-CHECK)

There was no working way to find the open pull requests that touch a file:
GitHub's search does not match pull requests by path, and with about 1,490
of them open, reading them is not an option. Work gets written twice, and
the template's "Depends on:" line (every pull request this one conflicts
with) is filled in from memory.

scripts/pr_overlap.py asks git instead, with no API call and no token.
The open pull requests are the ones the remote has a refs/pull/N/merge
for; their heads are fetched into refs/pr-overlap/N, a namespace of the
tool that follows the open set, so --no-fetch works offline. A pull
request's files are those that differ between its head and its merge base
with the base branch.

With paths it lists the open pull requests that change them. With none it
takes the branch's own files, committed or in the working tree, and says
how the branch stands to each pull request that changes one: clean or
conflict (git merge-tree, with the conflicting files), same, or included.

AGENTS.md and CONTRIBUTING.md name it where they ask to check the open
pull requests.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

@lixonik lixonik left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Windows 11: 19/19 overlap tests passed. The suite used disposable local Git repos for ref discovery, dirty path handling, overlap and ref cleanup. No findings from these checks.

AI-assisted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants