~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/switch.py

Fix #531967 by creating helpers for PathConflicts when a deletion
is involved.

* bzrlib/tests/test_conflicts.py:
(TestParametrizedResolveConflicts.mirror_scenarios): Renamed from
multiply_scenarios to make the intent clearer. Turned into a
classmethod too for the same reason.
(TestParametrizedResolveConflicts.scenarios): Now a classmethod.

* bzrlib/merge.py:
(Merge3Merger._merge_names): 'name conflict' and 'parent conflict'
can (and must) be handled in the same way. If a deletion is
involved we create an unversioned copy of the rejected item so the
user can restore that easily.
(Merge3Merger.cook_conflicts): Get rid of 'name conflict', 'parent
conflict' distinction and just create PathConflicts with a file_id
to address bug #531967.

* bzrlib/conflicts.py:
(PathConflict.associated_filenames): Helpers exist only when a
deletion is involved.
(PathConflict._resolve): We may have to version one path
again. This may happen when a deletion have occurred.
(PathConflict.action_take_this, PathConflict.action_take_other):
As a special case, we may have an helper to use when deletion was
involved.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006, 2007 Canonical Ltd.
 
1
# Copyright (C) 2007, 2009, 2010 Canonical Ltd.
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
# Original author: David Allouche
18
18
 
22
22
from bzrlib.trace import note
23
23
 
24
24
 
25
 
def switch(control_dir, to_branch, force=False):
 
25
def switch(control_dir, to_branch, force=False, quiet=False, revision_id=None):
26
26
    """Switch the branch associated with a checkout.
27
27
 
28
28
    :param control_dir: BzrDir of the checkout to change
29
29
    :param to_branch: branch that the checkout is to reference
30
30
    :param force: skip the check for local commits in a heavy checkout
 
31
    :param revision_id: revision ID to switch to.
31
32
    """
32
33
    _check_pending_merges(control_dir, force)
33
34
    try:
36
37
        source_repository = to_branch.repository
37
38
    _set_branch_location(control_dir, to_branch, force)
38
39
    tree = control_dir.open_workingtree()
39
 
    _update(tree, source_repository)
 
40
    _update(tree, source_repository, quiet, revision_id)
40
41
 
41
42
 
42
43
def _check_pending_merges(control, force=False):
79
80
            # synchronise the local branch with the new remote branch
80
81
            # and bind to it
81
82
            possible_transports = []
82
 
            if not force and _any_local_commits(b, possible_transports):
 
83
            try:
 
84
                if not force and _any_local_commits(b, possible_transports):
 
85
                    raise errors.BzrCommandError(
 
86
                        'Cannot switch as local commits found in the checkout. '
 
87
                        'Commit these to the bound branch or use --force to '
 
88
                        'throw them away.')
 
89
            except errors.BoundBranchConnectionFailure, e:
83
90
                raise errors.BzrCommandError(
84
 
                    'Cannot switch as local commits found in the checkout. '
85
 
                    'Commit these to the bound branch or use --force to '
86
 
                    'throw them away.')
 
91
                        'Unable to connect to current master branch %(target)s: '
 
92
                        '%(error)s To switch anyway, use --force.' %
 
93
                        e.__dict__)
87
94
            b.set_bound_location(None)
88
95
            b.pull(to_branch, overwrite=True,
89
96
                possible_transports=possible_transports)
112
119
    return False
113
120
 
114
121
 
115
 
def _update(tree, source_repository):
 
122
def _update(tree, source_repository, quiet=False, revision_id=None):
116
123
    """Update a working tree to the latest revision of its branch.
117
124
 
118
125
    :param tree: the working tree
121
128
    tree.lock_tree_write()
122
129
    try:
123
130
        to_branch = tree.branch
124
 
        if tree.last_revision() == to_branch.last_revision():
125
 
            note("Tree is up to date at revision %d.", to_branch.revno())
 
131
        if revision_id is None:
 
132
            revision_id = to_branch.last_revision()
 
133
        if tree.last_revision() == revision_id:
 
134
            if not quiet:
 
135
                note("Tree is up to date at revision %d.", to_branch.revno())
126
136
            return
127
137
        base_tree = source_repository.revision_tree(tree.last_revision())
128
 
        merge.Merge3Merger(tree, tree, base_tree, to_branch.basis_tree())
 
138
        merge.Merge3Merger(tree, tree, base_tree, to_branch.repository.revision_tree(revision_id))
129
139
        tree.set_last_revision(to_branch.last_revision())
130
 
        note('Updated to revision %d.' % to_branch.revno())
 
140
        if not quiet:
 
141
            note('Updated to revision %d.' % to_branch.revno())
131
142
    finally:
132
143
        tree.unlock()