~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/switch.py

  • Committer: Andrew Bennetts
  • Date: 2009-07-27 05:35:00 UTC
  • mfrom: (4570 +trunk)
  • mto: (4634.6.29 2.0)
  • mto: This revision was merged to the branch mainline in revision 4680.
  • Revision ID: andrew.bennetts@canonical.com-20090727053500-q76zsn2dx33jhmj5
Merge bzr.dev.

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):
26
26
    """Switch the branch associated with a checkout.
27
27
 
28
28
    :param control_dir: BzrDir of the checkout to change
36
36
        source_repository = to_branch.repository
37
37
    _set_branch_location(control_dir, to_branch, force)
38
38
    tree = control_dir.open_workingtree()
39
 
    _update(tree, source_repository)
 
39
    _update(tree, source_repository, quiet)
40
40
 
41
41
 
42
42
def _check_pending_merges(control, force=False):
79
79
            # synchronise the local branch with the new remote branch
80
80
            # and bind to it
81
81
            possible_transports = []
82
 
            if not force and _any_local_commits(b, possible_transports):
 
82
            try:
 
83
                if not force and _any_local_commits(b, possible_transports):
 
84
                    raise errors.BzrCommandError(
 
85
                        'Cannot switch as local commits found in the checkout. '
 
86
                        'Commit these to the bound branch or use --force to '
 
87
                        'throw them away.')
 
88
            except errors.BoundBranchConnectionFailure, e:
83
89
                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.')
 
90
                        'Unable to connect to current master branch %(target)s: '
 
91
                        '%(error)s To switch anyway, use --force.' %
 
92
                        e.__dict__)
87
93
            b.set_bound_location(None)
88
94
            b.pull(to_branch, overwrite=True,
89
95
                possible_transports=possible_transports)
112
118
    return False
113
119
 
114
120
 
115
 
def _update(tree, source_repository):
 
121
def _update(tree, source_repository, quiet=False):
116
122
    """Update a working tree to the latest revision of its branch.
117
123
 
118
124
    :param tree: the working tree
122
128
    try:
123
129
        to_branch = tree.branch
124
130
        if tree.last_revision() == to_branch.last_revision():
125
 
            note("Tree is up to date at revision %d.", to_branch.revno())
 
131
            if not quiet:
 
132
                note("Tree is up to date at revision %d.", to_branch.revno())
126
133
            return
127
134
        base_tree = source_repository.revision_tree(tree.last_revision())
128
135
        merge.Merge3Merger(tree, tree, base_tree, to_branch.basis_tree())
129
136
        tree.set_last_revision(to_branch.last_revision())
130
 
        note('Updated to revision %d.' % to_branch.revno())
 
137
        if not quiet:
 
138
            note('Updated to revision %d.' % to_branch.revno())
131
139
    finally:
132
140
        tree.unlock()