aboutsummaryrefslogtreecommitdiff
path: root/helpers/git-pull
blob: 6db6029ca1e46de9cd95242dbc559412e8bac396 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env bash

# This script pulls a specific branch from the origin repository, making sure
# not to keep the prefix. If the branch already exists, try to merge. If not,
# check out from origin.
#
# Syntax: git-pull linaro-local/[branch]

. llvm-common

branch=$1
if [[ $branch = '' ]]; then
  branch=`get_branch`
fi

if [[ $branch = 'master' ]]; then
  echo "Can't pull the master branch."
  echo "Use git-refresh instead."
  exit 1
fi

prefix="linaro-local/"
if echo $branch | grep -q linaro-local; then
  prefix=""
fi

safe_run git-refresh

if git branch -a | not grep -q $branch; then
	echo "Branch '$branch' doesn't exist in this repository"
	exit 2
fi

# If the branch exists already, merge
if git branch | grep -q $branch; then
  echo " + Merging the origin branch..."
  if not git merge --ff-only origin/$prefix$branch; then
    echo "Error merging the branch."
    exit 1
  fi
# If not, just check out the branch
else
  safe_run git checkout -b $branch origin/$prefix$branch
fi