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
()
| 53 | |
| 54 | |
| 55 | def 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 | |
| 95 | def get_git_remote_default_branch(remote_name): |
no test coverage detected
searching dependent graphs…