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

Function get_git_remote_default_branch

Tools/patchcheck/patchcheck.py:95–115  ·  view source on GitHub ↗

Get the name of the default branch for the given remote It is typically called 'main', but may differ

(remote_name)

Source from the content-addressed store, hash-verified

93
94
95def get_git_remote_default_branch(remote_name):
96 """Get the name of the default branch for the given remote
97
98 It is typically called 'main', but may differ
99 """
100 cmd = f"git remote show {remote_name}".split()
101 env = os.environ.copy()
102 env['LANG'] = 'C'
103 try:
104 remote_info = subprocess.check_output(cmd,
105 stderr=subprocess.DEVNULL,
106 cwd=SRCDIR,
107 encoding='UTF-8',
108 env=env)
109 except subprocess.CalledProcessError:
110 return None
111 for line in remote_info.splitlines():
112 if "HEAD branch:" in line:
113 base_branch = line.split(":")[1].strip()
114 return base_branch
115 return None
116
117
118@status("Getting base branch for PR",

Callers 1

get_base_branchFunction · 0.85

Calls 5

splitMethod · 0.45
copyMethod · 0.45
check_outputMethod · 0.45
splitlinesMethod · 0.45
stripMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…