#!/usr/bin/env bash set -euo pipefail script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" root="$(cd "$script_dir/.." && pwd)" cd "$root" origin="$(git remote get-url origin)" origin="${origin%/}" remote_root="${origin%/*}" remote_root="${remote_root%/*}" echo "remoteRoot $remote_root" fetch_repo() { local repo="$1" local branch="$2" local dir="$3" if [[ -d "$dir" ]]; then git -C "$dir" rev-parse --is-inside-work-tree >/dev/null git -C "$dir" remote set-url origin "$repo" git -C "$dir" fetch origin "$branch" git -C "$dir" checkout "$branch" git -C "$dir" pull --ff-only origin "$branch" else mkdir -p "$(dirname "$dir")" git clone --branch "$branch" --single-branch "$repo" "$dir" fi } fetch_repo "$remote_root/ae/build_infra" "master" "third_party/build_infra" fetch_repo "$remote_root/ae/CPP_Core" "master" "third_party/CPP_Core"