X-Git-Url: https://gerrit.nordix.org/gitweb?a=blobdiff_plain;f=jjb%2Fglobal%2Frebase-jobs.sh;h=657ed112dd9500d6c7aed26ef8793a4577bf9c68;hb=d643ea7acf4cd3e57ba89f092d39e0874b8b111c;hp=b2f77378b504355daa6cb975ba82b3e7e87c1b6d;hpb=8b5d3956fb57e41a51a3431e6e65663006400910;p=infra%2Fcicd.git diff --git a/jjb/global/rebase-jobs.sh b/jjb/global/rebase-jobs.sh old mode 100755 new mode 100644 index b2f77378..657ed112 --- a/jjb/global/rebase-jobs.sh +++ b/jjb/global/rebase-jobs.sh @@ -4,17 +4,39 @@ set -o nounset set -o pipefail cd $WORKSPACE -echo "Checking out $BRANCH" -git checkout $BRANCH -q -git pull -q -echo "Commit is" -echo "-------------------------------------------" -git show -s -echo "-------------------------------------------" -echo "Adding new remote $NORDIX_REMOTE for sync" +# Make sure the Nordix is set from Jenkins Job configuration +# parameter: NORDIX_REMOTE and not from previous job execution +if git remote | grep nordix > /dev/null ; then + git remote rm nordix +fi +# When the GERRIT_BRANCH is not set the rebase job wasn't triggered by merge +# but it's executed as part of timer. In this case we will make sure that all +# branches from remote are synced with Nordix Gerrit. +if [[ -z "${GERRIT_BRANCH:-}" ]] ; then + echo "-- Fetch all ${PROJECT} branches from Gerrit upstream --" + REMOTE_BRANCHES=$(git branch -r | grep -v 'HEAD -> ' | awk '/origin/ {gsub("origin/","");print}') + for branch in ${REMOTE_BRANCHES} ; do + git branch -f --track ${branch} origin/${branch} + done +# The job was triggered by merge on upstream Gerrit. We will make sure that branch set +# in GERRIT_BRANCH is in sync with Nordix Gerrit. +else + echo "-- Fetch branch: ${GERRIT_BRANCH} for project: ${PROJECT} --" + REMOTE_BRANCHES=${GERRIT_BRANCH} + git branch -f --track ${GERRIT_BRANCH} origin/${GERRIT_BRANCH} +fi +git fetch origin --tags -v +echo "-- Adding new remote $NORDIX_REMOTE for sync --" git remote add nordix $NORDIX_REMOTE -echo "-------------------------------------------" git remote -v -echo "-------------------------------------------" -echo "Pushing changes to Nordix branch $BRANCH" -git push nordix $BRANCH +echo "-- Merging changes from Gerrit upstream remote branches to local branch: --" +for branch in ${REMOTE_BRANCHES} ; do + echo "--- Branch name: ${branch}" + git checkout ${branch} -q -f + git merge origin/${branch} --ff-only --stat + echo "------ Pushing changes from branch: ${branch} to Nordix Gerrit" + git push nordix -v + echo "------ Pushing new tags from branch: ${branch} to Nordix Gerrit" + git push nordix --tags -f -v +done +echo "--------------------------------------------------------------------"