#!/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