5451 experimental and backwards compatibility is not garanteed. |
5451 experimental and backwards compatibility is not garanteed. |
5452 |
5452 |
5453 Returns 0 on success, 1 if an update had unresolved files. |
5453 Returns 0 on success, 1 if an update had unresolved files. |
5454 """ |
5454 """ |
5455 |
5455 |
5456 opts = pycompat.byteskwargs(opts) |
5456 if ui.configbool(b'commands', b'update.requiredest') and opts.get('update'): |
5457 if ui.configbool(b'commands', b'update.requiredest') and opts.get( |
|
5458 b'update' |
|
5459 ): |
|
5460 msg = _(b'update destination required by configuration') |
5457 msg = _(b'update destination required by configuration') |
5461 hint = _(b'use hg pull followed by hg update DEST') |
5458 hint = _(b'use hg pull followed by hg update DEST') |
5462 raise error.InputError(msg, hint=hint) |
5459 raise error.InputError(msg, hint=hint) |
5463 |
5460 |
5464 for path in urlutil.get_pull_paths(repo, ui, sources): |
5461 for path in urlutil.get_pull_paths(repo, ui, sources): |
5465 ui.status(_(b'pulling from %s\n') % urlutil.hidepassword(path.loc)) |
5462 ui.status(_(b'pulling from %s\n') % urlutil.hidepassword(path.loc)) |
5466 ui.flush() |
5463 ui.flush() |
5467 other = hg.peer(repo, opts, path, remotehidden=opts[b'remote_hidden']) |
5464 other = hg.peer( |
|
5465 repo, |
|
5466 pycompat.byteskwargs(opts), |
|
5467 path, |
|
5468 remotehidden=opts['remote_hidden'], |
|
5469 ) |
5468 update_conflict = None |
5470 update_conflict = None |
5469 try: |
5471 try: |
5470 branches = (path.branch, opts.get(b'branch', [])) |
5472 branches = (path.branch, opts.get('branch', [])) |
5471 revs, checkout = hg.addbranchrevs( |
5473 revs, checkout = hg.addbranchrevs( |
5472 repo, |
5474 repo, |
5473 other, |
5475 other, |
5474 branches, |
5476 branches, |
5475 opts.get(b'rev'), |
5477 opts.get('rev'), |
5476 remotehidden=opts[b'remote_hidden'], |
5478 remotehidden=opts['remote_hidden'], |
5477 ) |
5479 ) |
5478 |
5480 |
5479 pullopargs = {} |
5481 pullopargs = {} |
5480 |
5482 |
5481 nodes = None |
5483 nodes = None |
5482 if opts.get(b'bookmark') or revs: |
5484 if opts.get('bookmark') or revs: |
5483 # The list of bookmark used here is the same used to actually update |
5485 # The list of bookmark used here is the same used to actually update |
5484 # the bookmark names, to avoid the race from issue 4689 and we do |
5486 # the bookmark names, to avoid the race from issue 4689 and we do |
5485 # all lookup and bookmark queries in one go so they see the same |
5487 # all lookup and bookmark queries in one go so they see the same |
5486 # version of the server state (issue 4700). |
5488 # version of the server state (issue 4700). |
5487 nodes = [] |
5489 nodes = [] |
5500 for r in revs: |
5502 for r in revs: |
5501 fnodes.append(e.callcommand(b'lookup', {b'key': r})) |
5503 fnodes.append(e.callcommand(b'lookup', {b'key': r})) |
5502 remotebookmarks = fremotebookmarks.result() |
5504 remotebookmarks = fremotebookmarks.result() |
5503 remotebookmarks = bookmarks.unhexlifybookmarks(remotebookmarks) |
5505 remotebookmarks = bookmarks.unhexlifybookmarks(remotebookmarks) |
5504 pullopargs[b'remotebookmarks'] = remotebookmarks |
5506 pullopargs[b'remotebookmarks'] = remotebookmarks |
5505 for b in opts.get(b'bookmark', []): |
5507 for b in opts.get('bookmark', []): |
5506 b = repo._bookmarks.expandname(b) |
5508 b = repo._bookmarks.expandname(b) |
5507 if b not in remotebookmarks: |
5509 if b not in remotebookmarks: |
5508 raise error.InputError( |
5510 raise error.InputError( |
5509 _(b'remote bookmark %s not found!') % b |
5511 _(b'remote bookmark %s not found!') % b |
5510 ) |
5512 ) |
5514 nodes.append(node) |
5516 nodes.append(node) |
5515 if rev == checkout: |
5517 if rev == checkout: |
5516 checkout = node |
5518 checkout = node |
5517 |
5519 |
5518 wlock = util.nullcontextmanager() |
5520 wlock = util.nullcontextmanager() |
5519 if opts.get(b'update'): |
5521 if opts.get('update'): |
5520 wlock = repo.wlock() |
5522 wlock = repo.wlock() |
5521 with wlock: |
5523 with wlock: |
5522 pullopargs.update(opts.get(b'opargs', {})) |
5524 pullopargs.update(opts.get('opargs', {})) |
5523 modheads = exchange.pull( |
5525 modheads = exchange.pull( |
5524 repo, |
5526 repo, |
5525 other, |
5527 other, |
5526 path=path, |
5528 path=path, |
5527 heads=nodes, |
5529 heads=nodes, |
5528 force=opts.get(b'force'), |
5530 force=opts.get('force'), |
5529 bookmarks=opts.get(b'bookmark', ()), |
5531 bookmarks=opts.get('bookmark', ()), |
5530 opargs=pullopargs, |
5532 opargs=pullopargs, |
5531 confirm=opts.get(b'confirm'), |
5533 confirm=opts.get('confirm'), |
5532 ).cgresult |
5534 ).cgresult |
5533 |
5535 |
5534 # brev is a name, which might be a bookmark to be activated at |
5536 # brev is a name, which might be a bookmark to be activated at |
5535 # the end of the update. In other words, it is an explicit |
5537 # the end of the update. In other words, it is an explicit |
5536 # destination of the update |
5538 # destination of the update |
5540 checkout = repo.unfiltered().changelog.rev(checkout) |
5542 checkout = repo.unfiltered().changelog.rev(checkout) |
5541 |
5543 |
5542 # order below depends on implementation of |
5544 # order below depends on implementation of |
5543 # hg.addbranchrevs(). opts['bookmark'] is ignored, |
5545 # hg.addbranchrevs(). opts['bookmark'] is ignored, |
5544 # because 'checkout' is determined without it. |
5546 # because 'checkout' is determined without it. |
5545 if opts.get(b'rev'): |
5547 if opts.get('rev'): |
5546 brev = opts[b'rev'][0] |
5548 brev = opts['rev'][0] |
5547 elif opts.get(b'branch'): |
5549 elif opts.get('branch'): |
5548 brev = opts[b'branch'][0] |
5550 brev = opts['branch'][0] |
5549 else: |
5551 else: |
5550 brev = path.branch |
5552 brev = path.branch |
5551 |
5553 |
5552 # XXX path: we are losing the `path` object here. Keeping it |
5554 # XXX path: we are losing the `path` object here. Keeping it |
5553 # would be valuable. For example as a "variant" as we do |
5555 # would be valuable. For example as a "variant" as we do |
5554 # for pushes. |
5556 # for pushes. |
5555 repo._subtoppath = path.loc |
5557 repo._subtoppath = path.loc |
5556 try: |
5558 try: |
5557 update_conflict = postincoming( |
5559 update_conflict = postincoming( |
5558 ui, repo, modheads, opts.get(b'update'), checkout, brev |
5560 ui, repo, modheads, opts.get('update'), checkout, brev |
5559 ) |
5561 ) |
5560 except error.FilteredRepoLookupError as exc: |
5562 except error.FilteredRepoLookupError as exc: |
5561 msg = _(b'cannot update to target: %s') % exc.args[0] |
5563 msg = _(b'cannot update to target: %s') % exc.args[0] |
5562 exc.args = (msg,) + exc.args[1:] |
5564 exc.args = (msg,) + exc.args[1:] |
5563 raise |
5565 raise |