Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion ci.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,13 @@ def switch_branch(path, branch):
cur_branch = check_output('git rev-parse HEAD'.split(), cwd=path).decode().strip()
if cur_branch != branch:
branches = check_output('git ls-remote --heads origin'.split(), cwd=path)
branches = [line.split("/")[-1] for line in branches.decode().strip().split("\n")]
# Prefer refs/heads/<name> so branch names containing "/" (e.g. cursor/foo)
# are preserved; split("/")[-1] would keep only the last path segment.
branches = [
line.split("refs/heads/", 1)[-1]
for line in branches.decode().strip().split("\n")
if line.strip()
]

if branch in branches:
print(f'Switch to branch: {branch} (from {cur_branch})')
Expand Down
Loading