Files

59 lines
1.5 KiB
Bash
Raw Permalink Normal View History

2026-04-27 04:31:32 +03:30
#!/usr/bin/env bash
set -euo pipefail
TARGET_BRANCH="${TARGET_BRANCH:-develop}"
if [[ "$#" -gt 0 ]]; then
TARGET_MODULES=("$@")
else
TARGET_MODULES=("Accsess" "Ai" "Backend" "Schemas" "SensorHub")
fi
checkout_and_pull_branch() {
local repo_dir="$1"
git -C "$repo_dir" fetch origin "$TARGET_BRANCH"
if git -C "$repo_dir" show-ref --verify --quiet "refs/heads/${TARGET_BRANCH}"; then
git -C "$repo_dir" checkout "$TARGET_BRANCH"
else
git -C "$repo_dir" checkout -b "$TARGET_BRANCH" "origin/${TARGET_BRANCH}"
fi
git -C "$repo_dir" pull --ff-only origin "$TARGET_BRANCH"
}
pull_repo() {
local repo_dir="$1"
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
echo "Pulling ${repo_dir} on branch ${TARGET_BRANCH}"
checkout_and_pull_branch "$repo_dir"
if [[ -f "${repo_dir}/.gitmodules" ]]; then
echo "Updating nested submodules in ${repo_dir}"
git -C "$repo_dir" submodule update --init --recursive
git -C "$repo_dir" submodule foreach --recursive "
echo \"Updating \${displaypath} on branch ${TARGET_BRANCH}\"
git fetch origin ${TARGET_BRANCH}
if git show-ref --verify --quiet refs/heads/${TARGET_BRANCH}; then
git checkout ${TARGET_BRANCH}
else
git checkout -b ${TARGET_BRANCH} origin/${TARGET_BRANCH}
fi
git pull --ff-only origin ${TARGET_BRANCH}
"
fi
}
for module_dir in "${TARGET_MODULES[@]}"; do
pull_repo "$module_dir"
done
echo "Done."