]>
Commit | Line | Data |
---|---|---|
1 | #!/bin/bash | |
2 | # Helper to rewrite all local branches. | |
3 | ||
4 | rb_one() { | |
5 | local b=$1 | |
6 | shift | |
7 | ||
8 | printf "${BRACKET}### ${GREEN}${b}${NORMAL}" | |
9 | if ! git config --local "branch.${b}.merge" >/dev/null; then | |
10 | echo " -> skipping due to missing merge branch" | |
11 | else | |
12 | echo | |
13 | git checkout -q "${b}" || return | |
14 | git rebase "${opts[@]}" | sed -e '/^Fast-forwarded/d' -e "s:^:${BAD}:" -e "s:$:${NORMAL}:" | |
15 | if [[ ${PIPESTATUS[0]} -ne 0 ]] ; then | |
16 | git rebase --abort | |
17 | fi | |
18 | fi | |
19 | } | |
20 | ||
21 | usage() { | |
22 | cat <<EOF | |
23 | Usage: rb-all [-q] | |
24 | EOF | |
25 | exit 1 | |
26 | } | |
27 | ||
28 | main() { | |
29 | local opts=(-q) | |
30 | while [[ $# -ne 0 ]] ; do | |
31 | case $1 in | |
32 | -q|-v|-n|--no-stat|--stat) opts+=( "$1" );; | |
33 | *) usage ;; | |
34 | esac | |
35 | shift | |
36 | done | |
37 | ||
38 | [[ -z ${GOOD} ]] && eval "$(bash-colors --env)" | |
39 | ||
40 | # Switch to the top dir in case the working dir doesn't exist in every branch. | |
41 | cd "$(git rev-parse --show-toplevel)" || return | |
42 | ||
43 | # Skip if rebase is in progress. | |
44 | if [[ -e $(git rev-parse --git-path rebase-merge) || \ | |
45 | -e $(git rev-parse --git-path rebase-apply) ]] ; then | |
46 | printf "${BAD}skipping due to active rebase${NORMAL}\n" | |
47 | exit 1 | |
48 | fi | |
49 | ||
50 | local orig b branches | |
51 | orig=$(git rev-parse --abbrev-ref HEAD) || return | |
52 | ||
53 | branches=( $(git for-each-ref --format='%(refname:short)' 'refs/heads/*') ) | |
54 | for b in "${branches[@]}" ; do | |
55 | # If it's a branch in another worktree, ignore it. | |
56 | if [[ $(git branch --list "${b}") != "+"* ]] ; then | |
57 | rb_one "${b}" "${opts[@]}" | |
58 | fi | |
59 | done | |
60 | ||
61 | git checkout -q "${orig}" | |
62 | } | |
63 | main "$@" |