@@ -126,32 +126,59 @@ sync_repo() { |
| 126 | fi | 126 | fi |
| 127 | fi | 127 | fi |
| 128 | | 128 | |
| 129 | - # Case 3: Clone new repo | 129 | + # Case 3: Clone new repo with retry logic |
| 130 | local ssh_url="git@github.com:${github_org}/${repo}.git" | 130 | local ssh_url="git@github.com:${github_org}/${repo}.git" |
| 131 | - log_info "Cloning $repo (SSH)..." | 131 | + local max_retries=3 |
| 132 | - if timeout "$CLONE_TIMEOUT" git clone --progress "$ssh_url" "$repo_path" 2>&1; then | 132 | + local attempt=1 |
| 133 | - if [[ -d "$repo_path/.git" ]]; then | 133 | + local clone_success=false |
| 134 | - log_success "$repo (cloned)" | 134 | + |
| 135 | - ((total_cloned++)) || true | 135 | + while [[ $attempt -le $max_retries ]] && [[ "$clone_success" == "false" ]]; do |
| | 136 | + # Clean up any partial clone |
| | 137 | + [[ -d "$repo_path" ]] && rm -rf "$repo_path" |
| | 138 | + |
| | 139 | + if [[ $attempt -eq 1 ]]; then |
| | 140 | + log_info "Cloning $repo (SSH)..." |
| 136 | else | 141 | else |
| 137 | - log_error "$repo (clone failed - no permission?)" | 142 | + log_info "Cloning $repo (retry $attempt/$max_retries)..." |
| 138 | - failed_repos+=("${github_org}/${repo}") | | |
| 139 | - ((total_failed++)) || true | | |
| 140 | fi | 143 | fi |
| 141 | - else | 144 | + |
| 142 | - local exit_code=$? | 145 | + # Try full clone first, then shallow on final attempt |
| 143 | - if [[ -d "$repo_path/.git" ]]; then | 146 | + local clone_args="--progress" |
| 144 | - log_success "$repo (cloned)" | 147 | + if [[ $attempt -eq $max_retries ]]; then |
| 145 | - ((total_cloned++)) || true | 148 | + clone_args="--progress --depth 1" |
| 146 | - elif [[ $exit_code -eq 124 ]]; then | 149 | + log_info "(trying shallow clone...)" |
| 147 | - log_error "$repo (timeout after ${CLONE_TIMEOUT}s)" | 150 | + fi |
| 148 | - failed_repos+=("${github_org}/${repo}") | 151 | + |
| 149 | - ((total_failed++)) || true | 152 | + if timeout "$CLONE_TIMEOUT" git clone $clone_args "$ssh_url" "$repo_path" 2>&1; then |
| | 153 | + if [[ -d "$repo_path/.git" ]]; then |
| | 154 | + if [[ $attempt -eq $max_retries ]]; then |
| | 155 | + log_success "$repo (cloned shallow)" |
| | 156 | + else |
| | 157 | + log_success "$repo (cloned)" |
| | 158 | + fi |
| | 159 | + ((total_cloned++)) || true |
| | 160 | + clone_success=true |
| | 161 | + fi |
| 150 | else | 162 | else |
| 151 | - log_error "$repo (clone failed)" | 163 | + local exit_code=$? |
| 152 | - failed_repos+=("${github_org}/${repo}") | 164 | + if [[ -d "$repo_path/.git" ]]; then |
| 153 | - ((total_failed++)) || true | 165 | + log_success "$repo (cloned)" |
| | 166 | + ((total_cloned++)) || true |
| | 167 | + clone_success=true |
| | 168 | + elif [[ $exit_code -eq 124 ]]; then |
| | 169 | + log_warn "$repo (attempt $attempt timed out)" |
| | 170 | + else |
| | 171 | + log_warn "$repo (attempt $attempt failed)" |
| | 172 | + fi |
| 154 | fi | 173 | fi |
| | 174 | + |
| | 175 | + ((attempt++)) || true |
| | 176 | + done |
| | 177 | + |
| | 178 | + if [[ "$clone_success" == "false" ]]; then |
| | 179 | + log_error "$repo (clone failed after $max_retries attempts)" |
| | 180 | + failed_repos+=("${github_org}/${repo}") |
| | 181 | + ((total_failed++)) || true |
| 155 | fi | 182 | fi |
| 156 | } | 183 | } |
| 157 | | 184 | |