patchcheck: use URL paths to identify upstream remote (GH-135806)
Some checks are pending
Tests / Docs (push) Blocked by required conditions
Tests / Windows MSI (push) Blocked by required conditions
Tests / Check if Autoconf files are up to date (push) Blocked by required conditions
Tests / Change detection (push) Waiting to run
Tests / Check if generated files are up to date (push) Blocked by required conditions
Tests / (push) Blocked by required conditions
Tests / Ubuntu SSL tests with OpenSSL (push) Blocked by required conditions
Tests / WASI (push) Blocked by required conditions
Tests / Hypothesis tests on Ubuntu (push) Blocked by required conditions
Tests / Address sanitizer (push) Blocked by required conditions
Tests / Undefined behavior sanitizer (push) Blocked by required conditions
Tests / Cross build Linux (push) Blocked by required conditions
Tests / CIFuzz (push) Blocked by required conditions
Tests / All required checks pass (push) Blocked by required conditions
Lint / lint (push) Waiting to run
mypy / Run mypy on Lib/_pyrepl (push) Waiting to run
mypy / Run mypy on Lib/test/libregrtest (push) Waiting to run
mypy / Run mypy on Lib/tomllib (push) Waiting to run
mypy / Run mypy on Tools/build (push) Waiting to run
mypy / Run mypy on Tools/clinic (push) Waiting to run
mypy / Run mypy on Tools/cases_generator (push) Waiting to run
mypy / Run mypy on Tools/jit (push) Waiting to run
mypy / Run mypy on Tools/peg_generator (push) Waiting to run

* find defined "(fetch)" remotes with "python/cpython" in their URL
* if there is exactly one, use that remote name
* if there is one named "upstream", "origin", or "python",
  use that remote (in that precedence order)
* otherwise report an error listing the defined remotes
This commit is contained in:
Kattni 2025-06-22 00:51:23 -04:00 committed by GitHub
parent b14986c914
commit ac9d37c60b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 37 additions and 12 deletions

View file

@ -943,6 +943,7 @@ Anton Kasyanov
Lou Kates
Makoto Kato
Irit Katriel
Kattni
Hiroaki Kawai
Dmitry Kazakov
Brian Kearns

View file

@ -53,19 +53,43 @@ def get_git_branch():
def get_git_upstream_remote():
"""Get the remote name to use for upstream branches
Uses "upstream" if it exists, "origin" otherwise
"""
cmd = "git remote get-url upstream".split()
try:
subprocess.check_output(cmd,
stderr=subprocess.DEVNULL,
cwd=SRCDIR,
encoding='UTF-8')
except subprocess.CalledProcessError:
return "origin"
return "upstream"
Get the remote name to use for upstream branches
Check for presence of "https://github.com/python/cpython" remote URL.
If only one is found, return that remote name. If multiple are found,
check for and return "upstream", "origin", or "python", in that
order. Raise an error if no valid matches are found.
"""
cmd = "git remote -v".split()
output = subprocess.check_output(
cmd,
stderr=subprocess.DEVNULL,
cwd=SRCDIR,
encoding="UTF-8"
)
# Filter to desired remotes, accounting for potential uppercasing
filtered_remotes = {
remote.split("\t")[0].lower() for remote in output.split('\n')
if "python/cpython" in remote.lower() and remote.endswith("(fetch)")
}
if len(filtered_remotes) == 1:
[remote] = filtered_remotes
return remote
for remote_name in ["upstream", "origin", "python"]:
if remote_name in filtered_remotes:
return remote_name
remotes_found = "\n".join(
{remote for remote in output.split('\n') if remote.endswith("(fetch)")}
)
raise ValueError(
f"Patchcheck was unable to find an unambiguous upstream remote, "
f"with URL matching 'https://github.com/python/cpython'. "
f"For help creating an upstream remote, see Dev Guide: "
f"https://devguide.python.org/getting-started/"
f"git-boot-camp/#cloning-a-forked-cpython-repository "
f"\nRemotes found: \n{remotes_found}"
)
def get_git_remote_default_branch(remote_name):