-
Notifications
You must be signed in to change notification settings - Fork 5
/
update-repos
executable file
·106 lines (83 loc) · 3.16 KB
/
update-repos
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/bin/bash
# Synchronizes all the branches from the CoreOS upstream to the flatcar-linux
# organization clones.
set -euo pipefail
. ./lib/common.sh
# update-branches gets all the upstream branches, checks them out and pushes to
# the origin.
#
# It assumes upstream and origin remotes are created and up to date.
function update-branches() {
local UPSTREAM="${1}"
local ORIGIN="${2}"
local PUSH_TAGS="${3}"
local UPSTREAM_BRANCHES
# Exclude branches that contain "flatcar", "edge", or "main" and would overwrite our branches
# TODO: This should be configured per repo or we retire this script and rely on manual work
UPSTREAM_BRANCHES=$(git branch -r | grep "^[ ]*$UPSTREAM" | grep -v HEAD | cut -d/ -f 2- | grep -v flatcar | grep -v main | grep -v edge)
for branch in ${UPSTREAM_BRANCHES}; do
git checkout -B "${branch}" "${UPSTREAM}/${branch}"
done
# use the --force, Luke!
git push --all --force "${ORIGIN}"
# push tags only if PUSH_TAGS is true
if [[ ${PUSH_TAGS} == "1" ]] ; then
git push --tags "${ORIGIN}"
fi
}
# Merge each upstream systemd branch to Flatcar branch, e.g. v241-coreos to v241-flatcar.
# We need to deal with the special case, because of the special case of systemd repo,
# which has no base point like "flatcar-master" branch. So if upstream has updated
# the v241-coreos branch, that change needs to be also applied to v241-flatcar.
function update-systemd-branches() {
local UPSTREAM="${1}"
local FLATCAR_BRANCH="${2}"
local ORIGIN="origin"
local UPSTREAM_BRANCHES
UPSTREAM_BRANCHES=$(git branch -r | grep "^[ ]*$UPSTREAM/v2[4-9][1-9]" | grep -v HEAD | cut -d/ -f 2-)
for upstream_branch in ${UPSTREAM_BRANCHES}; do
local flatcar_branch
flatcar_branch="${upstream_branch//-${UPSTREAM}/-${FLATCAR_BRANCH}}"
if [[ -n "$(git ls-remote ${ORIGIN} ${flatcar_branch} 2>/dev/null)" ]]; then
git checkout -B "${flatcar_branch}" "${ORIGIN}/${flatcar_branch}"
git merge "${UPSTREAM}/${upstream_branch}"
git push "${ORIGIN}" "${flatcar_branch}"
fi
done
}
PREFIX=""
if [ $# -eq 1 ]; then
PREFIXTMP="$1"
if [ -d "${PWD}/${PREFIXTMP}" ]; then
PREFIX="${PREFIXTMP}"
echo "Using existing directory $PREFIX"
# we're not cleaning up this one since it's user provided
fi
fi
if [ -z "${PREFIX}" ]; then
PREFIX=$(mktemp -d "${PWD}/.update-repos.XXXXXXXXXX")
echo "Created new directory $PREFIX"
# clean up
trap '{ export EXT="$?"; rm -rf "${PREFIX}" && exit "${EXT}"; }' EXIT
fi
cd "${PREFIX}"
for repo in "${FLATCAR_REPOS[@]}"; do
# Systemd is handled below
if [ "${repo}" = "systemd" ]; then
continue
fi
[ ! -d "${repo}" ] && git clone "git@github.com:flatcar-linux/${repo}"
pushd "${repo}"
git remote add upstream "https://github.com/coreos/${repo}" || true
git fetch --all
update-branches upstream origin 1
popd
done
# The systemd stable repo is our upstream, not coreos/systemd
repo_systemd="systemd"
[ ! -d "${repo_systemd}" ] && git clone "git@github.com:flatcar-linux/${repo_systemd}"
pushd "${repo_systemd}"
git remote add upstream "https://github.com/systemd/systemd-stable" || true
git fetch --all
update-branches upstream origin 1
popd