~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/testbranch.py

  • Committer: Robert Collins
  • Date: 2005-10-17 23:13:00 UTC
  • mto: This revision was merged to the branch mainline in revision 1462.
  • Revision ID: robertc@robertcollins.net-20051017231300-e1c9e931bcfacd6a
Branch.open_containing now returns a tuple (Branch, relative-path).

This allows direct access to the common case of 'get me this file
from its branch'. (Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
from bzrlib.selftest.HTTPTestUtil import TestCaseWithWebserver
27
27
from bzrlib.trace import mutter
28
28
import bzrlib.transactions as transactions
29
 
from bzrlib.revision import NULL_REVISION
30
29
 
31
30
# TODO: Make a branch using basis branch, and check that it 
32
31
# doesn't request any files that could have been avoided, by 
63
62
        tree = b2.revision_tree('revision-1')
64
63
        eq(tree.get_file_text('foo-id'), 'hello')
65
64
 
66
 
    def test_revision_tree(self):
67
 
        b1 = Branch.initialize('.')
68
 
        b1.commit('lala!', rev_id='revision-1', allow_pointless=True)
69
 
        tree = b1.revision_tree('revision-1')
70
 
        tree = b1.revision_tree(None)
71
 
        self.assertEqual(len(tree.list_files()), 0)
72
 
        tree = b1.revision_tree(NULL_REVISION)
73
 
        self.assertEqual(len(tree.list_files()), 0)
74
 
 
75
 
    def get_unbalanced_branch_pair(self):
76
 
        """Return two branches, a and b, with one file in a."""
 
65
    def test_push_stores(self):
 
66
        """Copy the stores from one branch to another"""
77
67
        os.mkdir('a')
78
68
        br_a = Branch.initialize("a")
79
69
        file('a/b', 'wb').write('b')
80
70
        br_a.add('b')
81
 
        commit(br_a, "silly commit", rev_id='A')
 
71
        commit(br_a, "silly commit")
 
72
 
82
73
        os.mkdir('b')
83
74
        br_b = Branch.initialize("b")
84
 
        return br_a, br_b
85
 
 
86
 
    def get_balanced_branch_pair(self):
87
 
        """Returns br_a, br_b as with one commit in a, and b has a's stores."""
88
 
        br_a, br_b = self.get_unbalanced_branch_pair()
89
 
        br_a.push_stores(br_b)
90
 
        return br_a, br_b
91
 
 
92
 
    def test_push_stores(self):
93
 
        """Copy the stores from one branch to another"""
94
 
        br_a, br_b = self.get_unbalanced_branch_pair()
95
 
        # ensure the revision is missing.
96
75
        self.assertRaises(NoSuchRevision, br_b.get_revision, 
97
76
                          br_a.revision_history()[0])
98
77
        br_a.push_stores(br_b)
99
 
        # check that b now has all the data from a's first commit.
100
78
        rev = br_b.get_revision(br_a.revision_history()[0])
101
79
        tree = br_b.revision_tree(br_a.revision_history()[0])
102
80
        for file_id in tree:
106
84
 
107
85
    def test_copy_branch(self):
108
86
        """Copy the stores from one branch to another"""
109
 
        br_a, br_b = self.get_balanced_branch_pair()
 
87
        br_a, br_b = self.test_push_stores()
110
88
        commit(br_b, "silly commit")
111
89
        os.mkdir('c')
112
90
        br_c = copy_branch(br_a, 'c', basis_branch=br_b)
126
104
        self.assertTrue(os.path.exists('b/one'))
127
105
        self.assertFalse(os.path.exists('b/two'))
128
106
        
 
107
 
129
108
    def test_record_initial_ghost_merge(self):
130
109
        """A pending merge with no revision present is still a merge."""
131
110
        branch = Branch.initialize('.')
137
116
        self.assertEqual(len(rev.parent_sha1s), 0)
138
117
        self.assertEqual(rev.parent_ids[0], 'non:existent@rev--ision--0--2')
139
118
 
140
 
    def test_bad_revision(self):
141
 
        branch = Branch.initialize('.')
142
 
        self.assertRaises(errors.InvalidRevisionId, branch.get_revision, None)
143
 
 
144
119
# TODO 20051003 RBC:
145
120
# compare the gpg-to-sign info for a commit with a ghost and 
146
121
#     an identical tree without a ghost
183
158
                                        'FOO', 'A')
184
159
        self.assertEqual('FOO', branch.revision_store.get('A', 'sig').read())
185
160
 
186
 
    def test__relcontrolfilename(self):
187
 
        branch = Branch.initialize('.')
188
 
        self.assertEqual('.bzr/%25', branch._rel_controlfilename('%'))
189
 
        
190
 
    def test__relcontrolfilename_empty(self):
191
 
        branch = Branch.initialize('.')
192
 
        self.assertEqual('.bzr', branch._rel_controlfilename(''))
193
 
 
194
161
 
195
162
class TestRemote(TestCaseWithWebserver):
196
163
 
334
301
        self.failUnless(isinstance(self.branch._transaction,
335
302
                                   transactions.PassThroughTransaction))
336
303
        self.branch.unlock()
337
 
 
338
 
 
339
 
class TestBranchPushLocations(TestCaseInTempDir):
340
 
 
341
 
    def setUp(self):
342
 
        super(TestBranchPushLocations, self).setUp()
343
 
        self.branch = Branch.initialize('.')
344
 
        
345
 
    def test_get_push_location_unset(self):
346
 
        self.assertEqual(None, self.branch.get_push_location())
347
 
 
348
 
    def test_get_push_location_exact(self):
349
 
        self.build_tree(['.bazaar/'])
350
 
        print >> open('.bazaar/branches.conf', 'wt'), ("[%s]\n"
351
 
                                                       "push_location=foo" %
352
 
                                                       os.getcwdu())
353
 
        self.assertEqual("foo", self.branch.get_push_location())
354
 
 
355
 
    def test_set_push_location(self):
356
 
        self.branch.set_push_location('foo')
357
 
        self.assertFileEqual("[%s]\n"
358
 
                             "push_location = foo" % os.getcwdu(),
359
 
                             '.bazaar/branches.conf')
360
 
 
361
 
    # TODO RBC 20051029 test getting a push location from a branch in a 
362
 
    # recursive section - that is, it appends the branch name.