~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: John Arbash Meinel
  • Date: 2011-01-25 23:21:46 UTC
  • mto: This revision was merged to the branch mainline in revision 5636.
  • Revision ID: john@arbash-meinel.com-20110125232146-axecjegxo7xwc79y
Handle --force flags and propmting the user for what they might really want.

Show diffs side-by-side

added added

removed removed

Lines of Context:
498
498
    that, you can supply --revision to force the state of the tree.
499
499
    """
500
500
 
501
 
    takes_options = ['revision']
 
501
    takes_options = ['revision', 'directory',
 
502
        Option('force',
 
503
               help='Reset the tree even if it doesn\'t appear to be'
 
504
                    ' corrupted.'),
 
505
    ]
502
506
    hidden = True
503
507
 
504
 
    def run(self, revision=None):
505
 
        pass
 
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)
506
536
 
507
537
 
508
538
class cmd_revno(Command):