| #!/usr/bin/env bash |
| |
| # This script rebases all branches based on the current master. It does not |
| # pull upstream master beforehand. If you need a fresh master, use git-refresh. |
| # If you want to rebase only one branch, use the first argument for that. |
| # To protect broken branches from being merged (and forcing a manual merge), |
| # rename it to <name>-disabled and it'll be skipped. |
| # |
| # Syntax: git-rebase-all [branch (default=all)] |
| |
| . llvm-common |
| |
| echo "Rebasing all branches" |
| branch=`get_branch` |
| |
| if [[ `git diff | head -1` != '' ]]; then |
| echo "You have uncommitted changes in your repo, bailing" |
| echo "Please, stash your changes and run this script again" |
| exit 2 |
| fi |
| |
| if [[ $1 != '' ]]; then |
| if [[ `git branch | grep $1` = '' ]]; then |
| echo "Branch '$1' doesn't exist in this repository" |
| exit 3 |
| fi |
| branch=$1 |
| fi |
| |
| branches=`get_branches` |
| for br in $branches; do |
| if [[ $br != 'master' && `echo $br | grep "^disabled"` == '' ]]; then |
| safe_run git checkout $br |
| git rebase master |
| if [[ $? != 0 ]]; then |
| echo "Rebase failed, aborting rebase..." |
| safe_run git rebase --abort |
| safe_run git checkout master |
| exit 1 |
| fi |
| safe_run git checkout master |
| fi |
| done |
| |
| final_branch=`get_branch` |
| if [[ $branch != $final_branch ]]; then |
| echo "Back to original branch" |
| safe_run git checkout $branch |
| fi |