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