~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_switch.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-09-01 08:02:42 UTC
  • mfrom: (5390.3.3 faster-revert-593560)
  • Revision ID: pqm@pqm.ubuntu.com-20100901080242-esg62ody4frwmy66
(spiv) Avoid repeatedly calling self.target.all_file_ids() in
 InterTree.iter_changes. (Andrew Bennetts)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007-2011 Canonical Ltd
 
1
# Copyright (C) 2007-2010 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
22
22
from bzrlib import (
23
23
    branch,
24
24
    errors,
25
 
    lock,
26
25
    merge as _mod_merge,
27
26
    switch,
28
27
    tests,
29
 
    workingtree,
30
 
    )
 
28
)
31
29
 
32
30
 
33
31
class TestSwitch(tests.TestCaseWithTransport):
36
34
        super(TestSwitch, self).setUp()
37
35
        self.lightweight = True
38
36
 
39
 
    @staticmethod
40
 
    def _master_if_present(branch):
41
 
        master = branch.get_master_branch()
42
 
        if master:
43
 
            return master
44
 
        else:
45
 
            return branch
46
 
 
47
37
    def _setup_tree(self):
48
38
        tree = self.make_branch_and_tree('branch-1')
49
39
        self.build_tree(['branch-1/file-1'])
51
41
        tree.commit('rev1')
52
42
        return tree
53
43
 
54
 
    def _setup_uncommitted(self, same_revision=False):
55
 
        tree = self._setup_tree()
56
 
        to_branch = tree.bzrdir.sprout('branch-2').open_branch()
57
 
        self.build_tree(['branch-1/file-2'])
58
 
        if not same_revision:
59
 
            tree.add('file-2')
60
 
            tree.remove('file-1')
61
 
            tree.commit('rev2')
62
 
        checkout = tree.branch.create_checkout('checkout',
63
 
            lightweight=self.lightweight)
64
 
        self.build_tree(['checkout/file-3'])
65
 
        checkout.add('file-3')
66
 
        return checkout, to_branch
67
 
 
68
 
    def test_switch_store_uncommitted(self):
69
 
        """Test switch updates tree and stores uncommitted changes."""
70
 
        checkout, to_branch = self._setup_uncommitted()
71
 
        self.assertPathDoesNotExist('checkout/file-1')
72
 
        self.assertPathExists('checkout/file-2')
73
 
        switch.switch(checkout.bzrdir, to_branch, store_uncommitted=True)
74
 
        self.assertPathExists('checkout/file-1')
75
 
        self.assertPathDoesNotExist('checkout/file-2')
76
 
        self.assertPathDoesNotExist('checkout/file-3')
77
 
 
78
 
    def test_switch_restore_uncommitted(self):
79
 
        """Test switch updates tree and restores uncommitted changes."""
80
 
        checkout, to_branch = self._setup_uncommitted()
81
 
        old_branch = self._master_if_present(checkout.branch)
82
 
        self.assertPathDoesNotExist('checkout/file-1')
83
 
        self.assertPathExists('checkout/file-2')
84
 
        self.assertPathExists('checkout/file-3')
85
 
        switch.switch(checkout.bzrdir, to_branch, store_uncommitted=True)
86
 
        checkout = workingtree.WorkingTree.open('checkout')
87
 
        switch.switch(checkout.bzrdir, old_branch, store_uncommitted=True)
88
 
        self.assertPathDoesNotExist('checkout/file-1')
89
 
        self.assertPathExists('checkout/file-2')
90
 
        self.assertPathExists('checkout/file-3')
91
 
 
92
 
    def test_switch_restore_uncommitted_same_revision(self):
93
 
        """Test switch updates tree and restores uncommitted changes."""
94
 
        checkout, to_branch = self._setup_uncommitted(same_revision=True)
95
 
        old_branch = self._master_if_present(checkout.branch)
96
 
        switch.switch(checkout.bzrdir, to_branch, store_uncommitted=True)
97
 
        checkout = workingtree.WorkingTree.open('checkout')
