File tree Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change
1
+ #! /usr/bin/env bash
2
+
3
+ fail () {
4
+ printf ' %s\n' " $1 " >&2
5
+ exit " ${2-1} "
6
+ }
7
+
8
+ # make sure we're in the root directory of the repository
9
+ if [ ! -f " Cargo.toml" ]; then
10
+ fail " Failed to find \" Cargo.toml\" , are you sure you're in the root directory of the repository?"
11
+ fi
12
+
13
+ cwd=$( pwd)
14
+
15
+ # update all submodules
16
+ git submodule update --init --recursive
17
+
18
+ # array of submodule paths and their corresponding branch names
19
+ submodules=()
20
+
21
+ # get the path and the branch name from the .gitmodules file
22
+ while IFS=$' \n ' read -r line; do
23
+ if [[ " $line " =~ ^.* path\ = .* $ ]]; then
24
+ path=${line#* = }
25
+ elif [[ " $line " =~ ^.* branch\ = .* $ ]]; then
26
+ branch=${line#* = }
27
+ submodules+=(" $path :$branch " )
28
+ fi
29
+ done < .gitmodules
30
+
31
+ # iterate over the array and update each submodule
32
+ for i in " ${submodules[@]} " ; do
33
+ name=${i%%:* }
34
+ branch=${i#*: }
35
+ echo " Updating $name to $branch "
36
+ # change directory to the submodule
37
+ cd " $name " || fail " Failed to change directory into submodule \" $name \" "
38
+ # fetch the latest changes from the remote
39
+ git fetch || fail " Failed to fetch latest changes for submodule \" $name \" "
40
+ # checkout the specified branch
41
+ git checkout " $branch " || fail " Failed to checkout branch \" $branch \" for submodule \" $name \" "
42
+ # pull the latest changes from the remote
43
+ git pull || fail " Failed to pull latest changes for submodule \" $name \" "
44
+ # change directory back to the root of the repository
45
+ cd " $cwd " || fail " Failed to change directory back to root of repository"
46
+ done
You can’t perform that action at this time.
0 commit comments