Skip to content
Merged
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
22 changes: 12 additions & 10 deletions .github/scripts/api_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,16 +208,18 @@ def create_pr_or_update_branch_on_api_repo(
print(f"Cloning {api_repo_url} into temporary directory...")
api_repo = Repo.clone_from(api_repo_url, temp_dir)

# Checkout existing branch or create a new branch
print(f"Switching to branch: {branch_name}")
api_repo.git.checkout('-B', branch_name)

# Pull remote branch contents if it exists so we commit on top
try:
api_repo.git.pull('origin', branch_name)
print(f"Pulled latest from origin/{branch_name}")
except GitCommandError:
print(f"No existing remote branch '{branch_name}' to pull.")
# Continue the branch if it already exists, so the push is a fast
# forward. Starting it from main and pulling the remote branch in
# fails once main has commits the branch lacks, such as another
# repository's merged docs.
remote_branch = f"origin/{branch_name}"
remote_branches = [ref.name for ref in api_repo.remotes.origin.refs]
if remote_branch in remote_branches:
print(f"Switching to branch: {branch_name} ({remote_branch})")
api_repo.git.checkout('-B', branch_name, remote_branch)
else:
print(f"Switching to new branch: {branch_name} (from main)")
api_repo.git.checkout('-B', branch_name)

# Create repo directory if it doesn't exist
repo_dir = os.path.join(temp_dir, repo_name)
Expand Down
Loading