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