Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 1 | #!/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 | |
| 13 | echo "Rebasing all branches" |
| 14 | branch=`get_branch` |
| 15 | |
| 16 | if [[ `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 |
| 20 | fi |
| 21 | |
| 22 | if [[ $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 |
| 28 | fi |
| 29 | |
| 30 | branches=`get_branches` |
| 31 | for 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 |
| 43 | done |
| 44 | |
| 45 | final_branch=`get_branch` |
| 46 | if [[ $branch != $final_branch ]]; then |
| 47 | echo "Back to original branch" |
| 48 | safe_run git checkout $branch |
| 49 | fi |