MCPcopy Index your code
hub / github.com/python/cpython / get_git_upstream_remote

Function get_git_upstream_remote

Tools/patchcheck/patchcheck.py:55–92  ·  view source on GitHub ↗

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

()

Source from the content-addressed store, hash-verified

53
54
55def get_git_upstream_remote():
56 """
57 Get the remote name to use for upstream branches
58
59 Check for presence of "https://github.com/python/cpython" remote URL.
60 If only one is found, return that remote name. If multiple are found,
61 check for and return "upstream", "origin", or "python", in that
62 order. Raise an error if no valid matches are found.
63 """
64 cmd = "git remote -v".split()
65 output = subprocess.check_output(
66 cmd,
67 stderr=subprocess.DEVNULL,
68 cwd=SRCDIR,
69 encoding="UTF-8"
70 )
71 # Filter to desired remotes, accounting for potential uppercasing
72 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)")
75 }
76 if len(filtered_remotes) == 1:
77 [remote] = filtered_remotes
78 return remote
79 for remote_name in ["upstream", "origin", "python"]:
80 if remote_name in filtered_remotes:
81 return remote_name
82 remotes_found = "\n".join(
83 {remote for remote in output.split('\n') if remote.endswith("(fetch)")}
84 )
85 raise ValueError(
86 f"Patchcheck was unable to find an unambiguous upstream remote, "
87 f"with URL matching 'https://github.com/python/cpython'. "
88 f"For help creating an upstream remote, see Dev Guide: "
89 f"https://devguide.python.org/getting-started/"
90 f"git-boot-camp/#cloning-a-forked-cpython-repository "
91 f"\nRemotes found: \n{remotes_found}"
92 )
93
94
95def get_git_remote_default_branch(remote_name):

Callers 1

get_base_branchFunction · 0.85

Calls 5

splitMethod · 0.45
check_outputMethod · 0.45
lowerMethod · 0.45
endswithMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…