Skip to content

[3.14] patchcheck: use URL paths to identify upstream remote (GH-135806) #135808

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 3.14
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Misc/ACKS
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,7 @@ Anton Kasyanov
Lou Kates
Makoto Kato
Irit Katriel
Kattni
Hiroaki Kawai
Dmitry Kazakov
Brian Kearns
Expand Down
46 changes: 35 additions & 11 deletions Tools/patchcheck/patchcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,43 @@ def get_git_branch():


def get_git_upstream_remote():
"""Get the remote name to use for upstream branches
"""
Get the remote name to use for upstream branches

Uses "upstream" if it exists, "origin" otherwise
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 get-url upstream".split()
try:
subprocess.check_output(cmd,
stderr=subprocess.DEVNULL,
cwd=SRCDIR,
encoding='UTF-8')
except subprocess.CalledProcessError:
return "origin"
return "upstream"
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):
Expand Down
Loading