~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/testbranch.py

  • Committer: Aaron Bentley
  • Date: 2005-09-29 04:59:47 UTC
  • mto: (1393.1.21) (1185.14.1)
  • mto: This revision was merged to the branch mainline in revision 1396.
  • Revision ID: aaron.bentley@utoronto.ca-20050929045947-ff08a7f6578f9657
Conflict handling where OTHER is deleted

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# (C) 2005 Canonical Ltd
 
2
 
 
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.
 
7
 
 
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.
 
12
 
 
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
 
16
 
 
17
import os
 
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
 
22
 
 
23
class TestBranch(TestCaseInTempDir):
 
24
 
 
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"])
 
32
 
 
33
    def test_copy_stores(self):
 
34
        """Copy the stores from one branch to another"""
 
35
        os.mkdir('a')
 
36
        br_a = Branch.initialize("a")
 
37
        file('a/b', 'wb').write('b')
 
38
        br_a.add('b')
 
39
        commit(br_a, "silly commit")
 
40
 
 
41
        os.mkdir('b')
 
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])
 
48
        for file_id in tree:
 
49
            if tree.inventory[file_id].kind == "file":
 
50
                tree.get_file(file_id).read()
 
51
        return br_a, br_b
 
52
 
 
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")
 
57
        os.mkdir('c')
 
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'])
 
66
#         >>> br1.add('foo')
 
67
#         >>> br1.add('bar')
 
68
#         >>> commit(br1, "lala!", rev_id="REVISION-ID-1", verbose=False)
 
69
#         >>> br2 = ScratchBranch()
 
70
#         >>> br2.update_revisions(br1)
 
71
#         Added 2 texts.
 
72
#         Added 1 inventories.
 
73
#         Added 1 revisions.
 
74
#         >>> br2.revision_history()
 
75
#         [u'REVISION-ID-1']
 
76
#         >>> br2.update_revisions(br1)
 
77
#         Added 0 revisions.
 
78
#         >>> br1.text_store.total_size() == br2.text_store.total_size()
 
79
#         True