~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

(gz) Backport fixes to rmbranch on colocated branches from 2.6 (Martin
 Packman)

Show diffs side-by-side

added added

removed removed

Lines of Context:
149
149
    return location
150
150
 
151
151
 
152
 
def lookup_sibling_branch(control_dir, location, possible_transports=None):
153
 
    """Lookup sibling branch.
154
 
    
 
152
def open_sibling_branch(control_dir, location, possible_transports=None):
 
153
    """Open a branch, possibly a sibling.
 
154
 
155
155
    :param control_dir: Control directory relative to which to lookup the
156
156
        location.
157
157
    :param location: Location to look up
162
162
        return control_dir.open_branch(location, 
163
163
            possible_transports=possible_transports)
164
164
    except (errors.NotBranchError, errors.NoColocatedBranchSupport):
 
165
        this_url = _get_branch_location(control_dir)
 
166
        return Branch.open(
 
167
            urlutils.join(
 
168
                this_url, '..', urlutils.escape(location)))
 
169
 
 
170
 
 
171
def open_nearby_branch(near=None, location=None, possible_transports=None):
 
172
    """Open a nearby branch.
 
173
 
 
174
    :param near: Optional location of container from which to open branch
 
175
    :param location: Location of the branch
 
176
    :return: Branch instance
 
177
    """
 
178
    if near is None:
 
179
        if location is None:
 
180
            location = "."
165
181
        try:
166
 
            return Branch.open(location)
 
182
            return Branch.open(location,
 
183
                possible_transports=possible_transports)
167
184
        except errors.NotBranchError:
168
 
            this_url = _get_branch_location(control_dir)
169
 
            return Branch.open(
170
 
                urlutils.join(
171
 
                    this_url, '..', urlutils.escape(location)))
 
185
            near = "."
 
186
    cdir = controldir.ControlDir.open(near,
 
187
        possible_transports=possible_transports)
 
188
    return open_sibling_branch(cdir, location,
 
189
        possible_transports=possible_transports)
172
190
 
173
191
 
174
192
@symbol_versioning.deprecated_function(symbol_versioning.deprecated_in((2, 3, 0)))
6247
6265
                 possible_transports=possible_transports,
6248
6266
                 source_branch=branch).open_branch()
6249
6267
        else:
6250
 
            to_branch = lookup_sibling_branch(control_dir, to_location)
 
6268
            try:
 
6269
                to_branch = Branch.open(to_location,
 
6270
                    possible_transports=possible_transports)
 
6271
            except errors.NotBranchError:
 
6272
                to_branch = open_sibling_branch(control_dir, to_location,
 
6273
                    possible_transports=possible_transports)
6251
6274
        if revision is not None:
6252
6275
            revision = revision.as_revision_id(to_branch)
6253
6276
        switch.switch(control_dir, to_branch, force, revision_id=revision)
6450
6473
 
6451
6474
    takes_args = ["location?"]
6452
6475
 
 
6476
    takes_options = ['directory',
 
6477
        Option('force', help='Remove branch even if it is the active branch.')]
 
6478
 
6453
6479
    aliases = ["rmbranch"]
6454
6480
 
6455
 
    def run(self, location=None):
6456
 
        if location is None:
6457
 
            location = "."
6458
 
        cdir = controldir.ControlDir.open_containing(location)[0]
6459
 
        cdir.destroy_branch()
 
6481
    def run(self, directory=None, location=None, force=False):
 
6482
        br = open_nearby_branch(near=directory, location=location)
 
6483
        if not force and br.bzrdir.has_workingtree():
 
6484
            try:
 
6485
                active_branch = br.bzrdir.open_branch(name="")
 
6486
            except errors.NotBranchError:
 
6487
                active_branch = None
 
6488
            if (active_branch is not None and
 
6489
                br.control_url == active_branch.control_url):
 
6490
                raise errors.BzrCommandError(
 
6491
                    gettext("Branch is active. Use --force to remove it."))
 
6492
        br.bzrdir.destroy_branch(br.name)
6460
6493
 
6461
6494
 
6462
6495
class cmd_shelve(Command):