Skip to content

Commit 94dd9a9

Browse files
committed
gh-156064: Make patchcheck find the upstream remote in a partial clone
Since Git 2.37, ``git remote -v`` appends the object filter of a promisor remote to its fetch line (``... (fetch) [blob:none]``), so matching ``(fetch)`` at the end of the line missed the upstream remote of a partial clone, and also left it out of the "Remotes found" list in the error.
1 parent 20e6c2f commit 94dd9a9

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

Tools/patchcheck/patchcheck.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,20 +68,24 @@ def get_git_upstream_remote():
6868
cwd=SRCDIR,
6969
encoding="UTF-8"
7070
)
71+
# Keep the "(fetch)" lines only. A partial clone lists its filter after
72+
# the URL type, e.g. "upstream\thttps://github.com/python/cpython (fetch)
73+
# [blob:none]", so "(fetch)" is not necessarily at the end of the line.
74+
fetch_remotes = [
75+
remote for remote in output.split('\n') if "(fetch)" in remote
76+
]
7177
# Filter to desired remotes, accounting for potential uppercasing
7278
filtered_remotes = {
73-
remote.split("\t")[0].lower() for remote in output.split('\n')
74-
if "python/cpython" in remote.lower() and remote.endswith("(fetch)")
79+
remote.split("\t")[0].lower() for remote in fetch_remotes
80+
if "python/cpython" in remote.lower()
7581
}
7682
if len(filtered_remotes) == 1:
7783
[remote] = filtered_remotes
7884
return remote
7985
for remote_name in ["upstream", "origin", "python"]:
8086
if remote_name in filtered_remotes:
8187
return remote_name
82-
remotes_found = "\n".join(
83-
{remote for remote in output.split('\n') if remote.endswith("(fetch)")}
84-
)
88+
remotes_found = "\n".join(fetch_remotes)
8589
raise ValueError(
8690
f"Patchcheck was unable to find an unambiguous upstream remote, "
8791
f"with URL matching 'https://github.com/python/cpython'. "

0 commit comments

Comments
 (0)