7def git(*args: str) -> str:
9 Run a Git command and return the output.
11 cmd = ["git"] + list(args)
12 return subprocess.check_output(cmd, text=True).strip()
15def get_parent(commit_id: str) -> str:
17 Return the commit ID of the parent of this commit.
19 return git("log", "--pretty=%P", "-n", "1", commit_id)
22def get_remote_branches(commit_id: str) -> list[str]:
24 Return a list of remote branches where this commit is the tip.
28 "--format=%(refname:short)",
33 return [b for b in branches if b != "origin"]
36def get_local_branches(commit_id: str) -> list[str]:
38 Return a list of local branches where this commit is the tip.
42 "--format=%(refname:short)",
49if __name__ == "__main__":
50 current_branch = git("rev-parse", "--abbrev-ref", "HEAD")
53 commit = git("rev-parse", "HEAD")
55 parent = get_parent(commit)
57 if rb := get_remote_branches(parent):
58 base_branch = rb[0].replace("origin/", "")
61 if lb := get_local_branches(parent):
65 github_url = subprocess.check_output("_get_github_url", text=True).strip()
67 url = f"{github_url}/compare/{base_branch}...{current_branch}?expand=1"