/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 breezy/switch.py

  • Committer: Jelmer Vernooij
  • Date: 2018-11-11 04:08:32 UTC
  • mto: (7143.16.20 even-more-cleanups)
  • mto: This revision was merged to the branch mainline in revision 7175.
  • Revision ID: jelmer@jelmer.uk-20181111040832-nsljjynzzwmznf3h
Run autopep8.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
from .i18n import gettext
29
29
from .trace import note
30
30
 
 
31
 
31
32
def _run_post_switch_hooks(control_dir, to_branch, force, revision_id):
32
33
    from .branch import SwitchHookParams
33
34
    hooks = Branch.hooks['post_switch']
37
38
    for hook in hooks:
38
39
        hook(params)
39
40
 
 
41
 
40
42
def switch(control_dir, to_branch, force=False, quiet=False, revision_id=None,
41
43
           store_uncommitted=False):
42
44
    """Switch the branch associated with a checkout.
62
64
    _update(tree, source_repository, quiet, revision_id, store_uncommitted)
63
65
    _run_post_switch_hooks(control_dir, to_branch, force, revision_id)
64
66
 
 
67
 
65
68
def _check_pending_merges(control, force=False):
66
69
    """Check that there are no outstanding pending merges before switching.
67
70
 
79
82
    existing_pending_merges = tree.get_parent_ids()[1:]
80
83
    if len(existing_pending_merges) > 0:
81
84
        raise errors.BzrCommandError(gettext('Pending merges must be '
82
 
            'committed or reverted before using switch.'))
 
85
                                             'committed or reverted before using switch.'))
83
86
 
84
87
 
85
88
def _set_branch_location(control, to_branch, force=False):
110
113
                        'throw them away.'))
111
114
            except errors.BoundBranchConnectionFailure as e:
112
115
                raise errors.BzrCommandError(gettext(
113
 
                        'Unable to connect to current master branch %(target)s: '
114
 
                        '%(error)s To switch anyway, use --force.') %
115
 
                        e.__dict__)
 
116
                    'Unable to connect to current master branch %(target)s: '
 
117
                    '%(error)s To switch anyway, use --force.') %
 
118
                    e.__dict__)
116
119
            b.lock_write()
117
120
            try:
118
121
                b.set_bound_location(None)
128
131
            with b.lock_read():
129
132
                graph = b.repository.get_graph(to_branch.repository)
130
133
                if (b.controldir._format.colocated_branches and
131
 
                     (force or graph.is_ancestor(b.last_revision(),
132
 
                        to_branch.last_revision()))):
 
134
                    (force or graph.is_ancestor(b.last_revision(),
 
135
                                                    to_branch.last_revision()))):
133
136
                    b.controldir.destroy_branch()
134
137
                    b.controldir.set_branch_reference(to_branch, name="")
135
138
                else:
136
139
                    raise errors.BzrCommandError(gettext('Cannot switch a branch, '
137
 
                        'only a checkout.'))
 
140
                                                         'only a checkout.'))
138
141
 
139
142
 
140
143
def _any_local_commits(this_branch, possible_transports):