Repository navigation
Expand file tree
/
Copy pathupdate-subtrees.sh
More file actions
executable file
·105 lines (88 loc) · 2.38 KB
/
Copy pathupdate-subtrees.sh
File metadata and controls
executable file
·105 lines (88 loc) · 2.38 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
#!/bin/bash
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
echo "🔄 Updating git subtrees..."
# Check if .gitmodules exists
if [ ! -f .gitmodules ]; then
echo -e "${RED}Error: .gitmodules file not found${NC}"
exit 1
fi
# Parse .gitmodules and extract submodule information
# This awk script extracts path, url, and branch for each submodule
submodules=$(awk '
/^\[submodule/ {
if (path != "") {
print path "|" url "|" branch
}
path = ""
url = ""
branch = ""
}
/path = / { path = $3 }
/url = / { url = $3 }
/branch = / { branch = $3 }
END {
if (path != "") {
print path "|" url "|" branch
}
}
' .gitmodules)
# Check if we found any submodules
if [ -z "$submodules" ]; then
echo -e "${YELLOW}No submodules found in .gitmodules${NC}"
exit 0
fi
# Counter for statistics
total=0
updated=0
failed=0
# Process each submodule
while IFS='|' read -r path url branch; do
# Skip if not in resources directory
if [[ ! "$path" =~ ^resources/ ]]; then
continue
fi
total=$((total + 1))
echo ""
echo -e "${YELLOW}Processing: $path${NC}"
# Check if the directory exists
if [ ! -d "$path" ]; then
echo -e "${RED} ✗ Directory not found, skipping${NC}"
failed=$((failed + 1))
continue
fi
# Use branch from .gitmodules
if [ -z "$branch" ]; then
echo -e "${RED} ✗ No branch specified in .gitmodules${NC}"
failed=$((failed + 1))
continue
fi
echo -e " Branch: ${GREEN}$branch${NC}"
# Pull the latest changes
echo " Pulling latest changes..."
if git -C "$path" pull origin "$branch" --ff-only; then
echo -e "${GREEN} ✓ Successfully updated${NC}"
updated=$((updated + 1))
else
echo -e "${RED} ✗ Failed to pull (you may have local changes)${NC}"
failed=$((failed + 1))
fi
done <<< "$submodules"
# Print summary
echo ""
echo "================================"
echo "Summary:"
echo " Total processed: $total"
echo -e " ${GREEN}Successfully updated: $updated${NC}"
if [ $failed -gt 0 ]; then
echo -e " ${RED}Failed: $failed${NC}"
fi
echo "================================"
# Exit with error if any updates failed
if [ $failed -gt 0 ]; then
exit 1
fi