tenseleyflow/ndotfiles / 1862308

Browse files

properly set up submodules

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
1862308e3602a72474343dc966bd224c6ee286b9
Parents
4101820
Tree
6b0ef4e

1 changed file

StatusFile+-
M Script/sync-repos 25 0
Script/sync-reposmodified
@@ -50,6 +50,27 @@ check_requirements() {
5050
     fi
5151
 }
5252
 
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
+
5374
 sync_repo() {
5475
     local github_org="$1"
5576
     local repo="$2"
@@ -98,10 +119,12 @@ sync_repo() {
98119
                 ;;
99120
             uptodate)
100121
                 log_success "$repo (up to date)"
122
+                sync_submodules "$repo_path" "$repo"
101123
                 ;;
102124
             updated)
103125
                 log_success "$repo (updated)"
104126
                 ((total_updated++)) || true
127
+                sync_submodules "$repo_path" "$repo"
105128
                 ;;
106129
             diverged)
107130
                 log_warn "$repo (can't fast-forward, skipping)"
@@ -158,6 +181,7 @@ sync_repo() {
158181
                 fi
159182
                 ((total_cloned++)) || true
160183
                 clone_success=true
184
+                sync_submodules "$repo_path" "$repo"
161185
             fi
162186
         else
163187
             local exit_code=$?
@@ -165,6 +189,7 @@ sync_repo() {
165189
                 log_success "$repo (cloned)"
166190
                 ((total_cloned++)) || true
167191
                 clone_success=true
192
+                sync_submodules "$repo_path" "$repo"
168193
             elif [[ $exit_code -eq 124 ]]; then
169194
                 log_warn "$repo (attempt $attempt timed out)"
170195
             else