Skip to content

Commit 91554a8

Browse files
author
Nils Bars
committed
Check submodule sync on startup and offer to update
When running ./ctrl.sh up, check if any submodules point to different commits than what the repository tracks and prompt the user to update them.
1 parent b61837a commit 91554a8

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

ctrl.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,36 @@ function build {
330330
)
331331
}
332332

333+
function check_submodule_sync {
334+
# Check if submodules match the commits tracked by the main repo
335+
local out_of_sync=()
336+
while IFS= read -r line; do
337+
# git submodule status prefixes with '-' (not init), '+' (wrong commit), or ' ' (ok)
338+
if [[ "$line" == +* ]]; then
339+
# Extract submodule path (second field)
340+
local path
341+
path=$(echo "$line" | awk '{print $2}')
342+
out_of_sync+=("$path")
343+
fi
344+
done < <(git submodule status --recursive)
345+
346+
if [[ ${#out_of_sync[@]} -gt 0 ]]; then
347+
warning "The following submodules do not match the commits tracked by the repository:"
348+
for sm in "${out_of_sync[@]}"; do
349+
warning " - $sm"
350+
done
351+
read -r -p "$(txt bold)$(txt yellow)[?] Update submodules to match? [Y/n] $(txt reset)" answer
352+
if [[ -z "$answer" || "$answer" =~ ^[Yy] ]]; then
353+
info "=> Updating submodules"
354+
git submodule update --init --recursive
355+
else
356+
warning "Continuing with mismatched submodules."
357+
fi
358+
fi
359+
}
360+
333361
function up {
362+
check_submodule_sync
334363
export REAL_HOSTNAME="$(hostname)"
335364
export DEBUG=false
336365
export DISABLE_RESPONSE_CACHING=false

0 commit comments

Comments
 (0)