~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: Patch Queue Manager
  • Date: 2012-03-06 17:43:02 UTC
  • mfrom: (6437.41.4 rmbranch-active)
  • Revision ID: pqm@pqm.ubuntu.com-20120306174302-b6y3hyh1yfnutk9o
(jelmer) Require --force to remove active branches in 'bzr rmbranch'.
 (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
6458
6458
 
6459
6459
    takes_args = ["location?"]
6460
6460
 
6461
 
    takes_options = ['directory']
 
6461
    takes_options = ['directory',
 
6462
        Option('force', help='Remove branch even if it is the active branch.')]
6462
6463
 
6463
6464
    aliases = ["rmbranch"]
6464
6465
 
6465
 
    def run(self, directory=None, location=None):
 
6466
    def run(self, directory=None, location=None, force=False):
6466
6467
        br = open_nearby_branch(near=directory, location=location)
 
6468
        if not force and br.bzrdir.has_workingtree():
 
6469
            try:
 
6470
                active_branch = br.bzrdir.open_branch(name="")
 
6471
            except errors.NotBranchError:
 
6472
                active_branch = None
 
6473
            if (active_branch is not None and
 
6474
                br.control_url == active_branch.control_url):
 
6475
                raise errors.BzrCommandError(
 
6476
                    gettext("Branch is active. Use --force to remove it."))
6467
6477
        br.bzrdir.destroy_branch(br.name)
6468
6478
 
6469
6479