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' |
42 rebase= done= not_done= trouble= date=
43 topic_sha1=`git rev-parse --verify "refs/heads/$topic"`
45 if test "refs/heads/$topic" = "$branch"
51 git-rev-list -1 --pretty "$topic" |
52 sed -ne 's/^Date: *\(.*\)/ (\1)/p'
55 only_next_1=`git-rev-list ^master "^$topic" ${next} | sort`
56 only_next_2=`git-rev-list ^master ${next} | sort`
57 if test "$only_next_1" = "$only_next_2"
59 not_in_topic=`git-rev-list "^$topic" master`
60 if test -z "$not_in_topic"
64 rebase=" (can be rebased)"
70 git-rev-list ^master "$topic"
72 test -z "$not_in_master" &&
73 done="${LF}Fully merged -- delete."
77 git-rev-list --pretty=oneline ^${next} "$topic" |
78 sed -e 's/^[0-9a-f]* / - /'
80 if test -n "$not_in_next"
84 # If $topic and master are the same,
86 test "$master_sha1" = "$topic_sha1" ||
87 trouble="${LF}### MODIFIED AFTER COOKED ###"
89 not_done="${LF}Still not merged in ${next}$rebase.$LF$not_in_next"
94 not_done="${LF}Up to date."
97 echo "*** $topic ***$date$is_current$trouble$done$not_done"
99 if test -z "$trouble$not_done" &&
103 git branch -d "$topic"
109 ################################################################
112 Some important disciplines first.
114 * Once a topic branch forks from "master", never merge "master"
115 updates into the topic branch.
117 * Once a topic branch is fully cooked and merged into "master",
118 delete it. If you need to build on top of it to correct
119 earlier mistakes, create a new topic branch by forking at the
120 tip of the "master". This is not strictly necessary, but it
121 makes it easier to keep your history simple.
123 * Whenever you need to test or publish your changes to topic
124 branches, merge them into "next" branch.
126 So, you would want to know:
128 (1) ... if a topic branch has ever been merged to "next". Young
129 topic branches can have stupid mistakes you would rather
130 clean up, and things that have not been merged into other
131 branches can be easily rebased without affecting others.
133 (2) ... if a topic branch has been fully merged to "master".
134 Then you can delete it. More importantly, you can tell you
135 should not build on top of it.
137 (3) ... if a topic branch has commits unmerged to "next". You
138 need to merge them to test and/or publish.
140 Let's look at this example:
142 o---o---o---o---o---o---o---o---o---o "next"
146 / / c---c---c---c B /
150 ---o---o---o---o---o---o---o---o---o---o---o "master"
153 A, B and C are topic branches.
155 * A has one fix since it was merged up to "next".
157 * B has finished. It has been fully merged up to "master" and "next",
158 and is ready to be deleted.
160 * C has not merged to "next" at all.
164 git-rev-list ^master ^topic next
165 git-rev-list ^master next
167 if these match, topic has not merged in next at all.
171 git-rev-list master..topic
173 if this is empty, it is fully merged to "master".
177 git-rev-list next..topic
179 if this is empty, there is nothing to merge to "next".