~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/switch.py

  • Committer: Mark Hammond
  • Date: 2008-08-10 11:16:39 UTC
  • mto: (3606.5.3 1.6)
  • mto: This revision was merged to the branch mainline in revision 3626.
  • Revision ID: mhammond@skippinet.com.au-20080810111639-9upz1wig1s8lvz62
install all files with 'restartreplace uninsrestartdelete' and close
tbzrcache at uninstall time.

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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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, quiet=False, revision_id=None):
 
25
def switch(control_dir, to_branch, force=False):
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.
32
31
    """
33
32
    _check_pending_merges(control_dir, force)
34
33
    try:
37
36
        source_repository = to_branch.repository
38
37
    _set_branch_location(control_dir, to_branch, force)
39
38
    tree = control_dir.open_workingtree()
40
 
    _update(tree, source_repository, quiet, revision_id)
 
39
    _update(tree, source_repository)
41
40
 
42
41
 
43
42
def _check_pending_merges(control, force=False):
80
79
            # synchronise the local branch with the new remote branch
81
80
            # and bind to it
82
81
            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:
 
82
            if not force and _any_local_commits(b, possible_transports):
90
83
                raise errors.BzrCommandError(
91
 
                        'Unable to connect to current master branch %(target)s: '
92
 
                        '%(error)s To switch anyway, use --force.' %
93
 
                        e.__dict__)
 
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.')
94
87
            b.set_bound_location(None)
95
88
            b.pull(to_branch, overwrite=True,
96
89
                possible_transports=possible_transports)
119
112
    return False
120
113
 
121
114
 
122
 
def _update(tree, source_repository, quiet=False, revision_id=None):
 
115
def _update(tree, source_repository):
123
116
    """Update a working tree to the latest revision of its branch.
124
117
 
125
118
    :param tree: the working tree
128
121
    tree.lock_tree_write()
129
122
    try:
130
123
        to_branch = tree.branch
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())
 
124
        if tree.last_revision() == to_branch.last_revision():
 
125
            note("Tree is up to date at revision %d.", to_branch.revno())
136
126
            return
137
127
        base_tree = source_repository.revision_tree(tree.last_revision())
138
 
        merge.Merge3Merger(tree, tree, base_tree, to_branch.repository.revision_tree(revision_id))
 
128
        merge.Merge3Merger(tree, tree, base_tree, to_branch.basis_tree())
139
129
        tree.set_last_revision(to_branch.last_revision())
140
 
        if not quiet:
141
 
            note('Updated to revision %d.' % to_branch.revno())
 
130
        note('Updated to revision %d.' % to_branch.revno())
142
131
    finally:
143
132
        tree.unlock()