#!/usr/bin/env bash set -euo pipefail root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" staging_root="${NEXO_UPSTREAM_ROOT:-"$root/.upstream/mattermost"}" preflight_repo() { local name="$1" local dir="$staging_root/$name" if [ -d "$dir/.git" ]; then if [ -n "$(git -C "$dir" status --porcelain)" ]; then echo "refuse dirty upstream staging clone: $dir" >&2 exit 1 fi elif [ -e "$dir" ]; then echo "refuse non-git upstream staging path: $dir" >&2 exit 1 fi } sync_repo() { local name="$1" local url="$2" local branch="$3" local target="$4" local dir="$staging_root/$name" mkdir -p "$staging_root" if [ -d "$dir/.git" ]; then git -C "$dir" checkout -q "$branch" git -C "$dir" pull --ff-only --depth 1 origin "$branch" else git clone --depth 1 --single-branch --branch "$branch" "$url" "$dir" fi local commit commit="$(git -C "$dir" rev-parse HEAD)" echo "$name" echo " source: $url" echo " branch: $branch" echo " commit: $commit" echo " staging: ${dir#"$root"/}" echo " snapshot target: $target" } preflight_repo "mattermost" preflight_repo "mattermost-mobile" preflight_repo "mattermost-push-proxy" sync_repo "mattermost" "https://github.com/mattermost/mattermost.git" "master" "services/core/" sync_repo "mattermost-mobile" "https://github.com/mattermost/mattermost-mobile.git" "main" "apps/mattermost/" sync_repo "mattermost-push-proxy" "https://github.com/mattermost/mattermost-push-proxy.git" "master" "services/push-proxy/" cat <