blob: 3dbd3e1df43f85f2b630fd38f7dc727975d0db25 [file] [log] [blame]
Renato Golin94cc1042016-04-26 11:02:23 +01001#!/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
11branch=$1
12if [[ $branch = '' ]]; then
13 branch=`get_branch`
14fi
15force=$2
16if [[ $force != '-f' ]]; then
17 force=
18fi
19
20if [[ $branch = 'master' ]]; then
21 echo "Can't pull the master branch."
22 echo "Use git-refresh instead."
23 exit 1
24fi
25
26prefix="linaro-local/"
27if echo $branch | grep -q linaro-local; then
28 prefix=""
29fi
30
31safe_run git-refresh
32
33if git branch -a | not grep -q $branch; then
34 echo "Branch '$branch' doesn't exist in this repository"
35 exit 2
36fi
37
38# If the branch exists already, merge
39if 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
54else
55 safe_run git checkout -b $branch origin/$prefix$branch
56fi