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 | # |
Diana Picus | 72189fd | 2016-05-23 19:32:46 +0300 | [diff] [blame] | 7 | # Syntax: git-pull linaro-local/[branch] |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 8 | |
| 9 | . llvm-common |
| 10 | |
| 11 | branch=$1 |
| 12 | if [[ $branch = '' ]]; then |
| 13 | branch=`get_branch` |
| 14 | fi |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 15 | |
| 16 | if [[ $branch = 'master' ]]; then |
| 17 | echo "Can't pull the master branch." |
| 18 | echo "Use git-refresh instead." |
| 19 | exit 1 |
| 20 | fi |
| 21 | |
| 22 | prefix="linaro-local/" |
| 23 | if echo $branch | grep -q linaro-local; then |
| 24 | prefix="" |
| 25 | fi |
| 26 | |
| 27 | safe_run git-refresh |
| 28 | |
| 29 | if git branch -a | not grep -q $branch; then |
| 30 | echo "Branch '$branch' doesn't exist in this repository" |
| 31 | exit 2 |
| 32 | fi |
| 33 | |
| 34 | # If the branch exists already, merge |
| 35 | if git branch | grep -q $branch; then |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 36 | echo " + Merging the origin branch..." |
| 37 | if not git merge --ff-only origin/$prefix$branch; then |
Diana Picus | 72189fd | 2016-05-23 19:32:46 +0300 | [diff] [blame] | 38 | echo "Error merging the branch." |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 39 | exit 1 |
| 40 | fi |
| 41 | # If not, just check out the branch |
| 42 | else |
| 43 | safe_run git checkout -b $branch origin/$prefix$branch |
| 44 | fi |