-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit-commit-updated-submodules
More file actions
44 lines (34 loc) · 1.25 KB
/
Copy pathgit-commit-updated-submodules
File metadata and controls
44 lines (34 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env bash
set -euo pipefail
# Run from the superproject root.
cd "$(git rev-parse --show-toplevel)"
# Collect submodule paths from .gitmodules
mapfile -t submodules < <(git config --file .gitmodules --get-regexp path | awk '{print $2}')
if [ "${#submodules[@]}" -eq 0 ]; then
echo "No submodules found."
exit 0
fi
updated_any=false
for sub in "${submodules[@]}"; do
# Skip if submodule is not initialized
if [ ! -d "$sub" ]; then
echo "Skipping uninitialized submodule: $sub"
continue
fi
# Commit recorded in superproject HEAD (gitlink)
recorded_hash="$(git rev-parse "HEAD:$sub" 2>/dev/null || true)"
# Current commit checked out in submodule
current_hash="$(git -C "$sub" rev-parse HEAD 2>/dev/null || true)"
# If current hash differs, submodule pointer needs update in superproject
if [ -n "$current_hash" ] && [ "$recorded_hash" != "$current_hash" ]; then
short_hash="$(git -C "$sub" rev-parse --short HEAD)"
submodule_name="$(basename "$sub")"
git add "$sub"
git commit -m "Updated ${submodule_name} to ${short_hash}."
echo "Committed submodule update: ${submodule_name} -> ${short_hash}"
updated_any=true
fi
done
if [ "$updated_any" = false ]; then
echo "No updated submodules detected."
fi