4 branch=`git symbolic-ref HEAD`
5 while case $# in 0) break ;; esac
9 test refs/heads/master = "$branch" || {
10 echo >&2 Not on master
17 echo >&2 "Need argument"
21 git rev-parse --verify "$next" >/dev/null || exit
25 echo >&2 "$0 [--clean | --next test-next ]"
32 master_sha1=`git rev-parse --verify refs/heads/master`
35 (cd .git/refs/heads && find -type f) |
38 -e '/^[^\/][^\/]\//p' |
41 rebase= done= not_done= trouble= date=
42 topic_sha1=`git rev-parse --verify "refs/heads/$topic"`
44 if test "refs/heads/$topic" = "$branch"
50 git-rev-list -1 --pretty "$topic" |
51 sed -ne 's/^Date: *\(.*\)/ (\1)/p'
54 only_next_1=`git-rev-list ^master "^$topic" ${next} | sort`
55 only_next_2=`git-rev-list ^master ${next} | sort`
56 if test "$only_next_1" = "$only_next_2"
58 not_in_topic=`git-rev-list "^$topic" master`
59 if test -z "$not_in_topic"
63 rebase=" (can be rebased)"
69 git-rev-list ^master "$topic"
71 test -z "$not_in_master" &&
72 done="${LF}Fully merged -- delete."
76 git-rev-list --pretty=oneline ^${next} "$topic" |
77 sed -e 's/^[0-9a-f]* / - /'
79 if test -n "$not_in_next"
83 # If $topic and master are the same,
85 test "$master_sha1" = "$topic_sha1" ||
86 trouble="${LF}### MODIFIED AFTER COOKED ###"
88 not_done="${LF}Still not merged in ${next}$rebase.$LF$not_in_next"
93 not_done="${LF}Up to date."
96 echo "*** $topic ***$date$is_current$trouble$done$not_done"
98 if test -z "$trouble$not_done" &&
102 git branch -d "$topic"
108 ################################################################
111 Some important disciplines first.
113 * Once a topic branch forks from "master", never merge "master"
114 updates into the topic branch.
116 * Once a topic branch is fully cooked and merged into "master",
117 delete it. If you need to build on top of it to correct
118 earlier mistakes, create a new topic branch by forking at the
119 tip of the "master". This is not strictly necessary, but it
120 makes it easier to keep your history simple.
122 * Whenever you need to test or publish your changes to topic
123 branches, merge them into "next" branch.
125 So, you would want to know:
127 (1) ... if a topic branch has ever been merged to "next". Young
128 topic branches can have stupid mistakes you would rather
129 clean up, and things that have not been merged into other
130 branches can be easily rebased without affecting others.
132 (2) ... if a topic branch has been fully merged to "master".
133 Then you can delete it. More importantly, you can tell you
134 should not build on top of it.
136 (3) ... if a topic branch has commits unmerged to "next". You
137 need to merge them to test and/or publish.
139 Let's look at this example:
141 o---o---o---o---o---o---o---o---o---o "next"
145 / / c---c---c---c B /
149 ---o---o---o---o---o---o---o---o---o---o---o "master"
152 A, B and C are topic branches.
154 * A has one fix since it was merged up to "next".
156 * B has finished. It has been fully merged up to "master" and "next",
157 and is ready to be deleted.
159 * C has not merged to "next" at all.
163 git-rev-list ^master ^topic next
164 git-rev-list ^master next
166 if these match, topic has not merged in next at all.
170 git-rev-list master..topic
172 if this is empty, it is fully merged to "master".
176 git-rev-list next..topic
178 if this is empty, there is nothing to merge to "next".