blob: b223f90ddd4d0020834dedcb9cba6118a2bd1cb3 [file] [log] [blame]
robert.tomczykf8c734a2019-06-14 17:08:58 +01001#!/bin/bash
2set -o errexit
3set -o nounset
4set -o pipefail
5
6cd $WORKSPACE
7# When the GERRIT_BRANCH is not set the rebase job wasn't triggered by merge
8# but it's executed as part of timer. In this case we will make sure that all
9# branches from remote are synced with Nordix Gerrit.
10if [[ -z "${GERRIT_BRANCH:-}" ]] ; then
11 echo "-- Fetch all branches from OpenDev for project: ${PROJECT} --"
12 REMOTE_BRANCHES=$(git branch -r | grep -v 'HEAD -> ' | awk '/origin/ {gsub("origin/","");print}')
13 for branch in ${REMOTE_BRANCHES} ; do
14 git branch -f --track ${branch} origin/${branch}
15 done
16# The job was triggered by merge on OpenDev. We will make sure that branch set
17# in GERRIT_BRANCH is in sync with Nordix Gerrit.
18else
19 echo "-- Fetch branch: ${GERRIT_BRANCH} from OpenDev for project: ${PROJECT} --"
20 REMOTE_BRANCHES=${GERRIT_BRANCH}
21 git branch -f --track ${GERRIT_BRANCH} origin/${GERRIT_BRANCH}
22fi
23git fetch origin -v
24echo "-- Adding new remote $NORDIX_REMOTE for sync --"
25git remote add nordix $NORDIX_REMOTE
26git remote -v
27echo "-- Merging changes from OpenDev remote branches to local branch: --"
28for branch in ${REMOTE_BRANCHES} ; do
29 echo "------ Branch name: ${branch}"
30 git checkout ${branch} -q
31 git merge origin/${branch} --ff-only --stat
32done
33echo "-- Pushing changes to Nordix Gerrit --"
34git push nordix --all -v
35echo "--------------------------------------------------------------------"
36# Make sure the Nordix is set from Jenkins Job configuration
37# parameter: NORDIX_REMOTE in next job run
38if git remote | grep nordix > /dev/null ; then
39 git remote rm nordix
40fi