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
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')
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)
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"""
78
68
br_a = Branch.initialize("a")
79
69
file('a/b', 'wb').write('b')
81
commit(br_a, "silly commit", rev_id='A')
71
commit(br_a, "silly commit")
83
74
br_b = Branch.initialize("b")
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)
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:
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")
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'))
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')
140
def test_bad_revision(self):
141
branch = Branch.initialize('.')
142
self.assertRaises(errors.InvalidRevisionId, branch.get_revision, None)
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
184
159
self.assertEqual('FOO', branch.revision_store.get('A', 'sig').read())
186
def test__relcontrolfilename(self):
187
branch = Branch.initialize('.')
188
self.assertEqual('.bzr/%25', branch._rel_controlfilename('%'))
190
def test__relcontrolfilename_empty(self):
191
branch = Branch.initialize('.')
192
self.assertEqual('.bzr', branch._rel_controlfilename(''))
195
162
class TestRemote(TestCaseWithWebserver):
334
301
self.failUnless(isinstance(self.branch._transaction,
335
302
transactions.PassThroughTransaction))
336
303
self.branch.unlock()
339
class TestBranchPushLocations(TestCaseInTempDir):
342
super(TestBranchPushLocations, self).setUp()
343
self.branch = Branch.initialize('.')
345
def test_get_push_location_unset(self):
346
self.assertEqual(None, self.branch.get_push_location())
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" %
353
self.assertEqual("foo", self.branch.get_push_location())
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')
361
# TODO RBC 20051029 test getting a push location from a branch in a
362
# recursive section - that is, it appends the branch name.