-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate-submodules
More file actions
executable file
Β·174 lines (145 loc) Β· 4.61 KB
/
update-submodules
File metadata and controls
executable file
Β·174 lines (145 loc) Β· 4.61 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#!/usr/bin/env bash
# update-submodules
#
# Convenience script for contributors to update all submodules to their latest HEAD
# and commit the gitlink updates to the superrepo.
#
# Usage:
# ./update-submodules [--dry-run] [--help]
#
# This script:
# 1. Updates all submodules to their latest remote HEAD
# 2. Shows which submodules were updated
# 3. Commits the gitlink changes with a descriptive message
# 4. Provides guidance on next steps
set -euo pipefail
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Parse arguments
DRY_RUN=false
HELP=false
for arg in "$@"; do
case $arg in
--dry-run)
DRY_RUN=true
shift
;;
--help|-h)
HELP=true
shift
;;
*)
echo "Unknown argument: $arg"
HELP=true
;;
esac
done
if [[ "$HELP" == true ]]; then
echo "Usage: $0 [--dry-run] [--help]"
echo ""
echo "Update all submodules to their latest HEAD and commit gitlink changes."
echo ""
echo "Options:"
echo " --dry-run Show what would be done without making changes"
echo " --help, -h Show this help message"
echo ""
echo "This script helps contributors keep submodules up to date by:"
echo " 1. Updating all submodules to their remote HEAD"
echo " 2. Committing the gitlink updates"
echo " 3. Providing clear status and next steps"
exit 0
fi
echo -e "${BLUE}π Submodule Update Tool${NC}"
echo "=============================="
# Check if we're in a git repository
if ! git rev-parse --git-dir > /dev/null 2>&1; then
echo -e "${RED}β Error: Not in a git repository${NC}"
exit 1
fi
# Check if there are any submodules
if ! git submodule status > /dev/null 2>&1 || [ -z "$(git submodule status)" ]; then
echo -e "${YELLOW}β οΈ No submodules found in this repository${NC}"
exit 0
fi
echo -e "${BLUE}π Current submodule status:${NC}"
git submodule status
echo ""
echo -e "${BLUE}π Checking for updates...${NC}"
# Store initial submodule SHAs
declare -A initial_shas
while IFS= read -r line; do
# Parse submodule status: " SHA path (tag/branch)" or "-SHA path" or "+SHA path"
sha=$(echo "$line" | sed 's/^[-+ ]//' | awk '{print $1}')
path=$(echo "$line" | awk '{print $2}')
initial_shas["$path"]="$sha"
done < <(git submodule status)
if [[ "$DRY_RUN" == true ]]; then
echo -e "${YELLOW}π DRY RUN MODE - No changes will be made${NC}"
echo ""
fi
# Update submodules
echo -e "${BLUE}β¬οΈ Fetching latest changes for all submodules...${NC}"
if [[ "$DRY_RUN" == false ]]; then
git submodule update --remote --merge
else
echo "Would run: git submodule update --remote --merge"
fi
echo ""
echo -e "${BLUE}π Checking for changes...${NC}"
# Check which submodules were updated
updated_modules=()
while IFS= read -r line; do
sha=$(echo "$line" | sed 's/^[-+ ]//' | awk '{print $1}')
path=$(echo "$line" | awk '{print $2}')
if [[ "${initial_shas[$path]}" != "$sha" ]]; then
updated_modules+=("$path")
echo -e "${GREEN}β
Updated: $path${NC}"
echo " ${initial_shas[$path]} β $sha"
fi
done < <(git submodule status)
if [[ ${#updated_modules[@]} -eq 0 ]]; then
echo -e "${GREEN}β
All submodules are already up to date${NC}"
exit 0
fi
echo ""
echo -e "${BLUE}π Summary: ${#updated_modules[@]} submodule(s) updated${NC}"
# Check git status
if [[ "$DRY_RUN" == false ]]; then
if git diff --quiet && git diff --cached --quiet; then
echo -e "${YELLOW}β οΈ No gitlink changes detected (this is unusual)${NC}"
exit 0
fi
fi
# Commit the changes
commit_message="feat: update submodules to latest HEAD
Updated submodules:"
for module in "${updated_modules[@]}"; do
commit_message+="
- $module: ${initial_shas[$module]} β $(git submodule status "$module" | sed 's/^[-+ ]//' | awk '{print $1}')"
done
commit_message+="
π€ Generated with Claude Code
Co-Authored-By: Claude <noreply@anthropic.com>"
echo ""
echo -e "${BLUE}πΎ Committing gitlink updates...${NC}"
if [[ "$DRY_RUN" == false ]]; then
git add .
git commit -m "$commit_message"
echo -e "${GREEN}β
Committed gitlink updates${NC}"
else
echo "Would commit with message:"
echo "$commit_message"
fi
echo ""
echo -e "${BLUE}π Next steps:${NC}"
echo "1. Review the commit with: git show"
echo "2. Push changes with: git push"
echo "3. Or check the log with: git log --oneline -5"
if [[ "$DRY_RUN" == true ]]; then
echo ""
echo -e "${YELLOW}π This was a dry run. Re-run without --dry-run to apply changes.${NC}"
fi