@@ -50,6 +50,27 @@ check_requirements() { |
| 50 | 50 | fi |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | +sync_submodules() { |
| 54 | + local repo_path="$1" |
| 55 | + local repo="$2" |
| 56 | + |
| 57 | + [[ -f "$repo_path/.gitmodules" ]] || return 0 |
| 58 | + |
| 59 | + ( |
| 60 | + cd "$repo_path" 2>/dev/null || exit 0 |
| 61 | + # Prefix `-` = uninitialized, `+` = checked-out commit differs from index. |
| 62 | + # Either means `submodule update --init --recursive` has work to do. |
| 63 | + if git submodule status --recursive 2>/dev/null | grep -qE '^[-+]'; then |
| 64 | + log_info " $repo: syncing submodules..." |
| 65 | + if timeout "$CLONE_TIMEOUT" git submodule update --init --recursive 2>&1 >/dev/null; then |
| 66 | + log_success " $repo: submodules initialized" |
| 67 | + else |
| 68 | + log_warn " $repo: submodule update failed" |
| 69 | + fi |
| 70 | + fi |
| 71 | + ) |
| 72 | +} |
| 73 | + |
| 53 | 74 | sync_repo() { |
| 54 | 75 | local github_org="$1" |
| 55 | 76 | local repo="$2" |
@@ -98,10 +119,12 @@ sync_repo() { |
| 98 | 119 | ;; |
| 99 | 120 | uptodate) |
| 100 | 121 | log_success "$repo (up to date)" |
| 122 | + sync_submodules "$repo_path" "$repo" |
| 101 | 123 | ;; |
| 102 | 124 | updated) |
| 103 | 125 | log_success "$repo (updated)" |
| 104 | 126 | ((total_updated++)) || true |
| 127 | + sync_submodules "$repo_path" "$repo" |
| 105 | 128 | ;; |
| 106 | 129 | diverged) |
| 107 | 130 | log_warn "$repo (can't fast-forward, skipping)" |
@@ -158,6 +181,7 @@ sync_repo() { |
| 158 | 181 | fi |
| 159 | 182 | ((total_cloned++)) || true |
| 160 | 183 | clone_success=true |
| 184 | + sync_submodules "$repo_path" "$repo" |
| 161 | 185 | fi |
| 162 | 186 | else |
| 163 | 187 | local exit_code=$? |
@@ -165,6 +189,7 @@ sync_repo() { |
| 165 | 189 | log_success "$repo (cloned)" |
| 166 | 190 | ((total_cloned++)) || true |
| 167 | 191 | clone_success=true |
| 192 | + sync_submodules "$repo_path" "$repo" |
| 168 | 193 | elif [[ $exit_code -eq 124 ]]; then |
| 169 | 194 | log_warn "$repo (attempt $attempt timed out)" |
| 170 | 195 | else |