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