197 branch = repo.dirstate.branch() |
197 branch = repo.dirstate.branch() |
198 bheads = repo.branchheads(branch) |
198 bheads = repo.branchheads(branch) |
199 nbhs = [bh for bh in bheads if not repo[bh].bookmarks()] |
199 nbhs = [bh for bh in bheads if not repo[bh].bookmarks()] |
200 |
200 |
201 if parent not in bheads: |
201 if parent not in bheads: |
|
202 # Case A: working copy if not on a head. |
|
203 # |
|
204 # This is probably a user mistake We bailout pointing at 'hg update' |
202 if len(repo.heads()) <= 1: |
205 if len(repo.heads()) <= 1: |
203 msg, hint = msgdestmerge['nootherheadsbehind'] |
206 msg, hint = msgdestmerge['nootherheadsbehind'] |
204 else: |
207 else: |
205 msg, hint = msgdestmerge['notatheads'] |
208 msg, hint = msgdestmerge['notatheads'] |
206 raise error.Abort(msg, hint=hint) |
209 raise error.Abort(msg, hint=hint) |
207 |
210 elif len(nbhs) > 2: |
208 if len(nbhs) > 2: |
211 # Case B: There is more than 2 anonymous heads |
|
212 # |
|
213 # This means that there will be more than 1 candidate. This is |
|
214 # ambiguous. We abort asking the user to pick as explicit destination |
|
215 # instead. |
209 msg, hint = msgdestmerge['toomanyheads'] |
216 msg, hint = msgdestmerge['toomanyheads'] |
210 msg %= (branch, len(bheads)) |
217 msg %= (branch, len(bheads)) |
211 raise error.Abort(msg, hint=hint) |
218 raise error.Abort(msg, hint=hint) |
212 |
219 elif len(nbhs) <= 1: |
213 if len(nbhs) <= 1: |
220 # Case B: There is no other anonymous head that the one we are one |
|
221 # |
|
222 # This means that there is no natural candidate to merge with. |
|
223 # We abort, with various messages for various cases. |
214 if len(bheads) > 1: |
224 if len(bheads) > 1: |
215 msg, hint = msgdestmerge['bookmarkedheads'] |
225 msg, hint = msgdestmerge['bookmarkedheads'] |
216 elif len(repo.heads()) > 1: |
226 elif len(repo.heads()) > 1: |
217 msg, hint = msgdestmerge['nootherbranchheads'] |
227 msg, hint = msgdestmerge['nootherbranchheads'] |
218 msg %= branch |
228 msg %= branch |
219 else: |
229 else: |
220 msg, hint = msgdestmerge['nootherheads'] |
230 msg, hint = msgdestmerge['nootherheads'] |
221 raise error.Abort(msg, hint=hint) |
231 raise error.Abort(msg, hint=hint) |
222 |
232 elif parent == nbhs[0]: |
223 if parent == nbhs[0]: |
|
224 node = nbhs[-1] |
233 node = nbhs[-1] |
225 else: |
234 else: |
226 node = nbhs[0] |
235 node = nbhs[0] |
227 assert node is not None |
236 assert node is not None |
228 return node |
237 return node |