https://github.com/python/cpython/commit/b79e64b67dcd48d8482d49b2c2f24b430f8f20db
commit: b79e64b67dcd48d8482d49b2c2f24b430f8f20db
branch: 3.13
author: Miss Islington (bot) <31488909+miss-isling...@users.noreply.github.com>
committer: hugovk <1324225+hug...@users.noreply.github.com>
date: 2025-06-23T12:57:03+03:00
summary:

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

Co-authored-by: Kattni <kat...@kattni.com>

files:
M Misc/ACKS
M Tools/patchcheck/patchcheck.py

diff --git a/Misc/ACKS b/Misc/ACKS
index 3adb168f33c40a..d2fdeb8f3178fe 100644
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -931,6 +931,7 @@ Anton Kasyanov
 Lou Kates
 Makoto Kato
 Irit Katriel
+Kattni
 Hiroaki Kawai
 Dmitry Kazakov
 Brian Kearns
diff --git a/Tools/patchcheck/patchcheck.py b/Tools/patchcheck/patchcheck.py
index af1f0584bb5403..22a8059f1670a0 100755
--- a/Tools/patchcheck/patchcheck.py
+++ b/Tools/patchcheck/patchcheck.py
@@ -65,19 +65,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):

_______________________________________________
Python-checkins mailing list -- python-checkins@python.org
To unsubscribe send an email to python-checkins-le...@python.org
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: arch...@mail-archive.com

Reply via email to