45 lines
1.2 KiB
Bash
45 lines
1.2 KiB
Bash
|
|
#!/usr/bin/env bash
|
||
|
|
|
||
|
|
set -euo pipefail
|
||
|
|
|
||
|
|
TARGET_BRANCH="${TARGET_BRANCH:-develop}"
|
||
|
|
|
||
|
|
if [[ "$#" -gt 0 ]]; then
|
||
|
|
TARGET_REPOS=("$@")
|
||
|
|
else
|
||
|
|
TARGET_REPOS=("Ai" "Backend" "SensorHub")
|
||
|
|
fi
|
||
|
|
|
||
|
|
pull_schemas_submodule() {
|
||
|
|
local repo_dir="$1"
|
||
|
|
local submodule_path="Schemas"
|
||
|
|
local submodule_dir="${repo_dir}/${submodule_path}"
|
||
|
|
|
||
|
|
if ! git -C "$repo_dir" rev-parse --is-inside-work-tree >/dev/null 2>&1; then
|
||
|
|
echo "Skipping ${repo_dir}: not a git repository."
|
||
|
|
return 0
|
||
|
|
fi
|
||
|
|
|
||
|
|
if ! git -C "$submodule_dir" rev-parse --is-inside-work-tree >/dev/null 2>&1; then
|
||
|
|
echo "Skipping ${repo_dir}: ${submodule_path} submodule is not initialized."
|
||
|
|
return 0
|
||
|
|
fi
|
||
|
|
|
||
|
|
echo "Updating ${submodule_path} in ${repo_dir} on branch ${TARGET_BRANCH}"
|
||
|
|
git -C "$submodule_dir" fetch origin "$TARGET_BRANCH"
|
||
|
|
|
||
|
|
if git -C "$submodule_dir" show-ref --verify --quiet "refs/heads/${TARGET_BRANCH}"; then
|
||
|
|
git -C "$submodule_dir" checkout "$TARGET_BRANCH"
|
||
|
|
else
|
||
|
|
git -C "$submodule_dir" checkout -b "$TARGET_BRANCH" "origin/${TARGET_BRANCH}"
|
||
|
|
fi
|
||
|
|
|
||
|
|
git -C "$submodule_dir" pull --ff-only origin "$TARGET_BRANCH"
|
||
|
|
}
|
||
|
|
|
||
|
|
for repo_dir in "${TARGET_REPOS[@]}"; do
|
||
|
|
pull_schemas_submodule "$repo_dir"
|
||
|
|
done
|
||
|
|
|
||
|
|
echo "Done."
|