blob: 6b09246c5c2d5afc235dfed03823578eed2f04b4 [file] [log] [blame]
Renato Golin94cc1042016-04-26 11:02:23 +01001#!/usr/bin/env bash
2
3# This script rebases all branches based on the current master. It does not
4# pull upstream master beforehand. If you need a fresh master, use git-refresh.
5# If you want to rebase only one branch, use the first argument for that.
6# To protect broken branches from being merged (and forcing a manual merge),
7# rename it to <name>-disabled and it'll be skipped.
8#
9# Syntax: git-rebase-all [branch (default=all)]
10
11. llvm-common
12
13echo "Rebasing all branches"
14branch=`get_branch`
15
16if [[ `git diff | head -1` != '' ]]; then
17 echo "You have uncommitted changes in your repo, bailing"
18 echo "Please, stash your changes and run this script again"
19 exit 2
20fi
21
22if [[ $1 != '' ]]; then
23 if [[ `git branch | grep $1` = '' ]]; then
24 echo "Branch '$1' doesn't exist in this repository"
25 exit 3
26 fi
27 branch=$1
28fi
29
30branches=`get_branches`
31for br in $branches; do
32 if [[ $br != 'master' && `echo $br | grep "^disabled"` == '' ]]; then
33 safe_run git checkout $br
34 git rebase master
35 if [[ $? != 0 ]]; then
36 echo "Rebase failed, aborting rebase..."
37 safe_run git rebase --abort
38 safe_run git checkout master
39 exit 1
40 fi
41 safe_run git checkout master
42 fi
43done
44
45final_branch=`get_branch`
46if [[ $branch != $final_branch ]]; then
47 echo "Back to original branch"
48 safe_run git checkout $branch
49fi