3 # This script uses git branch and rev-list commands to output changes between
6 # $ git rev-list master..topic
7 # list all changes made in topic not yet in master
8 # This is used to list changes not yet merged in master
10 # $ git rev-list topic..master
11 # list all changes made on master not in topic
12 # This is used to check if a rebase is needed for a clean fast-forward
14 # The master branch is master by default
20 COLOR
=1 # Colorize by default
21 SHOW_MERGE_BASE_DATE
=0
24 echo "$0 [-r] [-v] [-l] [--help] [<origin>] [<branchname>]"
26 echo "This command will compare all branches on a git repository against"
27 echo "the branch given in option (default is master). By default it just"
28 echo "output the number of commits not yet merged on <branchname>."
30 echo " -r : also output the number of commits done"
31 echo " on <branchname> since last merge."
32 echo " -l : list commits to be merged."
33 echo " -sd : show split date (merge base)"
34 echo " --no-color : disable color"
35 echo " -v : verbose mode"
39 function set_colors
() {
41 COL_RESET
=$ESC_SEQ"39;49;00m"
42 COL_RED
=$ESC_SEQ"31;01m"
43 COL_GREEN
=$ESC_SEQ"32;01m"
44 COL_YELLOW
=$ESC_SEQ"33;01m"
45 COL_BROWN
=$ESC_SEQ"33;02m"
46 COL_BLUE
=$ESC_SEQ"34;01m"
47 COL_MAGENTA
=$ESC_SEQ"35;01m"
48 COL_CYAN
=$ESC_SEQ"36;01m"
51 if [[ -z $
(git-symbolic-ref HEAD
2>/dev
/null
) ]]; then
52 echo Must be run inside a Git repository
69 SHOW_MERGE_BASE_DATE
=1
71 -h|
--h|
--he|
--hel|
--help)
80 if [ "$MASTER" = "" ]; then
83 if [ "$ORIGIN" = "" ]; then
93 if [ "$MASTER" = "" ]; then
97 if [ "$COLOR" = "1" ]; then
101 # Check if $MASTER branch exists
103 if [[ -z $
(git show-ref refs
/heads
/master
) ]]; then
104 # No $MASTER branch. Use current branch
106 if [[ "$MASTER" != "master" ]]; then
107 # Do not warn if MASTER was automatically set
108 echo Warning.
$MASTER branch does not exist
111 MASTER
=$
(git-symbolic-ref HEAD
)
115 echo Check all branches against
$MASTER
117 function check_branch
(){
122 if [ "$SHOW_MERGE_BASE_DATE" = "1" ]; then
123 refpoint
=$
(git merge-base
$branch $MASTER)
125 refpoint
=$
(git rev-parse
$branch)
128 BOUTPUT
=$COL_BROWN${branch}$COL_BLUE
129 BOUTPUT
=$BOUTPUT" "$
(git log
$refpoint -1 --pretty=format
:"%ar, %s")
130 BOUTPUT
=$BOUTPUT$COL_RESET
134 if [ "$REBASE" = "1" ]; then
135 REVLIST
=$
(git rev-list
--pretty=oneline
$branch..
$MASTER)
136 if [ "$REVLIST" != "" ]; then
138 n
=$
(echo -e "$REVLIST" |
wc -l)
139 BOUTPUT
="$BOUTPUT\n\t$COL_RED$n$COL_RESET commit(s) away"
141 if [ "$VERBOSE" = "1" ]; then
142 BOUTPUT
="$BOUTPUT\n\tno rebase required"
147 REVLIST
=$
(git rev-list
--pretty=oneline
$MASTER..
$branch)
148 if [ "$REVLIST" != "" ]; then
150 n
=$
(echo -e "$REVLIST" |
wc -l)
151 BOUTPUT
="$BOUTPUT\n\t$COL_RED$n$COL_RESET merge(s) waiting"
152 if [ "$LIST" = "1" ]; then
153 BOUTPUT
="$BOUTPUT\n$REVLIST"
156 if [ "$VERBOSE" = "1" ]; then
157 BOUTPUT
="$BOUTPUT\n\tnothing to merge"
161 if [ "$BOUTPUT" != "$branch" ]; then
162 case "$left$right" in
172 echo -e "$BOUTPUT$COL_RESET"
177 if [ "$ORIGIN" != "" ]; then
180 # List all branched, removes the star and skip the master branch
182 git branch |
sed 's,*,,g' |
grep -v $MASTER |
while read entry