~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_switch.py

  • Committer: Martin Pool
  • Date: 2010-01-29 14:09:05 UTC
  • mto: This revision was merged to the branch mainline in revision 4992.
  • Revision ID: mbp@sourcefrog.net-20100129140905-2uiarb6p8di1ywsr
Correction to url

from review: https://code.edge.launchpad.net/~mbp/bzr/doc/+merge/18250

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007-2010 Canonical Ltd
 
1
# Copyright (C) 2007, 2008, 2009 Canonical Ltd
2
2
# -*- coding: utf-8 -*-
3
3
#
4
4
# This program is free software; you can redistribute it and/or modify
20
20
 
21
21
import os
22
22
 
23
 
from bzrlib import osutils
24
23
from bzrlib.workingtree import WorkingTree
25
 
from bzrlib.tests import TestCaseWithTransport
 
24
from bzrlib.tests.blackbox import ExternalBase
26
25
from bzrlib.directory_service import directories
27
26
 
28
27
 
29
 
class TestSwitch(TestCaseWithTransport):
 
28
class TestSwitch(ExternalBase):
30
29
 
31
30
    def _create_sample_tree(self):
32
31
        tree = self.make_branch_and_tree('branch-1')
168
167
    def prepare_lightweight_switch(self):
169
168
        branch = self.make_branch('branch')
170
169
        branch.create_checkout('tree', lightweight=True)
171
 
        osutils.rename('branch', 'branch1')
 
170
        os.rename('branch', 'branch1')
172
171
 
173
172
    def test_switch_lightweight_after_branch_moved(self):
174
173
        self.prepare_lightweight_switch()
226
225
        self.run_bzr('switch -b foo:branch2', working_dir='tree')
227
226
        tree = WorkingTree.open('tree')
228
227
        self.assertEndsWith(tree.branch.base, 'foo-branch2/')
229
 
 
230
 
    def test_switch_with_post_switch_hook(self):
231
 
        from bzrlib import branch as _mod_branch
232
 
        calls = []
233
 
        _mod_branch.Branch.hooks.install_named_hook('post_switch',
234
 
            calls.append, None)
235
 
        self.make_branch_and_tree('branch')
236
 
        self.run_bzr('branch branch branch2')
237
 
        self.run_bzr('checkout branch checkout')
238
 
        os.chdir('checkout')
239
 
        self.assertLength(0, calls)
240
 
        out, err = self.run_bzr('switch ../branch2')
241
 
        self.assertLength(1, calls)
242
 
 
243
 
    def test_switch_lightweight_co_with_post_switch_hook(self):
244
 
        from bzrlib import branch as _mod_branch
245
 
        calls = []
246
 
        _mod_branch.Branch.hooks.install_named_hook('post_switch',
247
 
            calls.append, None)
248
 
        self.make_branch_and_tree('branch')
249
 
        self.run_bzr('branch branch branch2')
250
 
        self.run_bzr('checkout --lightweight branch checkout')
251
 
        os.chdir('checkout')
252
 
        self.assertLength(0, calls)
253
 
        out, err = self.run_bzr('switch ../branch2')
254
 
        self.assertLength(1, calls)
255
 
 
256
 
    def test_switch_lightweight_directory(self):
257
 
        """Test --directory option"""
258
 
 
259
 
        # create a source branch
260
 
        a_tree = self.make_branch_and_tree('a')
261
 
        self.build_tree_contents([('a/a', 'initial\n')])
262
 
        a_tree.add('a')
263
 
        a_tree.commit(message='initial')
264
 
 
265
 
        # clone and add a differing revision
266
 
        b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
267
 
        self.build_tree_contents([('b/a', 'initial\nmore\n')])
268
 
        b_tree.commit(message='more')
269
 
 
270
 
        self.run_bzr('checkout --lightweight a checkout')
271
 
        self.run_bzr('switch --directory checkout b')
272
 
        self.assertFileEqual('initial\nmore\n', 'checkout/a')