The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
enhance: create_litellm_branch tool to be more robust (#17874)
Alexsander Hamir762b429d6cbe
diff --git a/scripts/create_litellm_branch.sh b/scripts/create_litellm_branch.shindex 3ad6deb2915..5338ae034f2 100755--- a/scripts/create_litellm_branch.sh+++ b/scripts/create_litellm_branch.sh@@ -2,6 +2,17 @@# Script to create a branch with litellm_ prefix from a contributor's branch# Usage: ./create_litellm_branch.sh [source_branch] [new_branch_name]+#+# Examples:+# ./create_litellm_branch.sh branch-name+# ./create_litellm_branch.sh remote:branch-name+# ./create_litellm_branch.sh codgician:ghcopilot-costmap+#+# If source_branch is in format "remote:branch", the script will:+# - Automatically add the remote if it doesn't exist (assumes GitHub fork)+# - Fetch the branch from that remote+# - Create a new branch with litellm_ prefix+## If no arguments provided, uses current branch as sourceset -e@@ -33,12 +44,55 @@ print_error() {# Get source branch (default to current branch)SOURCE_BRANCH="${1:-$(git branch --show-current)}"+# Handle remote:branch format (e.g., codgician:ghcopilot-costmap)+if [[ "$SOURCE_BRANCH" == *:* ]]; then+ REMOTE_NAME="${SOURCE_BRANCH%%:*}"+ BRANCH_NAME="${SOURCE_BRANCH#*:}"++ print_info "Detected remote:branch format - remote: '$REMOTE_NAME', branch: '$BRANCH_NAME'"++ # Check if remote exists+ if ! git remote | grep -q "^${REMOTE_NAME}$"; then+ print_info "Remote '$REMOTE_NAME' not found. Attempting to add it..."++ # Try to add remote (assuming GitHub fork)+ if git remote add "$REMOTE_NAME" "https://github.com/${REMOTE_NAME}/litellm.git" 2>/dev/null; then+ print_success "Added remote '$REMOTE_NAME'"+ else+ print_error "Failed to add remote '$REMOTE_NAME'. Please add it manually:"+ print_info " git remote add $REMOTE_NAME https://github.com/${REMOTE_NAME}/litellm.git"+ exit 1+ fi+ fi++ # Fetch the branch from the remote+ print_info "Fetching branch '$BRANCH_NAME' from remote '$REMOTE_NAME'..."+ if git fetch "$REMOTE_NAME" "$BRANCH_NAME":"$BRANCH_NAME" 2>/dev/null; then+ print_success "Fetched branch '$BRANCH_NAME' from '$REMOTE_NAME'"+ SOURCE_BRANCH="$BRANCH_NAME"+ else+ # Try fetching without creating local branch+ if git fetch "$REMOTE_NAME" "$BRANCH_NAME" 2>/dev/null; then+ print_success "Fetched branch '$BRANCH_NAME' from '$REMOTE_NAME'"+ SOURCE_BRANCH="$REMOTE_NAME/$BRANCH_NAME"+ else+ print_error "Failed to fetch branch '$BRANCH_NAME' from remote '$REMOTE_NAME'"+ print_info "Please verify the remote and branch name exist"+ exit 1+ fi+ fi+fi+# Get new branch nameif [ -n "$2" ]; thenNEW_BRANCH_NAME="$2"else- # Auto-generate from source branch name- NEW_BRANCH_NAME="$SOURCE_BRANCH"+ # Auto-generate from source branch name (use just branch name, not remote/branch)+ if [[ "$SOURCE_BRANCH" == */* ]]; then+ NEW_BRANCH_NAME="${SOURCE_BRANCH##*/}"+ else+ NEW_BRANCH_NAME="$SOURCE_BRANCH"+ fifi# Remove litellm_ prefix if it already exists@@ -50,16 +104,26 @@ fi# Add litellm_ prefixNEW_BRANCH_NAME="litellm_${NEW_BRANCH_NAME}"-# Validate branch name (Git branch naming rules)-if ! [[ "$NEW_BRANCH_NAME" =~ ^[a-zA-Z0-9/._-]+$ ]]; then- print_error "Invalid branch name: $NEW_BRANCH_NAME"- print_info "Branch names can only contain alphanumeric characters, /, ., _, and -"- exit 1-fi++# Function to check if branch exists in any remote+branch_exists_in_remote() {+ local branch_name="$1"+ # Check local branches+ if git show-ref --verify --quiet refs/heads/"$branch_name"; then+ return 0+ fi+ # Check all remote branches+ for remote in $(git remote); do+ if git show-ref --verify --quiet refs/remotes/"$remote"/"$branch_name"; then+ return 0+ fi+ done+ return 1+}# Check if source branch exists-if ! git show-ref --verify --quiet refs/heads/"$SOURCE_BRANCH" && ! git show-ref --verify --quiet refs/remotes/origin/"$SOURCE_BRANCH"; then- print_error "Source branch '$SOURCE_BRANCH' does not exist locally or remotely"+if ! branch_exists_in_remote "$SOURCE_BRANCH"; then+ print_error "Source branch '$SOURCE_BRANCH' does not exist locally or in any remote"exit 1fi@@ -86,11 +150,27 @@ if [ "$CURRENT_BRANCH" != "$SOURCE_BRANCH" ]; thenif git show-ref --verify --quiet refs/heads/"$SOURCE_BRANCH"; thenprint_info "Source branch '$SOURCE_BRANCH' exists locally"else- print_info "Fetching source branch '$SOURCE_BRANCH' from remote..."- git fetch origin "$SOURCE_BRANCH":"$SOURCE_BRANCH" || {- print_error "Failed to fetch branch '$SOURCE_BRANCH' from remote"- exit 1- }+ # Find which remote has the branch+ REMOTE_WITH_BRANCH=""+ for remote in $(git remote); do+ if git show-ref --verify --quiet refs/remotes/"$remote"/"$SOURCE_BRANCH"; then+ REMOTE_WITH_BRANCH="$remote"+ break+ fi+ done++ if [ -n "$REMOTE_WITH_BRANCH" ]; then+ print_info "Source branch '$SOURCE_BRANCH' exists in remote '$REMOTE_WITH_BRANCH'"+ # Use the remote branch directly+ SOURCE_BRANCH="$REMOTE_WITH_BRANCH/$SOURCE_BRANCH"+ else+ # Try fetching from origin as fallback+ print_info "Fetching source branch '$SOURCE_BRANCH' from remote..."+ git fetch origin "$SOURCE_BRANCH":"$SOURCE_BRANCH" || {+ print_error "Failed to fetch branch '$SOURCE_BRANCH' from remote"+ exit 1+ }+ fififi