comparison mercurial/merge.py @ 6375:cdc458b12f0f

update: better logic and messages for updates - complain about attempts to merge with ancestor - when updating, differentiate between - crossing named branches with no local changes (jump) - crossing named branches with local changes (complain) - nonlinear update on the same named branch, no changes (complain some more) - nonlinear update on the same named branch, changes (different complaining)
author Matt Mackall <mpm@selenic.com>
date Mon, 24 Mar 2008 10:01:05 -0500
parents 6aa4a3fa4e60
children 0b89315d5de2
comparison
equal deleted inserted replaced
6374:31a01e3d99cc 6375:cdc458b12f0f
344 if wc.branch() == "default": # no default branch! 344 if wc.branch() == "default": # no default branch!
345 node = repo.lookup("tip") # update to tip 345 node = repo.lookup("tip") # update to tip
346 else: 346 else:
347 raise util.Abort(_("branch %s not found") % wc.branch()) 347 raise util.Abort(_("branch %s not found") % wc.branch())
348 overwrite = force and not branchmerge 348 overwrite = force and not branchmerge
349 forcemerge = force and branchmerge
350 pl = wc.parents() 349 pl = wc.parents()
351 p1, p2 = pl[0], repo.changectx(node) 350 p1, p2 = pl[0], repo.changectx(node)
352 pa = p1.ancestor(p2) 351 pa = p1.ancestor(p2)
353 fp1, fp2, xp1, xp2 = p1.node(), p2.node(), str(p1), str(p2) 352 fp1, fp2, xp1, xp2 = p1.node(), p2.node(), str(p1), str(p2)
354 fastforward = False 353 fastforward = False
355 354
356 ### check phase 355 ### check phase
357 if not overwrite and len(pl) > 1: 356 if not overwrite and len(pl) > 1:
358 raise util.Abort(_("outstanding uncommitted merges")) 357 raise util.Abort(_("outstanding uncommitted merges"))
359 if pa == p1 or pa == p2: # is there a linear path from p1 to p2? 358 if branchmerge:
360 if branchmerge: 359 if pa == p2:
361 if p1.branch() != p2.branch() and pa != p2: 360 raise util.Abort(_("can't merge with ancestor"))
361 elif pa == p1:
362 if p1.branch() != p2.branch():
362 fastforward = True 363 fastforward = True
363 else: 364 else:
364 raise util.Abort(_("there is nothing to merge, just use " 365 raise util.Abort(_("nothing to merge (use 'hg update'"
365 "'hg update' or look at 'hg heads'")) 366 " or check 'hg heads')"))
366 elif not (overwrite or branchmerge): 367 if not force and (wc.files() or wc.deleted()):
367 if wc.files() or wc.deleted():
368 raise util.Abort(_("update spans branches, use 'hg merge' "
369 "or 'hg update -C' to lose changes"))
370 # Allow jumping branches if there are no changes
371 overwrite = True
372 if branchmerge and not forcemerge:
373 if wc.files() or wc.deleted():
374 raise util.Abort(_("outstanding uncommitted changes")) 368 raise util.Abort(_("outstanding uncommitted changes"))
369 elif not overwrite:
370 if pa == p1 or pa == p2: # linear
371 pass # all good
372 elif p1.branch() == p2.branch():
373 if wc.files() or wc.deleted():
374 raise util.Abort(_("crosses branches (use 'hg merge' or "
375 "'hg update -C' to discard changes)"))
376 raise util.Abort(_("crosses branches (use 'hg merge'"
377 "or 'hg update -C')"))
378 elif wc.files() or wc.deleted():
379 raise util.Abort(_("crosses named branches (use "
380 "'hg update -C' to discard changes)"))
381 else:
382 # Allow jumping branches if there are no changes
383 overwrite = True
375 384
376 ### calculate phase 385 ### calculate phase
377 action = [] 386 action = []
378 if not force: 387 if not force:
379 _checkunknown(wc, p2) 388 _checkunknown(wc, p2)