4 while case $# in 0) break ;; esac
8 branch=`git symbolic-ref HEAD` &&
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"`
45 git-rev-list -1 --pretty "$topic" |
46 sed -ne 's/^Date: *\(.*\)/ (\1)/p'
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"
53 not_in_topic=`git-rev-list "^$topic" master`
54 if test -z "$not_in_topic"
58 rebase=" (can be rebased)"
64 git-rev-list ^master "$topic"
66 test -z "$not_in_master" &&
67 done="${LF}Fully merged -- delete."
71 git-rev-list --pretty=oneline ^${next} "$topic" |
72 sed -e 's/^[0-9a-f]* / - /'
74 if test -n "$not_in_next"
78 # If $topic and master are the same,
80 test "$master_sha1" = "$topic_sha1" ||
81 trouble="${LF}### MODIFIED AFTER COOKED ###"
83 not_done="${LF}Still not merged in ${next}$rebase.$LF$not_in_next"
88 not_done="${LF}Up to date."
91 echo "*** $topic ***$date$trouble$done$not_done"
93 if test -z "$trouble$not_done" &&
97 git branch -d "$topic"
103 ################################################################
106 Some important disciplines first.
108 * Once a topic branch forks from "master", never merge "master"
109 updates into the topic branch.
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.
117 * Whenever you need to test or publish your changes to topic
118 branches, merge them into "next" branch.
120 So, you would want to know:
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.
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.
131 (3) ... if a topic branch has commits unmerged to "next". You
132 need to merge them to test and/or publish.
134 Let's look at this example:
136 o---o---o---o---o---o---o---o---o---o "next"
140 / / c---c---c---c B /
144 ---o---o---o---o---o---o---o---o---o---o---o "master"
147 A, B and C are topic branches.
149 * A has one fix since it was merged up to "next".
151 * B has finished. It has been fully merged up to "master" and "next",
152 and is ready to be deleted.
154 * C has not merged to "next" at all.
158 git-rev-list ^master ^topic next
159 git-rev-list ^master next
161 if these match, topic has not merged in next at all.
165 git-rev-list master..topic
167 if this is empty, it is fully merged to "master".
171 git-rev-list next..topic
173 if this is empty, there is nothing to merge to "next".