aboutsummaryrefslogtreecommitdiff
path: root/helpers/git-rebase-all
blob: 6b09246c5c2d5afc235dfed03823578eed2f04b4 (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
#!/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