Add support for submodules.
[git-scripts.git] / git-wip
bloba2d4e52a985e3e23b407c4f79edd2634e3b87003
1 #! /bin/sh
3 program=$0
5 USAGE='[--stat]'
7 LONG_USAGE=" Read wip file and display topic branch/log waiting for merging
9 The WIP file is '.git/.wip'. There is three kinds of line:
11 <empty> : does nothing
12 --- <text> : display --- <text> as-is
13 branch [branch-point] : output commits done on branch since branch-point
14 Default value for branch-point is master.
17 exec_path=$(git --exec-path)
18 . $exec_path/git-sh-setup
19 require_work_tree
20 cd_to_toplevel
22 FILE=".git/.wip"
23 STAT=0
25 display () {
26 branch=$1
27 from=${2:-master}
28 n=$(git cherry $from $branch | wc -l)
29 echo
30 printf " * $branch (`git log -1 --pretty="%ai" $branch`)"
31 if [ "$n" = "" ]; then
32 echo ""
33 elif [ "$n" = "1" ]; then
34 echo " 1 commit"
35 else
36 echo " $n commits"
38 git log --pretty=" %s" $branch ^$from |
39 while read line; do printf -- " - %s\n" "$line"; done
40 if [ "$STAT" = "1" ]; then
41 echo ""
42 git diff $branch~$n..$branch --stat | sed 's,^, ,g'
46 handle_line () {
47 line="$1"
48 first=$2
50 case "$first" in
51 "") ;;
52 "---") echo; echo "$line";
54 *) display $first $3;
55 esac
58 while :
60 case $1 in
61 -h|*help)
62 usage
64 --stat)
65 STAT=1
68 if [ -f $FILE ]; then
69 while read line; do handle_line "$line" $line; done < $FILE;
70 else
71 echo No WIP description for this project.
73 break
75 esac
76 shift
77 done