Fatih Degirmenci | a2beeb2 | 2018-12-10 10:57:50 -0800 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | set -o errexit |
| 3 | set -o nounset |
| 4 | set -o pipefail |
| 5 | |
| 6 | cd $WORKSPACE |
robert.tomczyk | 3459cae | 2019-09-25 09:31:57 +0100 | [diff] [blame] | 7 | # Make sure the Nordix is set from Jenkins Job configuration |
| 8 | # parameter: NORDIX_REMOTE and not from previous job execution |
| 9 | if git remote | grep nordix > /dev/null ; then |
| 10 | git remote rm nordix |
| 11 | fi |
| 12 | # 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. |
| 15 | if [[ -z "${GERRIT_BRANCH:-}" ]] ; then |
| 16 | echo "-- Fetch all ${PROJECT} branches from Gerrit upstream --" |
| 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 upstream Gerrit. We will make sure that branch set |
| 22 | # in GERRIT_BRANCH is in sync with Nordix Gerrit. |
| 23 | else |
| 24 | echo "-- Fetch branch: ${GERRIT_BRANCH} for project: ${PROJECT} --" |
| 25 | REMOTE_BRANCHES=${GERRIT_BRANCH} |
| 26 | git branch -f --track ${GERRIT_BRANCH} origin/${GERRIT_BRANCH} |
| 27 | fi |
robert.tomczyk | 2ef892a | 2019-10-18 11:46:03 +0100 | [diff] [blame] | 28 | git fetch origin --tags -v |
robert.tomczyk | 3459cae | 2019-09-25 09:31:57 +0100 | [diff] [blame] | 29 | echo "-- Adding new remote $NORDIX_REMOTE for sync --" |
Fatih Degirmenci | a2beeb2 | 2018-12-10 10:57:50 -0800 | [diff] [blame] | 30 | git remote add nordix $NORDIX_REMOTE |
Fatih Degirmenci | a2beeb2 | 2018-12-10 10:57:50 -0800 | [diff] [blame] | 31 | git remote -v |
robert.tomczyk | 3459cae | 2019-09-25 09:31:57 +0100 | [diff] [blame] | 32 | echo "-- Merging changes from Gerrit upstream remote branches to local branch: --" |
| 33 | for branch in ${REMOTE_BRANCHES} ; do |
robert.tomczyk | 2ef892a | 2019-10-18 11:46:03 +0100 | [diff] [blame] | 34 | echo "--- Branch name: ${branch}" |
robert.tomczyk | 3459cae | 2019-09-25 09:31:57 +0100 | [diff] [blame] | 35 | git checkout ${branch} -q -f |
| 36 | git merge origin/${branch} --ff-only --stat |
robert.tomczyk | 2ef892a | 2019-10-18 11:46:03 +0100 | [diff] [blame] | 37 | echo "------ Pushing changes from branch: ${branch} to Nordix Gerrit" |
| 38 | git push nordix -v |
| 39 | echo "------ Pushing new tags from branch: ${branch} to Nordix Gerrit" |
robert.tomczyk | 2490c7f | 2019-11-11 10:52:38 +0000 | [diff] [blame] | 40 | git push nordix --tags -f -v |
robert.tomczyk | 3459cae | 2019-09-25 09:31:57 +0100 | [diff] [blame] | 41 | done |
robert.tomczyk | 3459cae | 2019-09-25 09:31:57 +0100 | [diff] [blame] | 42 | echo "--------------------------------------------------------------------" |