~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/branch_implementations/test_branch.py

Add a --transport parameter to the test suite to set the default transport to be used in the test suite.

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
                           )
32
32
import bzrlib.gpg
33
33
from bzrlib.osutils import getcwd
 
34
from bzrlib.revision import NULL_REVISION
34
35
from bzrlib.tests import TestCase, TestCaseWithTransport, TestSkipped
35
36
from bzrlib.trace import mutter
36
37
import bzrlib.transactions as transactions
37
38
from bzrlib.transport import get_transport
38
39
from bzrlib.transport.http import HttpServer
39
40
from bzrlib.transport.memory import MemoryServer
40
 
from bzrlib.revision import NULL_REVISION
 
41
from bzrlib.workingtree import WorkingTree
41
42
 
42
43
# TODO: Make a branch using basis branch, and check that it 
43
44
# doesn't request any files that could have been avoided, by 
80
81
        b1 = self.make_branch('b1')
81
82
        b2 = self.make_branch('b2')
82
83
        file('b1/foo', 'w').write('hello')
83
 
        b1.working_tree().add(['foo'], ['foo-id'])
84
 
        b1.working_tree().commit('lala!', rev_id='revision-1', allow_pointless=False)
 
84
        wt = WorkingTree('b1', b1)
 
85
        wt.add(['foo'], ['foo-id'])
 
86
        wt.commit('lala!', rev_id='revision-1', allow_pointless=False)
85
87
 
86
88
        mutter('start fetch')
87
89
        f = Fetcher(from_branch=b1, to_branch=b2)
95
97
 
96
98
    def test_revision_tree(self):
97
99
        b1 = self.get_branch()
98
 
        b1.working_tree().commit('lala!', rev_id='revision-1', allow_pointless=True)
 
100
        wt = WorkingTree('.', b1)
 
101
        wt.commit('lala!', rev_id='revision-1', allow_pointless=True)
99
102
        tree = b1.revision_tree('revision-1')
100
103
        tree = b1.revision_tree(None)
101
104
        self.assertEqual(len(tree.list_files()), 0)
107
110
        os.mkdir('a')
108
111
        br_a = self.make_branch('a')
109
112
        file('a/b', 'wb').write('b')
110
 
        br_a.working_tree().add('b')
 
113
        WorkingTree("a", br_a).add('b')
111
114
        commit(br_a, "silly commit", rev_id='A')
112
115
        os.mkdir('b')
113
116
        br_b = self.make_branch('b')
146
149
        """Copy only part of the history of a branch."""
147
150
        self.build_tree(['a/', 'a/one'])
148
151
        br_a = self.make_branch('a')
149
 
        br_a.working_tree().add(['one'])
150
 
        br_a.working_tree().commit('commit one', rev_id='u@d-1')
 
152
        wt = WorkingTree("a", br_a)
 
153
        wt.add(['one'])
 
154
        wt.commit('commit one', rev_id='u@d-1')
151
155
        self.build_tree(['a/two'])
152
 
        br_a.working_tree().add(['two'])
153
 
        br_a.working_tree().commit('commit two', rev_id='u@d-2')
 
156
        wt.add(['two'])
 
157
        wt.commit('commit two', rev_id='u@d-2')
154
158
        br_b = copy_branch(br_a, 'b', revision='u@d-1')
155
159
        self.assertEqual(br_b.last_revision(), 'u@d-1')
156
160
        self.assertTrue(os.path.exists('b/one'))
159
163
    def test_record_initial_ghost_merge(self):
160
164
        """A pending merge with no revision present is still a merge."""
161
165
        branch = self.get_branch()
162
 
        branch.working_tree().add_pending_merge('non:existent@rev--ision--0--2')
163
 
        branch.working_tree().commit('pretend to merge nonexistent-revision', rev_id='first')
 
166
        wt = WorkingTree(".", branch)
 
167
        wt.add_pending_merge('non:existent@rev--ision--0--2')
 
168
        wt.commit('pretend to merge nonexistent-revision', rev_id='first')
164
169
        rev = branch.get_revision(branch.last_revision())
165
170
        self.assertEqual(len(rev.parent_ids), 1)
166
171
        # parent_sha1s is not populated now, WTF. rbc 20051003
178
183
    def test_pending_merges(self):
179
184
        """Tracking pending-merged revisions."""
180
185
        b = self.get_branch()
181
 
        wt = b.working_tree()
 
186
        wt = WorkingTree(".", b)
182
187
        self.assertEquals(wt.pending_merges(), [])
183
188
        wt.add_pending_merge('foo@azkhazan-123123-abcabc')
184
189
        self.assertEquals(wt.pending_merges(), ['foo@azkhazan-123123-abcabc'])
188
193
        self.assertEquals(wt.pending_merges(),
189
194
                          ['foo@azkhazan-123123-abcabc',
190
195
                           'wibble@fofof--20050401--1928390812'])
191
 
        b.working_tree().commit("commit from base with two merges")
 
196
        wt.commit("commit from base with two merges")
192
197
        rev = b.get_revision(b.revision_history()[0])
193
198
        self.assertEquals(len(rev.parent_ids), 2)
194
199
        self.assertEquals(rev.parent_ids[0],
200
205
 
201
206
    def test_sign_existing_revision(self):
202
207
        branch = self.get_branch()
203
 
        branch.working_tree().commit("base", allow_pointless=True, rev_id='A')
 
208
        WorkingTree(".", branch).commit("base", allow_pointless=True,
 
209
                                        rev_id='A')
204
210
        from bzrlib.testament import Testament
205
211
        branch.sign_revision('A', bzrlib.gpg.LoopbackGPGStrategy(None))
206
212
        self.assertEqual(Testament.from_revision(branch, 'A').as_short_text(),
241
247
        os.mkdir('bzr.dev')
242
248
        branch = self.get_branch()
243
249
        branch.nick = "My happy branch"
244
 
        branch.working_tree().commit('My commit respect da nick.')
 
250
        WorkingTree('.', branch).commit('My commit respect da nick.')
245
251
        committed = branch.get_revision(branch.last_revision())
246
252
        self.assertEqual(committed.properties["branch-nick"], 
247
253
                         "My happy branch")
423
429
        fn = branches_config_filename()
424
430
        print >> open(fn, 'wt'), ("[%s]\n"
425
431
                                  "push_location=foo" %
426
 
                                  getcwd())
 
432
                                  self.get_branch().base[:-1])
427
433
        self.assertEqual("foo", self.get_branch().get_push_location())
428
434
 
429
435
    def test_set_push_location(self):
433
439
        fn = branches_config_filename()
434
440
        self.get_branch().set_push_location('foo')
435
441
        self.assertFileEqual("[%s]\n"
436
 
                             "push_location = foo" % getcwd(),
 
442
                             "push_location = foo" % self.get_branch().base[:-1],
437
443
                             fn)
438
444
 
439
445
    # TODO RBC 20051029 test getting a push location from a branch in a