Announce, WI and SA updates.
[git.git] / TO
1 #!/bin/sh
2
3 clean= next=next
4 while case $# in 0) break ;; esac
5 do
6         case "$1" in
7         --clean)
8                 branch=`git symbolic-ref HEAD` &&
9                 test refs/heads/master = "$branch" || {
10                         echo >&2 Not on master 
11                         exit 1
12                 }
13                 clean=t
14                 ;;
15         --next)
16                 test 2 -le $# || {
17                         echo >&2 "Need argument"
18                         exit 1
19                 }
20                 next="$2"
21                 git rev-parse --verify "$next" >/dev/null || exit
22                 shift
23                 ;;
24         *)
25                 echo >&2 "$0 [--clean | --next test-next ]"
26                 exit 1
27                 ;;
28         esac
29         shift
30 done
31
32 master_sha1=`git rev-parse --verify refs/heads/master`
33 LF='
34 '
35 (cd .git/refs/heads && find -type f) |
36 sed -n \
37     -e 's/^\.\///' \
38     -e '/^[^\/][^\/]\//p' |
39 while read topic
40 do
41         rebase= done= not_done= trouble= date=
42         topic_sha1=`git rev-parse --verify "refs/heads/$topic"`
43
44         date=`
45                 git-rev-list -1 --pretty "$topic" |
46                 sed -ne 's/^Date: *\(.*\)/ (\1)/p'
47         `
48         # (1)
49         only_next_1=`git-rev-list ^master "^$topic" ${next} | sort`
50         only_next_2=`git-rev-list ^master           ${next} | sort`
51         if test "$only_next_1" = "$only_next_2"
52         then
53                 not_in_topic=`git-rev-list "^$topic" master`
54                 if test -z "$not_in_topic"
55                 then
56                         rebase=" (vanilla)"
57                 else
58                         rebase=" (can be rebased)"
59                 fi
60         fi
61
62         # (2)
63         not_in_master=`
64                 git-rev-list ^master "$topic"
65         `
66         test -z "$not_in_master" &&
67         done="${LF}Fully merged -- delete."
68
69         # (3)
70         not_in_next=`
71                 git-rev-list --pretty=oneline ^${next} "$topic" |
72                 sed -e 's/^[0-9a-f]* / - /'
73         `
74         if test -n "$not_in_next"
75         then
76                 if test -n "$done"
77                 then
78                         # If $topic and master are the same,
79                         # it is fine.
80                         test "$master_sha1" = "$topic_sha1" ||
81                         trouble="${LF}### MODIFIED AFTER COOKED ###"
82                 fi
83                 not_done="${LF}Still not merged in ${next}$rebase.$LF$not_in_next"
84         elif test -n "$done"
85         then
86                 not_done=
87         else
88                 not_done="${LF}Up to date."
89         fi
90
91         echo "*** $topic ***$date$trouble$done$not_done"
92
93         if test -z "$trouble$not_done" &&
94             test -n "$done" &&
95             test t = "$clean"
96         then
97                 git branch -d "$topic"
98         fi
99 done
100
101 exit
102
103 ################################################################
104 Using Topic Branches
105
106 Some important disciplines first.
107
108  * Once a topic branch forks from "master", never merge "master"
109    updates into the topic branch.
110
111  * Once a topic branch is fully cooked and merged into "master",
112    delete it.  If you need to build on top of it to correct
113    earlier mistakes, create a new topic branch by forking at the
114    tip of the "master".  This is not strictly necessary, but it
115    makes it easier to keep your history simple.
116
117  * Whenever you need to test or publish your changes to topic
118    branches, merge them into "next" branch.
119
120 So, you would want to know:
121
122 (1) ... if a topic branch has ever been merged to "next".  Young
123     topic branches can have stupid mistakes you would rather
124     clean up, and things that have not been merged into other
125     branches can be easily rebased without affecting others.
126
127 (2) ... if a topic branch has been fully merged to "master".
128     Then you can delete it.  More importantly, you can tell you
129     should not build on top of it.
130
131 (3) ... if a topic branch has commits unmerged to "next".  You
132     need to merge them to test and/or publish.
133
134 Let's look at this example:
135
136                    o---o---o---o---o---o---o---o---o---o "next"
137                   /       /           /           /
138                  /   a---a---b A     /           /
139                 /   /               /           /
140                /   /   c---c---c---c B         /
141               /   /   /             \         /
142              /   /   /   b---b C     \       /
143             /   /   /   /             \     /
144     ---o---o---o---o---o---o---o---o---o---o---o "master"
145
146
147 A, B and C are topic branches.
148
149  * A has one fix since it was merged up to "next".
150
151  * B has finished.  It has been fully merged up to "master" and "next",
152    and is ready to be deleted.
153
154  * C has not merged to "next" at all.
155
156 To compute (1):
157
158         git-rev-list ^master ^topic next
159         git-rev-list ^master        next
160
161         if these match, topic has not merged in next at all.
162
163 To compute (2):
164
165         git-rev-list master..topic
166
167         if this is empty, it is fully merged to "master".
168
169 To compute (3):
170
171         git-rev-list next..topic
172
173         if this is empty, there is nothing to merge to "next".
174