Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | # This script pulls a specific branch from the origin repository, making sure |
| 4 | # not to keep the prefix. If the branch already exists, try to merge. If not, |
| 5 | # check out from origin. |
| 6 | # |
| 7 | # Syntax: git-pull linaro-local/[branch] -f |
| 8 | |
| 9 | . llvm-common |
| 10 | |
| 11 | branch=$1 |
| 12 | if [[ $branch = '' ]]; then |
| 13 | branch=`get_branch` |
| 14 | fi |
| 15 | force=$2 |
| 16 | if [[ $force != '-f' ]]; then |
| 17 | force= |
| 18 | fi |
| 19 | |
| 20 | if [[ $branch = 'master' ]]; then |
| 21 | echo "Can't pull the master branch." |
| 22 | echo "Use git-refresh instead." |
| 23 | exit 1 |
| 24 | fi |
| 25 | |
| 26 | prefix="linaro-local/" |
| 27 | if echo $branch | grep -q linaro-local; then |
| 28 | prefix="" |
| 29 | fi |
| 30 | |
| 31 | safe_run git-refresh |
| 32 | |
| 33 | if git branch -a | not grep -q $branch; then |
| 34 | echo "Branch '$branch' doesn't exist in this repository" |
| 35 | exit 2 |
| 36 | fi |
| 37 | |
| 38 | # If the branch exists already, merge |
| 39 | if git branch | grep -q $branch; then |
| 40 | if [[ $force = '-f' ]]; then |
| 41 | echo " + Force check out $branch" |
| 42 | safe_run git checkout master |
| 43 | safe_run git branch -D $branch |
| 44 | safe_run git checkout -b $branch origin/$prefix$branch |
| 45 | exit 0 |
| 46 | fi |
| 47 | |
| 48 | echo " + Merging the origin branch..." |
| 49 | if not git merge --ff-only origin/$prefix$branch; then |
| 50 | echo "Error merging the branch. Use -f to force." |
| 51 | exit 1 |
| 52 | fi |
| 53 | # If not, just check out the branch |
| 54 | else |
| 55 | safe_run git checkout -b $branch origin/$prefix$branch |
| 56 | fi |