Michael Still | e8cadae | 2014-01-06 19:47:27 +1100 | [diff] [blame] | 1 | #!/bin/bash -e |
| 2 | |
Joshua Hesketh | 1c8d2df | 2014-05-05 15:48:31 +1000 | [diff] [blame] | 3 | # Stolen from http://git.openstack.org/cgit/openstack-infra/config/plain/modules/jenkins/files/slave_scripts/gerrit-git-prep.sh |
Michael Still | e8cadae | 2014-01-06 19:47:27 +1100 | [diff] [blame] | 4 | |
| 5 | GERRIT_SITE=$1 |
Joshua Hesketh | 1c8d2df | 2014-05-05 15:48:31 +1000 | [diff] [blame] | 6 | GIT_ORIGIN=$2 |
Michael Still | e8cadae | 2014-01-06 19:47:27 +1100 | [diff] [blame] | 7 | |
| 8 | if [ -z "$GERRIT_SITE" ] |
| 9 | then |
| 10 | echo "The gerrit site name (eg 'https://review.openstack.org') must be the first argument." |
| 11 | exit 1 |
| 12 | fi |
| 13 | |
Joshua Hesketh | 1c8d2df | 2014-05-05 15:48:31 +1000 | [diff] [blame] | 14 | if [ -z "$ZUUL_URL" ] |
Michael Still | e8cadae | 2014-01-06 19:47:27 +1100 | [diff] [blame] | 15 | then |
Joshua Hesketh | 1c8d2df | 2014-05-05 15:48:31 +1000 | [diff] [blame] | 16 | echo "The ZUUL_URL must be provided." |
Michael Still | e8cadae | 2014-01-06 19:47:27 +1100 | [diff] [blame] | 17 | exit 1 |
| 18 | fi |
| 19 | |
| 20 | if [ -z "$GIT_ORIGIN" ] || [ -n "$ZUUL_NEWREV" ] |
| 21 | then |
| 22 | GIT_ORIGIN="$GERRIT_SITE/p" |
| 23 | # git://git.openstack.org/ |
| 24 | # https://review.openstack.org/p |
| 25 | fi |
| 26 | |
| 27 | if [ -z "$ZUUL_REF" ] |
| 28 | then |
Joshua Hesketh | 1c8d2df | 2014-05-05 15:48:31 +1000 | [diff] [blame] | 29 | 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 Still | e8cadae | 2014-01-06 19:47:27 +1100 | [diff] [blame] | 39 | fi |
| 40 | |
| 41 | if [ ! -z "$ZUUL_CHANGE" ] |
| 42 | then |
| 43 | echo "Triggered by: $GERRIT_SITE/$ZUUL_CHANGE" |
| 44 | fi |
| 45 | |
| 46 | set -x |
| 47 | if [[ ! -e .git ]] |
| 48 | then |
| 49 | ls -a |
| 50 | rm -fr .[^.]* * |
| 51 | if [ -d /opt/git/$ZUUL_PROJECT/.git ] |
| 52 | then |
Joshua Hesketh | 326fd8a | 2015-06-05 12:37:44 +1000 | [diff] [blame^] | 53 | git clone -vvvvvv file:///opt/git/$ZUUL_PROJECT . |
Michael Still | e8cadae | 2014-01-06 19:47:27 +1100 | [diff] [blame] | 54 | else |
Joshua Hesketh | 326fd8a | 2015-06-05 12:37:44 +1000 | [diff] [blame^] | 55 | git clone -vvvvvv $GIT_ORIGIN/$ZUUL_PROJECT . |
Michael Still | e8cadae | 2014-01-06 19:47:27 +1100 | [diff] [blame] | 56 | fi |
| 57 | fi |
Joshua Hesketh | 326fd8a | 2015-06-05 12:37:44 +1000 | [diff] [blame^] | 58 | git remote -vvvvvv set-url origin $GIT_ORIGIN/$ZUUL_PROJECT |
Michael Still | e8cadae | 2014-01-06 19:47:27 +1100 | [diff] [blame] | 59 | |
| 60 | # attempt to work around bugs 925790 and 1229352 |
Joshua Hesketh | 326fd8a | 2015-06-05 12:37:44 +1000 | [diff] [blame^] | 61 | if ! git remote -vvvvvv update |
Michael Still | e8cadae | 2014-01-06 19:47:27 +1100 | [diff] [blame] | 62 | then |
| 63 | echo "The remote update failed, so garbage collecting before trying again." |
| 64 | git gc |
Joshua Hesketh | 326fd8a | 2015-06-05 12:37:44 +1000 | [diff] [blame^] | 65 | git remote -vvvvvv update |
Michael Still | e8cadae | 2014-01-06 19:47:27 +1100 | [diff] [blame] | 66 | fi |
| 67 | |
| 68 | git reset --hard |
| 69 | if ! git clean -x -f -d -q ; then |
| 70 | sleep 1 |
| 71 | git clean -x -f -d -q |
| 72 | fi |
| 73 | |
Joshua Hesketh | 1c8d2df | 2014-05-05 15:48:31 +1000 | [diff] [blame] | 74 | if echo "$ZUUL_REF" | grep -q ^refs/tags/ |
Michael Still | e8cadae | 2014-01-06 19:47:27 +1100 | [diff] [blame] | 75 | then |
Joshua Hesketh | 326fd8a | 2015-06-05 12:37:44 +1000 | [diff] [blame^] | 76 | git fetch -vvvvvv --tags $ZUUL_URL/$ZUUL_PROJECT |
Joshua Hesketh | 1c8d2df | 2014-05-05 15:48:31 +1000 | [diff] [blame] | 77 | git checkout $ZUUL_REF |
| 78 | git reset --hard $ZUUL_REF |
| 79 | elif [ -z "$ZUUL_NEWREV" ] |
| 80 | then |
Joshua Hesketh | 326fd8a | 2015-06-05 12:37:44 +1000 | [diff] [blame^] | 81 | git fetch -vvvvvv $ZUUL_URL/$ZUUL_PROJECT $ZUUL_REF |
Michael Still | e8cadae | 2014-01-06 19:47:27 +1100 | [diff] [blame] | 82 | git checkout FETCH_HEAD |
| 83 | git reset --hard FETCH_HEAD |
Michael Still | e8cadae | 2014-01-06 19:47:27 +1100 | [diff] [blame] | 84 | else |
| 85 | git checkout $ZUUL_NEWREV |
| 86 | git reset --hard $ZUUL_NEWREV |
Michael Still | e8cadae | 2014-01-06 19:47:27 +1100 | [diff] [blame] | 87 | fi |
Joshua Hesketh | 1c8d2df | 2014-05-05 15:48:31 +1000 | [diff] [blame] | 88 | |
| 89 | if ! git clean -x -f -d -q ; then |
| 90 | sleep 1 |
| 91 | git clean -x -f -d -q |
| 92 | fi |
Michael Still | e8cadae | 2014-01-06 19:47:27 +1100 | [diff] [blame] | 93 | |
| 94 | if [ -f .gitmodules ] |
| 95 | then |
| 96 | git submodule init |
| 97 | git submodule sync |
| 98 | git submodule update --init |
Michael Still | bcd886e | 2014-01-10 15:13:42 +1100 | [diff] [blame] | 99 | fi |
Joshua Hesketh | 57b415a | 2014-05-06 14:14:38 +1000 | [diff] [blame] | 100 | |
| 101 | # Added for turbo-hipster |
| 102 | git branch -D working || true |
| 103 | git checkout -b working |