blob: a0b1349b5a5e6f86af0746f0cc01026be48aa44f [file] [log] [blame]
Michael Stille8cadae2014-01-06 19:47:27 +11001#!/bin/bash -e
2
Joshua Hesketh1c8d2df2014-05-05 15:48:31 +10003# Stolen from http://git.openstack.org/cgit/openstack-infra/config/plain/modules/jenkins/files/slave_scripts/gerrit-git-prep.sh
Michael Stille8cadae2014-01-06 19:47:27 +11004
5GERRIT_SITE=$1
Joshua Hesketh1c8d2df2014-05-05 15:48:31 +10006GIT_ORIGIN=$2
Michael Stille8cadae2014-01-06 19:47:27 +11007
8if [ -z "$GERRIT_SITE" ]
9then
10 echo "The gerrit site name (eg 'https://review.openstack.org') must be the first argument."
11 exit 1
12fi
13
Joshua Hesketh1c8d2df2014-05-05 15:48:31 +100014if [ -z "$ZUUL_URL" ]
Michael Stille8cadae2014-01-06 19:47:27 +110015then
Joshua Hesketh1c8d2df2014-05-05 15:48:31 +100016 echo "The ZUUL_URL must be provided."
Michael Stille8cadae2014-01-06 19:47:27 +110017 exit 1
18fi
19
20if [ -z "$GIT_ORIGIN" ] || [ -n "$ZUUL_NEWREV" ]
21then
22 GIT_ORIGIN="$GERRIT_SITE/p"
23 # git://git.openstack.org/
24 # https://review.openstack.org/p
25fi
26
27if [ -z "$ZUUL_REF" ]
28then
Joshua Hesketh1c8d2df2014-05-05 15:48:31 +100029 if [ -n "$BRANCH" ]
30 then
31 echo "No ZUUL_REF so using requested branch $BRANCH from origin."
32 ZUUL_REF=$BRANCH
33 # use the origin since zuul mergers have outdated branches
34 ZUUL_URL=$GIT_ORIGIN
35 else
36 echo "Provide either ZUUL_REF or BRANCH in the calling enviromnent."
37 exit 1
38 fi
Michael Stille8cadae2014-01-06 19:47:27 +110039fi
40
41if [ ! -z "$ZUUL_CHANGE" ]
42then
43 echo "Triggered by: $GERRIT_SITE/$ZUUL_CHANGE"
44fi
45
46set -x
47if [[ ! -e .git ]]
48then
49 ls -a
50 rm -fr .[^.]* *
51 if [ -d /opt/git/$ZUUL_PROJECT/.git ]
52 then
Joshua Hesketh326fd8a2015-06-05 12:37:44 +100053 git clone -vvvvvv file:///opt/git/$ZUUL_PROJECT .
Michael Stille8cadae2014-01-06 19:47:27 +110054 else
Joshua Hesketh326fd8a2015-06-05 12:37:44 +100055 git clone -vvvvvv $GIT_ORIGIN/$ZUUL_PROJECT .
Michael Stille8cadae2014-01-06 19:47:27 +110056 fi
57fi
Joshua Hesketh326fd8a2015-06-05 12:37:44 +100058git remote -vvvvvv set-url origin $GIT_ORIGIN/$ZUUL_PROJECT
Michael Stille8cadae2014-01-06 19:47:27 +110059
60# attempt to work around bugs 925790 and 1229352
Joshua Hesketh326fd8a2015-06-05 12:37:44 +100061if ! git remote -vvvvvv update
Michael Stille8cadae2014-01-06 19:47:27 +110062then
63 echo "The remote update failed, so garbage collecting before trying again."
64 git gc
Joshua Hesketh326fd8a2015-06-05 12:37:44 +100065 git remote -vvvvvv update
Michael Stille8cadae2014-01-06 19:47:27 +110066fi
67
68git reset --hard
69if ! git clean -x -f -d -q ; then
70 sleep 1
71 git clean -x -f -d -q
72fi
73
Joshua Hesketh1c8d2df2014-05-05 15:48:31 +100074if echo "$ZUUL_REF" | grep -q ^refs/tags/
Michael Stille8cadae2014-01-06 19:47:27 +110075then
Joshua Hesketh326fd8a2015-06-05 12:37:44 +100076 git fetch -vvvvvv --tags $ZUUL_URL/$ZUUL_PROJECT
Joshua Hesketh1c8d2df2014-05-05 15:48:31 +100077 git checkout $ZUUL_REF
78 git reset --hard $ZUUL_REF
79elif [ -z "$ZUUL_NEWREV" ]
80then
Joshua Hesketh326fd8a2015-06-05 12:37:44 +100081 git fetch -vvvvvv $ZUUL_URL/$ZUUL_PROJECT $ZUUL_REF
Michael Stille8cadae2014-01-06 19:47:27 +110082 git checkout FETCH_HEAD
83 git reset --hard FETCH_HEAD
Michael Stille8cadae2014-01-06 19:47:27 +110084else
85 git checkout $ZUUL_NEWREV
86 git reset --hard $ZUUL_NEWREV
Michael Stille8cadae2014-01-06 19:47:27 +110087fi
Joshua Hesketh1c8d2df2014-05-05 15:48:31 +100088
89if ! git clean -x -f -d -q ; then
90 sleep 1
91 git clean -x -f -d -q
92fi
Michael Stille8cadae2014-01-06 19:47:27 +110093
94if [ -f .gitmodules ]
95then
96 git submodule init
97 git submodule sync
98 git submodule update --init
Michael Stillbcd886e2014-01-10 15:13:42 +110099fi
Joshua Hesketh57b415a2014-05-06 14:14:38 +1000100
101# Added for turbo-hipster
102git branch -D working || true
103git checkout -b working