-
Notifications
You must be signed in to change notification settings - Fork 5
/
mirror-repos-branch
executable file
·75 lines (56 loc) · 1.85 KB
/
mirror-repos-branch
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
#!/bin/bash
# Mirroring a specific branch from the flatcar remote repos.
# Run it like:
#
# ./mirror-repos-branch build-2010.0.1 flatcar-build-2010.0.1
#
# source = build-2010.0.1, destination = flatcar-build-2010.0.1
set -euo pipefail
ALL_REPOS=${ALL_REPOS:-0}
FORCE_MODE=${FORCE_MODE:-0}
if [ -z "$1" ] || [ "$1" == "-h" ] || [ "$1" == "--help" ] ; then
echo "Usage:"
echo " $0 src-build-x.y.z dst-build-x.y.z"
echo ""
exit 1
fi
SRC_BUILD_BRANCH=$1
DST_BUILD_BRANCH=$2
PUSH_OPTIONS=""
if [ "${FORCE_MODE}" = "1" ]; then
PUSH_OPTIONS+=" --force"
fi
. ./lib/common.sh
if [ "${ALL_REPOS}" = "0" ]; then
FLATCAR_REPOS=("coreos-overlay" "portage-stable" "scripts")
fi
REPOS_DIR=$(mktemp -d "${PWD}/.mirror-repos.XXXXXXXXXX")
echo "Created new directory $REPOS_DIR"
# clean up
trap '{ export EXT="$?"; rm -rf "${REPOS_DIR}" && exit "${EXT}"; }' EXIT
cd "${REPOS_DIR}"
# Check if we are in the monorepo case
[ ! -d scripts ] && git clone --recurse-submodules "git@github.com:flatcar/scripts"
if [ "$(git -C scripts show "origin/${SRC_BUILD_BRANCH}":.gitmodules 2>/dev/null)" = "" ]; then
FLATCAR_REPOS=("scripts")
fi
for repo in "${FLATCAR_REPOS[@]}"; do
# Note: systemd repo has neither flatcar-build-* branches nor flatcar-master
# branch. So we should skip systemd completely.
if [ "${repo}" = "systemd" ]; then
continue
fi
HEAD_URL="git@github.com:flatcar/${repo}"
[ ! -d "${repo}" ] && git clone --recurse-submodules "${HEAD_URL}"
pushd "${repo}"
src_branch=""
if [ -n "$(git ls-remote --heads "${HEAD_URL}" "${SRC_BUILD_BRANCH}")" ]; then
src_branch=${SRC_BUILD_BRANCH}
else
src_branch="flatcar-master"
fi
echo "Mirroring a branch ${src_branch} to ${DST_BUILD_BRANCH}"
git checkout --recurse-submodules --force -B "${DST_BUILD_BRANCH}" "origin/${src_branch}"
git push ${PUSH_OPTIONS} origin "${DST_BUILD_BRANCH}"
popd
done