forked from flink-ci/git-repo-sync
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sync_repo.sh
executable file
·42 lines (30 loc) · 1.02 KB
/
sync_repo.sh
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
#!/usr/bin/env bash
# Configuration
[email protected]:apache/hudi.git
[email protected]:apachehudi-ci/hudi-mirror.git
TARGET_BRANCHES="master"
echo "Syncing branches"
# update last sync file
date > .last-sync
if [ ! -d ".repo" ]; then
echo "SOURCE_REPO ($SOURCE_REPO) does not exist. Cloning ..."
git clone --mirror $SOURCE_REPO .repo
else
# update list of current branches
git fetch origin 'refs/heads/release-*:refs/release-*'
fi
cd .repo
# echo "Fetching from SOURCE_REPO ($SOURCE_REPO)"
# git fetch origin master
for RELEASE_BRANCH in `git branch -a | grep "release-" | sort -V -r | head -n 4` ; do
TARGET_BRANCHES+=" $RELEASE_BRANCH"
done
echo "Fetching branches '$TARGET_BRANCHES' from SOURCE_REPO ($SOURCE_REPO)"
git fetch origin $TARGET_BRANCHES
echo "Pushing branches '$TARGET_BRANCHES' to TARGET_REPO ($TARGET_REPO)"
# generating refspec
REFSPEC=""
for TARGET_BRANCH in $TARGET_BRANCHES ; do
REFSPEC+="refs/heads/$TARGET_BRANCH:refs/heads/$TARGET_BRANCH "
done
git push -f $TARGET_REPO $REFSPEC