@@ -126,32 +126,59 @@ sync_repo() { |
| 126 | 126 | fi |
| 127 | 127 | fi |
| 128 | 128 | |
| 129 | | - # Case 3: Clone new repo |
| 129 | + # Case 3: Clone new repo with retry logic |
| 130 | 130 | local ssh_url="git@github.com:${github_org}/${repo}.git" |
| 131 | | - log_info "Cloning $repo (SSH)..." |
| 132 | | - if timeout "$CLONE_TIMEOUT" git clone --progress "$ssh_url" "$repo_path" 2>&1; then |
| 133 | | - if [[ -d "$repo_path/.git" ]]; then |
| 134 | | - log_success "$repo (cloned)" |
| 135 | | - ((total_cloned++)) || true |
| 131 | + local max_retries=3 |
| 132 | + local attempt=1 |
| 133 | + local clone_success=false |
| 134 | + |
| 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 | 141 | else |
| 137 | | - log_error "$repo (clone failed - no permission?)" |
| 138 | | - failed_repos+=("${github_org}/${repo}") |
| 139 | | - ((total_failed++)) || true |
| 142 | + log_info "Cloning $repo (retry $attempt/$max_retries)..." |
| 140 | 143 | fi |
| 141 | | - else |
| 142 | | - local exit_code=$? |
| 143 | | - if [[ -d "$repo_path/.git" ]]; then |
| 144 | | - log_success "$repo (cloned)" |
| 145 | | - ((total_cloned++)) || true |
| 146 | | - elif [[ $exit_code -eq 124 ]]; then |
| 147 | | - log_error "$repo (timeout after ${CLONE_TIMEOUT}s)" |
| 148 | | - failed_repos+=("${github_org}/${repo}") |
| 149 | | - ((total_failed++)) || true |
| 144 | + |
| 145 | + # Try full clone first, then shallow on final attempt |
| 146 | + local clone_args="--progress" |
| 147 | + if [[ $attempt -eq $max_retries ]]; then |
| 148 | + clone_args="--progress --depth 1" |
| 149 | + log_info "(trying shallow clone...)" |
| 150 | + fi |
| 151 | + |
| 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 | 162 | else |
| 151 | | - log_error "$repo (clone failed)" |
| 152 | | - failed_repos+=("${github_org}/${repo}") |
| 153 | | - ((total_failed++)) || true |
| 163 | + local exit_code=$? |
| 164 | + if [[ -d "$repo_path/.git" ]]; then |
| 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 | 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 | 182 | fi |
| 156 | 183 | } |
| 157 | 184 | |