mirror of
https://github.com/boykopovar/AnyPS5.git
synced 2026-11-04 13:07:32 +00:00
15 lines
567 B
Python
15 lines
567 B
Python
import subprocess
|
|
|
|
CANDIDATES = ("upstream/main", "origin/main", "main")
|
|
|
|
|
|
def resolve(repo, name=None):
|
|
if name:
|
|
return name
|
|
for candidate in CANDIDATES:
|
|
found = subprocess.run(["git", "-C", str(repo), "rev-parse", "--verify", "--quiet", f"{candidate}^{{commit}}"],
|
|
capture_output=True, text=True, encoding="utf-8", errors="replace")
|
|
if found.returncode == 0:
|
|
return candidate
|
|
raise ValueError(f"no base branch found ({', '.join(CANDIDATES)}); fetch the upstream remote or pass --base")
|