aboutsummaryrefslogtreecommitdiff
path: root/helpers/git-pull
blob: 3dbd3e1df43f85f2b630fd38f7dc727975d0db25 (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
45
46
47
48
49
50
51
52
53
54
55
56
#!/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] -f

. llvm-common

branch=$1
if [[ $branch = '' ]]; then
  branch=`get_branch`
fi
force=$2
if [[ $force != '-f' ]]; then
  force=
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
  if [[ $force = '-f' ]]; then
    echo " + Force check out $branch"
    safe_run git checkout master
    safe_run git branch -D $branch
    safe_run git checkout -b $branch origin/$prefix$branch
    exit 0
  fi

  echo " + Merging the origin branch..."
  if not git merge --ff-only origin/$prefix$branch; then
    echo "Error merging the branch. Use -f to force."
    exit 1
  fi
# If not, just check out the branch
else
  safe_run git checkout -b $branch origin/$prefix$branch
fi