~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_switch.py

  • Committer: Jelmer Vernooij
  • Date: 2011-12-14 12:15:44 UTC
  • mto: This revision was merged to the branch mainline in revision 6365.
  • Revision ID: jelmer@samba.org-20111214121544-v07cbvmi30re6q7w
s/NoVfsCalls/ContainsNoVfsCalls/.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007-2010 Canonical Ltd
 
1
# Copyright (C) 2007-2011 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
19
19
 
20
20
import os
21
21
 
22
 
from bzrlib import branch, errors, switch, tests
 
22
from bzrlib import (
 
23
    branch,
 
24
    errors,
 
25
    merge as _mod_merge,
 
26
    switch,
 
27
    tests,
 
28
    )
23
29
 
24
30
 
25
31
class TestSwitch(tests.TestCaseWithTransport):
47
53
            lightweight=self.lightweight)
48
54
        self.build_tree(['checkout/file-3'])
49
55
        checkout.add('file-3')
50
 
        self.failIfExists('checkout/file-1')
51
 
        self.failUnlessExists('checkout/file-2')
 
56
        self.assertPathDoesNotExist('checkout/file-1')
 
57
        self.assertPathExists('checkout/file-2')
52
58
        switch.switch(checkout.bzrdir, to_branch)
53
 
        self.failUnlessExists('checkout/file-1')
54
 
        self.failIfExists('checkout/file-2')
55
 
        self.failUnlessExists('checkout/file-3')
 
59
        self.assertPathExists('checkout/file-1')
 
60
        self.assertPathDoesNotExist('checkout/file-2')
 
61
        self.assertPathExists('checkout/file-3')
56
62
 
57
63
    def test_switch_after_branch_moved(self):
58
64
        """Test switch after the branch is moved."""
78
84
                'Unable to connect to current master branch .*'
79
85
                'To switch anyway, use --force.')
80
86
        switch.switch(checkout.bzrdir, to_branch, force=True)
81
 
        self.failIfExists('checkout/file-1')
82
 
        self.failUnlessExists('checkout/file-2')
83
 
        self.failUnlessExists('checkout/file-3')
 
87
        self.assertPathDoesNotExist('checkout/file-1')
 
88
        self.assertPathExists('checkout/file-2')
 
89
        self.assertPathExists('checkout/file-3')
84
90
 
85
91
    def test_switch_when_pending_merges(self):
86
92
        """Test graceful failure if pending merges are outstanding."""
114
120
        checkout = tree.branch.create_checkout('checkout',
115
121
            lightweight=self.lightweight)
116
122
        switch.switch(checkout.bzrdir, tree.branch, revision_id="rev1")
117
 
        self.failUnlessExists('checkout/file-1')
118
 
        self.failIfExists('checkout/file-2')
 
123
        self.assertPathExists('checkout/file-1')
 
124
        self.assertPathDoesNotExist('checkout/file-2')
119
125
 
120
126
    def test_switch_changing_root_id(self):
121
127
        tree = self._setup_tree()
129
135
        switch.switch(checkout.bzrdir, tree2.branch)
130
136
        self.assertEqual('custom-root-id', tree2.get_root_id())
131
137
 
 
138
    def test_switch_configurable_file_merger(self):
 
139
        class DummyMerger(_mod_merge.ConfigurableFileMerger):
 
140
            name_prefix = 'file'
 
141
 
 
142
        _mod_merge.Merger.hooks.install_named_hook(
 
143
            'merge_file_content', DummyMerger,
 
144
            'test factory')
 
145
        foo = self.make_branch('foo')
 
146
        checkout = foo.create_checkout('checkout', lightweight=True)
 
147
        self.build_tree_contents([('checkout/file', 'a')])
 
148
        checkout.add('file')
 
149
        checkout.commit('a')
 
150
        bar = foo.bzrdir.sprout('bar').open_workingtree()
 
151
        self.build_tree_contents([('bar/file', 'b')])
 
152
        bar.commit('b')
 
153
        self.build_tree_contents([('checkout/file', 'c')])
 
154
        switch.switch(checkout.bzrdir, bar.branch)
 
155
 
132
156
 
133
157
class TestSwitchHeavyweight(TestSwitch):
134
158
 
155
179
        self.assertContainsRe(str(err),
156
180
            'Cannot switch as local commits found in the checkout.')
157
181
        # Check all is ok when force is given
158
 
        self.failIfExists('checkout/file-1')
159
 
        self.failUnlessExists('checkout/file-2')
 
182
        self.assertPathDoesNotExist('checkout/file-1')
 
183
        self.assertPathExists('checkout/file-2')
160
184
        switch.switch(checkout.bzrdir, to_branch, force=True)
161
 
        self.failUnlessExists('checkout/file-1')
162
 
        self.failIfExists('checkout/file-2')
163
 
        self.failIfExists('checkout/file-3')
164
 
        self.failUnlessExists('checkout/file-4')
 
185
        self.assertPathExists('checkout/file-1')
 
186
        self.assertPathDoesNotExist('checkout/file-2')
 
187
        self.assertPathDoesNotExist('checkout/file-3')
 
188
        self.assertPathExists('checkout/file-4')
165
189
        # Check that the checkout is a true mirror of the bound branch
166
190
        self.assertEqual(to_branch.last_revision_info(),
167
191
                         checkout.branch.last_revision_info())