Mercurial > public > mercurial-scm > hg
comparison mercurial/commands.py @ 16708:4a02cf4fbb2e
merge: respect bookmarks during merge
Bookmarks will behave more like named branches when merge tries to pick
a revision to merge.
Bookmarks now to respect the current bookmarks. Bookmarks will not
accidentally merged with unnamed heads or other bookmarks. However merge
can pick heads with diverging bookmarks and pick those automatically.
We end up with two cases for picking a revision to merge:
(1) In case of an current bookmark, merge can pick a branch head that has a
diverged bookmark
(2) In case of no current bookmark, merge can pick a branch head that does not
have a bookmark.
author | David Soria Parra <dsp@php.net> |
---|---|
date | Sun, 13 May 2012 11:55:42 +0200 |
parents | c2d9ef43ff6c |
children | 497deec204d1 |
comparison
equal
deleted
inserted
replaced
16707:f8dee1a8f844 | 16708:4a02cf4fbb2e |
---|---|
4166 if opts.get('rev') and node: | 4166 if opts.get('rev') and node: |
4167 raise util.Abort(_("please specify just one revision")) | 4167 raise util.Abort(_("please specify just one revision")) |
4168 if not node: | 4168 if not node: |
4169 node = opts.get('rev') | 4169 node = opts.get('rev') |
4170 | 4170 |
4171 if not node: | 4171 if node: |
4172 node = scmutil.revsingle(repo, node).node() | |
4173 | |
4174 if not node and repo._bookmarkcurrent: | |
4175 bmheads = repo.bookmarkheads(repo._bookmarkcurrent) | |
4176 curhead = repo[repo._bookmarkcurrent] | |
4177 if len(bmheads) == 2: | |
4178 if curhead == bmheads[0]: | |
4179 node = bmheads[1] | |
4180 else: | |
4181 node = bmheads[0] | |
4182 elif len(bmheads) > 2: | |
4183 raise util.Abort(_("multiple matching bookmarks to merge - " | |
4184 "please merge with an explicit rev or bookmark"), | |
4185 hint=_("run 'hg heads' to see all heads")) | |
4186 elif len(bmheads) <= 1: | |
4187 raise util.Abort(_("no matching bookmark to merge - " | |
4188 "please merge with an explicit rev or bookmark"), | |
4189 hint=_("run 'hg heads' to see all heads")) | |
4190 | |
4191 if not node and not repo._bookmarkcurrent: | |
4172 branch = repo[None].branch() | 4192 branch = repo[None].branch() |
4173 bheads = repo.branchheads(branch) | 4193 bheads = repo.branchheads(branch) |
4174 if len(bheads) > 2: | 4194 nbhs = [bh for bh in bheads if not repo[bh].bookmarks()] |
4195 | |
4196 if len(nbhs) > 2: | |
4175 raise util.Abort(_("branch '%s' has %d heads - " | 4197 raise util.Abort(_("branch '%s' has %d heads - " |
4176 "please merge with an explicit rev") | 4198 "please merge with an explicit rev") |
4177 % (branch, len(bheads)), | 4199 % (branch, len(bheads)), |
4178 hint=_("run 'hg heads .' to see heads")) | 4200 hint=_("run 'hg heads .' to see heads")) |
4179 | 4201 |
4180 parent = repo.dirstate.p1() | 4202 parent = repo.dirstate.p1() |
4181 if len(bheads) == 1: | 4203 if len(nbhs) == 1: |
4204 if len(bheads) > 1: | |
4205 raise util.Abort(_("heads are bookmarked - " | |
4206 "please merge with an explicit rev"), | |
4207 hint=_("run 'hg heads' to see all heads")) | |
4182 if len(repo.heads()) > 1: | 4208 if len(repo.heads()) > 1: |
4183 raise util.Abort(_("branch '%s' has one head - " | 4209 raise util.Abort(_("branch '%s' has one head - " |
4184 "please merge with an explicit rev") | 4210 "please merge with an explicit rev") |
4185 % branch, | 4211 % branch, |
4186 hint=_("run 'hg heads' to see all heads")) | 4212 hint=_("run 'hg heads' to see all heads")) |
4191 | 4217 |
4192 if parent not in bheads: | 4218 if parent not in bheads: |
4193 raise util.Abort(_('working directory not at a head revision'), | 4219 raise util.Abort(_('working directory not at a head revision'), |
4194 hint=_("use 'hg update' or merge with an " | 4220 hint=_("use 'hg update' or merge with an " |
4195 "explicit revision")) | 4221 "explicit revision")) |
4196 node = parent == bheads[0] and bheads[-1] or bheads[0] | 4222 if parent == nbhs[0]: |
4197 else: | 4223 node = nbhs[-1] |
4198 node = scmutil.revsingle(repo, node).node() | 4224 else: |
4225 node = nbhs[0] | |
4199 | 4226 |
4200 if opts.get('preview'): | 4227 if opts.get('preview'): |
4201 # find nodes that are ancestors of p2 but not of p1 | 4228 # find nodes that are ancestors of p2 but not of p1 |
4202 p1 = repo.lookup('.') | 4229 p1 = repo.lookup('.') |
4203 p2 = repo.lookup(node) | 4230 p2 = repo.lookup(node) |