/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2011-01-27 17:45:24 UTC
  • mfrom: (5630.2.8 2.4-reset-checkout)
  • Revision ID: pqm@pqm.ubuntu.com-20110127174524-89zg98o11grbj26x
(jameinel) Add 'bzr reset-workingtree' as a way to fix a corrupted dirstate
 file. (John A Meinel)

Show diffs side-by-side

added added

removed removed

Lines of Context:
482
482
            d.destroy_workingtree()
483
483
 
484
484
 
 
485
class cmd_repair_workingtree(Command):
 
486
    __doc__ = """Reset the working tree state file.
 
487
 
 
488
    This is not meant to be used normally, but more as a way to recover from
 
489
    filesystem corruption, etc. This rebuilds the working inventory back to a
 
490
    'known good' state. Any new modifications (adding a file, renaming, etc)
 
491
    will be lost, though modified files will still be detected as such.
 
492
 
 
493
    Most users will want something more like "bzr revert" or "bzr update"
 
494
    unless the state file has become corrupted.
 
495
 
 
496
    By default this attempts to recover the current state by looking at the
 
497
    headers of the state file. If the state file is too corrupted to even do
 
498
    that, you can supply --revision to force the state of the tree.
 
499
    """
 
500
 
 
501
    takes_options = ['revision', 'directory',
 
502
        Option('force',
 
503
               help='Reset the tree even if it doesn\'t appear to be'
 
504
                    ' corrupted.'),
 
505
    ]
 
506
    hidden = True
 
507
 
 
508
    def run(self, revision=None, directory='.', force=False):
 
509
        tree, _ = WorkingTree.open_containing(directory)
 
510
        self.add_cleanup(tree.lock_tree_write().unlock)
 
511
        if not force:
 
512
            try:
 
513
                tree.check_state()
 
514
            except errors.BzrError:
 
515
                pass # There seems to be a real error here, so we'll reset
 
516
            else:
 
517
                # Refuse
 
518
                raise errors.BzrCommandError(
 
519
                    'The tree does not appear to be corrupt. You probably'
 
520
                    ' want "bzr revert" instead. Use "--force" if you are'
 
521
                    ' sure you want to reset the working tree.')
 
522
        if revision is None:
 
523
            revision_ids = None
 
524
        else:
 
525
            revision_ids = [r.as_revision_id(tree.branch) for r in revision]
 
526
        try:
 
527
            tree.reset_state(revision_ids)
 
528
        except errors.BzrError, e:
 
529
            if revision_ids is None:
 
530
                extra = (', the header appears corrupt, try passing -r -1'
 
531
                         ' to set the state to the last commit')
 
532
            else:
 
533
                extra = ''
 
534
            raise errors.BzrCommandError('failed to reset the tree state'
 
535
                                         + extra)
 
536
 
 
537
 
485
538
class cmd_revno(Command):
486
539
    __doc__ = """Show current revision number.
487
540