~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/switch.py

  • Committer: Vincent Ladeuil
  • Date: 2010-02-10 15:46:03 UTC
  • mfrom: (4985.3.21 update)
  • mto: This revision was merged to the branch mainline in revision 5021.
  • Revision ID: v.ladeuil+lp@free.fr-20100210154603-k4no1gvfuqpzrw7p
Update performs two merges in a more logical order but stop on conflicts

Show diffs side-by-side

added added

removed removed

Lines of Context:
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()