|
| 1 | +#!/bin/sh -e |
| 2 | +get_spongepowered_remote() { |
| 3 | + git remote -v | grep -E 'SpongePowered\/'`basename $(pwd)`'(\.git)? \(fetch\)' | awk -F"\t" '{print $1}' |
| 4 | +} |
| 5 | + |
| 6 | +checkout() { |
| 7 | + if git rev-parse $1>/dev/null 2>/dev/null |
| 8 | + then git checkout $1 |
| 9 | + else git checkout -b `get-spongepowered-remote`/$1 $1 |
| 10 | + fi |
| 11 | +} |
| 12 | + |
| 13 | +# $1 should be a pattern containing OUT |
| 14 | +# $2, if present, should be the smallest number |
| 15 | +get_largest_numbered_branch() { |
| 16 | + x= |
| 17 | + if [ ! -z $2 ] |
| 18 | + then x=$(($2 + 1)) |
| 19 | + else x=1 |
| 20 | + fi |
| 21 | + |
| 22 | + remote=`get_spongepowered_remote` |
| 23 | + # Must pipe git branch through grep -e '.*'; git branch does not error when no branches match, but grep does. |
| 24 | + while git branch --list -a $remote/`echo $1 | sed 's/OUT/'$x'/'` | grep -e '.*' > /dev/null |
| 25 | + do x=$((x + 1)) |
| 26 | + done |
| 27 | + echo $((x - 1)) |
| 28 | +} |
| 29 | + |
| 30 | +help() { |
| 31 | + echo "Usage:" > /dev/stderr |
| 32 | + echo " $0 b - Check out the latest bleeding version" > /dev/stderr |
| 33 | + echo " $0 s - Check out the latest stable version" > /dev/stderr |
| 34 | + echo " $0 <major API version> - Check out a specific stable version" > /dev/stderr |
| 35 | + echo " Example: $0 6" > /dev/stderr |
| 36 | + echo " Minimum supported version is 5" > /dev/stderr |
| 37 | + exit 1 |
| 38 | +} |
| 39 | + |
| 40 | +if [ $# -ne 1 ] |
| 41 | +then help |
| 42 | +elif [ $1 = b ] |
| 43 | +then |
| 44 | + echo Fetching all repositories... |
| 45 | + git submodule foreach --recursive git fetch --all --prune |
| 46 | + echo |
| 47 | + echo Checking out bleeding... |
| 48 | + git submodule foreach --recursive git checkout bleeding |
| 49 | +elif [ $1 = s ] || [ $(($1)) -gt 4 ] # If it isn't a number, it will resolve to 0, and thus not be checked. |
| 50 | +then |
| 51 | + echo Fetching all repositories... |
| 52 | + git submodule foreach --recursive git fetch --all --prune |
| 53 | + echo |
| 54 | + |
| 55 | + cd SpongeCommon |
| 56 | + major=$1 |
| 57 | + if [ $major = s ] |
| 58 | + then |
| 59 | + major=`get_largest_numbered_branch "stable-OUT" 5` |
| 60 | + echo Will check out API version $major in all repositories. |
| 61 | + elif [ $major -lt 5 ] |
| 62 | + then |
| 63 | + help |
| 64 | + elif ! (git branch --list -a `get_spongepowered_remote`/stable-$major | grep -e '.*') > /dev/null |
| 65 | + then |
| 66 | + echo No such API version $major. If you want bleeding, use '"b"' instead. > /dev/stderr |
| 67 | + exit 1 |
| 68 | + fi |
| 69 | + echo Checking out SpongeCommon... |
| 70 | + checkout stable-$major |
| 71 | + cd .. |
| 72 | + echo |
| 73 | + echo Checking out SpongeForge... |
| 74 | + cd SpongeForge |
| 75 | + checkout stable-$major |
| 76 | + cd .. |
| 77 | + echo |
| 78 | + echo Checking out SpongeVanilla... |
| 79 | + cd SpongeVanilla |
| 80 | + checkout stable-$major |
| 81 | + cd .. |
| 82 | + echo |
| 83 | + |
| 84 | + cd SpongeCommon/SpongeAPI |
| 85 | + minor=`get_largest_numbered_branch "stable-$major.OUT.0"` |
| 86 | + patch=`get_largest_numbered_branch "stable-$major.$minor.OUT"` |
| 87 | + echo Checking out SpongeAPI... |
| 88 | + checkout stable-$major.$minor.$patch |
| 89 | + cd ../.. |
| 90 | +else help |
| 91 | +fi |
| 92 | +echo |
| 93 | +echo Pulling all repositories... |
| 94 | +git submodule foreach --recursive git pull |
0 commit comments