-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathupdate-submodule-refs.sh
More file actions
executable file
·103 lines (88 loc) · 2.27 KB
/
Copy pathupdate-submodule-refs.sh
File metadata and controls
executable file
·103 lines (88 loc) · 2.27 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
#!/usr/bin/env bash
set -euo pipefail
# Update the mobile submodules (iOS / Android) to specific refs.
# Usage:
# scripts/update-submodule-refs.sh [--ios-ref <ref>] [--android-ref <ref>]
# [--skip-ios] [--skip-android]
#
# When a ref is omitted the default branch defined in .gitmodules (main) is used.
IOS_PATH="apps/react-native/ios"
ANDROID_PATH="apps/react-native/android"
IOS_REF=""
ANDROID_REF=""
UPDATE_IOS=true
UPDATE_ANDROID=true
while [[ $# -gt 0 ]]; do
case "$1" in
--ios-ref)
IOS_REF="${2:-}"
if [[ -z "$IOS_REF" ]]; then
echo "Error: --ios-ref requires a value" >&2
exit 1
fi
shift 2
;;
--android-ref)
ANDROID_REF="${2:-}"
if [[ -z "$ANDROID_REF" ]]; then
echo "Error: --android-ref requires a value" >&2
exit 1
fi
shift 2
;;
--skip-ios)
UPDATE_IOS=false
shift
;;
--skip-android)
UPDATE_ANDROID=false
shift
;;
-h|--help)
sed -n '1,120p' "$0"
exit 0
;;
*)
echo "Unknown argument: $1" >&2
exit 1
;;
esac
done
update_submodule() {
local path=$1
local label=$2
local ref=$3
if [[ ! -d "$path" ]]; then
echo "Initializing submodule for $label ($path)"
git submodule update --init "$path"
fi
if [[ -z "$ref" || "$ref" == "default" ]]; then
# Use ref configured in .gitmodules (dev)
ref=$(git config -f .gitmodules "submodule.${label}.branch" || echo "main")
fi
echo "::group::Updating $label ($path) to $ref"
git submodule sync -- "$path"
git submodule update --init "$path"
local old_sha
old_sha=$(git ls-tree HEAD "$path" | awk '{print $3}')
(
cd "$path"
git fetch origin "$ref"
git checkout --detach FETCH_HEAD
)
git add "$path"
local staged_sha
staged_sha=$(git ls-files --stage "$path" | awk 'NR==1 {print $2}')
if [[ "$staged_sha" == "$old_sha" ]]; then
echo "No change for $label; already at $staged_sha"
else
echo "Updated $label from ${old_sha:-<none>} to $staged_sha"
fi
echo "::endgroup::"
}
if $UPDATE_IOS; then
update_submodule "$IOS_PATH" "apps/react-native/ios" "$IOS_REF"
fi
if $UPDATE_ANDROID; then
update_submodule "$ANDROID_PATH" "apps/react-native/android" "$ANDROID_REF"
fi