98
 
        switch.switch(checkout.bzrdir, old_branch, store_uncommitted=True)
99
 
        self.assertPathExists('checkout/file-3')
100
 
 
101
44
    def test_switch_updates(self):
102
45
        """Test switch updates tree and keeps uncommitted changes."""
103
 
        checkout, to_branch = self._setup_uncommitted()
104
 
        self.assertPathDoesNotExist('checkout/file-1')
105
 
        self.assertPathExists('checkout/file-2')
 
46
        tree = self._setup_tree()
 
47
        to_branch = tree.bzrdir.sprout('branch-2').open_branch()
 
48
        self.build_tree(['branch-1/file-2'])
 
49
        tree.add('file-2')
 
50
        tree.remove('file-1')
 
51
        tree.commit('rev2')
 
52
        checkout = tree.branch.create_checkout('checkout',
 
53
            lightweight=self.lightweight)
 
54
        self.build_tree(['checkout/file-3'])
 
55
        checkout.add('file-3')
 
56
        self.failIfExists('checkout/file-1')
 
57
        self.failUnlessExists('checkout/file-2')
106
58
        switch.switch(checkout.bzrdir, to_branch)
107
 
        self.assertPathExists('checkout/file-1')
108
 
        self.assertPathDoesNotExist('checkout/file-2')
109
 
        self.assertPathExists('checkout/file-3')
 
59
        self.failUnlessExists('checkout/file-1')
 
60
        self.failIfExists('checkout/file-2')
 
61
        self.failUnlessExists('checkout/file-3')
110
62
 
111
63
    def test_switch_after_branch_moved(self):
112
64
        """Test switch after the branch is moved."""
132
84
                'Unable to connect to current master branch .*'
133
85
                'To switch anyway, use --force.')
134
86
        switch.switch(checkout.bzrdir, to_branch, force=True)
135
 
        self.assertPathDoesNotExist('checkout/file-1')
136
 
        self.assertPathExists('checkout/file-2')
137
 
        self.assertPathExists('checkout/file-3')
 
87
        self.failIfExists('checkout/file-1')
 
88
        self.failUnlessExists('checkout/file-2')
 
89
        self.failUnlessExists('checkout/file-3')
138
90
 
139
91
    def test_switch_when_pending_merges(self):
140
92
        """Test graceful failure if pending merges are outstanding."""
168
120
        checkout = tree.branch.create_checkout('checkout',
169
121
            lightweight=self.lightweight)
170
122
        switch.switch(checkout.bzrdir, tree.branch, revision_id="rev1")
171
 
        self.assertPathExists('checkout/file-1')
172
 
        self.assertPathDoesNotExist('checkout/file-2')
 
123
        self.failUnlessExists('checkout/file-1')
 
124
        self.failIfExists('checkout/file-2')
173
125
 
174
126
    def test_switch_changing_root_id(self):
175
127
        tree = self._setup_tree()
227
179
        self.assertContainsRe(str(err),
228
180
            'Cannot switch as local commits found in the checkout.')
229
181
        # Check all is ok when force is given
230
 
        self.assertPathDoesNotExist('checkout/file-1')
231
 
        self.assertPathExists('checkout/file-2')
 
182
        self.failIfExists('checkout/file-1')
 
183
        self.failUnlessExists('checkout/file-2')
232
184
        switch.switch(checkout.bzrdir, to_branch, force=True)
233
 
        self.assertPathExists('checkout/file-1')
234
 
        self.assertPathDoesNotExist('checkout/file-2')
235
 
        self.assertPathDoesNotExist('checkout/file-3')
236
 
        self.assertPathExists('checkout/file-4')
 
185
        self.failUnlessExists('checkout/file-1')
 
186
        self.failIfExists('checkout/file-2')
 
187
        self.failIfExists('checkout/file-3')
 
188
        self.failUnlessExists('checkout/file-4')
237
189
        # Check that the checkout is a true mirror of the bound branch
238
190
        self.assertEqual(to_branch.last_revision_info(),
239
191
                         checkout.branch.last_revision_info())