1
# (C) 2005 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
from bzrlib.selftest import TestCaseInTempDir
19
from bzrlib.branch import Branch, copy_stores, copy_branch
20
from bzrlib.commit import commit
21
from bzrlib.errors import NoSuchRevision, UnlistableBranch
23
class TestBranch(TestCaseInTempDir):
25
def test_append_revisions(self):
26
"""Test appending more than one revision"""
27
br = Branch.initialize(".")
28
br.append_revision("rev1")
29
self.assertEquals(br.revision_history(), ["rev1",])
30
br.append_revision("rev2", "rev3")
31
self.assertEquals(br.revision_history(), ["rev1", "rev2", "rev3"])
33
def test_copy_stores(self):
34
"""Copy the stores from one branch to another"""
36
br_a = Branch.initialize("a")
37
file('a/b', 'wb').write('b')
39
commit(br_a, "silly commit")
42
br_b = Branch.initialize("b")
43
self.assertRaises(NoSuchRevision, br_b.get_revision,
44
br_a.revision_history()[0])
45
copy_stores(br_a, br_b)
46
rev = br_b.get_revision(br_a.revision_history()[0])
47
tree = br_b.revision_tree(br_a.revision_history()[0])
49
if tree.inventory[file_id].kind == "file":
50
tree.get_file(file_id).read()
53
def test_copy_branch(self):
54
"""Copy the stores from one branch to another"""
55
br_a, br_b = self.test_copy_stores()
56
commit(br_b, "silly commit")
58
br_c = copy_branch(br_a, 'c', basis_branch=br_b)
59
self.assertEqual(br_a.revision_history(), br_c.revision_history())
60
assert br_b.last_patch() not in br_c.revision_history()
61
br_c.get_revision(br_b.last_patch())
62
# TODO: rewrite this as a regular unittest, without relying on the displayed output
63
# >>> from bzrlib.commit import commit
64
# >>> bzrlib.trace.silent = True
65
# >>> br1 = ScratchBranch(files=['foo', 'bar'])
68
# >>> commit(br1, "lala!", rev_id="REVISION-ID-1", verbose=False)
69
# >>> br2 = ScratchBranch()
70
# >>> br2.update_revisions(br1)
72
# Added 1 inventories.
74
# >>> br2.revision_history()
76
# >>> br2.update_revisions(br1)
78
# >>> br1.text_store.total_size() == br2.text_store.total_size()