/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
1185.50.22 by John Arbash Meinel
Forgot to add the test.
1
# Copyright (C) 2004, 2005 by Canonical Ltd
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
2
#
1185.50.22 by John Arbash Meinel
Forgot to add the test.
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.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
7
#
1185.50.22 by John Arbash Meinel
Forgot to add the test.
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.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
12
#
1185.50.22 by John Arbash Meinel
Forgot to add the test.
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
1532 by Robert Collins
Merge in John Meinels integration branch.
18
1666.1.4 by Robert Collins
* 'Metadir' is now the default disk format. This improves behaviour in
19
from bzrlib.tests.workingtree_implementations import TestCaseWithWorkingTree
1185.50.22 by John Arbash Meinel
Forgot to add the test.
20
from bzrlib.branch import Branch
1910.2.31 by Aaron Bentley
Fix bugs in basis inventory handling, change filename
21
from bzrlib import inventory
1740.2.2 by Aaron Bentley
Add test for the basis inventory automatically adding the revision id.
22
from bzrlib.revision import Revision
1910.2.31 by Aaron Bentley
Fix bugs in basis inventory handling, change filename
23
import bzrlib.xml6
1185.50.22 by John Arbash Meinel
Forgot to add the test.
24
1532 by Robert Collins
Merge in John Meinels integration branch.
25
1666.1.4 by Robert Collins
* 'Metadir' is now the default disk format. This improves behaviour in
26
class TestBasisInventory(TestCaseWithWorkingTree):
1185.50.22 by John Arbash Meinel
Forgot to add the test.
27
28
    def test_create(self):
1638.1.2 by Robert Collins
Change the basis-inventory file to not have the revision-id in the file name.
29
        # TODO: jam 20051218 this probably should add more than just
30
        #                    a couple files to the inventory
31
1185.50.22 by John Arbash Meinel
Forgot to add the test.
32
        # Make sure the basis file is created by a commit
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
33
        t = self.make_branch_and_tree('.')
34
        b = t.branch
1185.50.22 by John Arbash Meinel
Forgot to add the test.
35
        open('a', 'wb').write('a\n')
36
        t.add('a')
37
        t.commit('a', rev_id='r1')
38
1910.2.31 by Aaron Bentley
Fix bugs in basis inventory handling, change filename
39
        t._control_files.get_utf8('basis-inventory-cache')
1185.50.22 by John Arbash Meinel
Forgot to add the test.
40
1638.1.2 by Robert Collins
Change the basis-inventory file to not have the revision-id in the file name.
41
        basis_inv = t.basis_tree().inventory
42
        self.assertEquals('r1', basis_inv.revision_id)
1185.50.22 by John Arbash Meinel
Forgot to add the test.
43
        
1185.65.17 by Robert Collins
Merge from integration, mode-changes are broken.
44
        store_inv = b.repository.get_inventory('r1')
1185.50.22 by John Arbash Meinel
Forgot to add the test.
45
        self.assertEquals(store_inv._byid, basis_inv._byid)
46
47
        open('b', 'wb').write('b\n')
48
        t.add('b')
49
        t.commit('b', rev_id='r2')
50
1910.2.31 by Aaron Bentley
Fix bugs in basis inventory handling, change filename
51
        t._control_files.get_utf8('basis-inventory-cache')
1185.50.22 by John Arbash Meinel
Forgot to add the test.
52
1638.1.2 by Robert Collins
Change the basis-inventory file to not have the revision-id in the file name.
53
        basis_inv_txt = t.read_basis_inventory()
1910.2.31 by Aaron Bentley
Fix bugs in basis inventory handling, change filename
54
        basis_inv = bzrlib.xml6.serializer_v6.read_inventory_from_string(basis_inv_txt)
1638.1.2 by Robert Collins
Change the basis-inventory file to not have the revision-id in the file name.
55
        self.assertEquals('r2', basis_inv.revision_id)
1185.65.17 by Robert Collins
Merge from integration, mode-changes are broken.
56
        store_inv = b.repository.get_inventory('r2')
1185.50.22 by John Arbash Meinel
Forgot to add the test.
57
58
        self.assertEquals(store_inv._byid, basis_inv._byid)
59
1910.2.31 by Aaron Bentley
Fix bugs in basis inventory handling, change filename
60
    def test_wrong_format(self):
61
        """WorkingTree.basis safely ignores junk basis inventories"""
62
        t = self.make_branch_and_tree('.')
63
        b = t.branch
64
        open('a', 'wb').write('a\n')
65
        t.add('a')
66
        t.commit('a', rev_id='r1')
67
        t._control_files.put_utf8('basis-inventory-cache', 'booga')
68
        t.basis_tree()
69
        t._control_files.put_utf8('basis-inventory-cache', '<xml/>')
70
        t.basis_tree()
71
        t._control_files.put_utf8('basis-inventory-cache', '<inventory />')
72
        t.basis_tree()
73
        t._control_files.put_utf8('basis-inventory-cache', 
74
                                  '<inventory format="pi"/>')
75
        t.basis_tree()
76
1740.2.2 by Aaron Bentley
Add test for the basis inventory automatically adding the revision id.
77
    def test_basis_inv_gets_revision(self):
78
        """When the inventory of the basis tree has no revision id it gets set.
79
1908.6.3 by Robert Collins
Tidy up the last_revision_id and add_pending_merge conversion to use cleaner apis.
80
        It gets set during set_parent_trees() or set_parent_ids().
1740.2.2 by Aaron Bentley
Add test for the basis inventory automatically adding the revision id.
81
        """
82
        tree = self.make_branch_and_tree('.')
83
        tree.lock_write()
1908.6.1 by Robert Collins
Change all callers of set_last_revision to use set_parent_trees.
84
        # TODO change this to use CommitBuilder
1910.2.31 by Aaron Bentley
Fix bugs in basis inventory handling, change filename
85
        inv = inventory.Inventory(revision_id='r1')
86
        inv.root.revision = 'r1'
87
        inv_lines = tree.branch.repository.serialise_inventory(inv).split('\n')
88
        inv_lines = [(l + '\n') for l in inv_lines if l is not None]
1740.2.2 by Aaron Bentley
Add test for the basis inventory automatically adding the revision id.
89
        tree.branch.repository.control_weaves.get_weave('inventory',
90
            tree.branch.repository.get_transaction()
1910.2.31 by Aaron Bentley
Fix bugs in basis inventory handling, change filename
91
            ).add_lines('r1', [], inv_lines)
1740.2.2 by Aaron Bentley
Add test for the basis inventory automatically adding the revision id.
92
        rev = Revision(timestamp=0,
93
                       timezone=None,
94
                       committer="Foo Bar <foo@example.com>",
95
                       message="Message",
96
                       inventory_sha1="",
97
                       revision_id='r1')
98
        rev.parent_ids = []
99
        tree.branch.repository.add_revision('r1', rev)
100
        tree.unlock()
101
        tree.branch.append_revision('r1')
1908.6.1 by Robert Collins
Change all callers of set_last_revision to use set_parent_trees.
102
        tree.set_parent_trees(
103
            [('r1', tree.branch.repository.revision_tree('r1'))])
1740.2.2 by Aaron Bentley
Add test for the basis inventory automatically adding the revision id.
104
        # TODO: we should deserialise the file here, rather than peeking
105
        # without parsing, but to do this properly needs a serialiser on the
106
        # tree object that abstracts whether it is xml/rio/etc.
107
        self.assertContainsRe(
1910.2.31 by Aaron Bentley
Fix bugs in basis inventory handling, change filename
108
            tree._control_files.get_utf8('basis-inventory-cache').read(),
1740.2.2 by Aaron Bentley
Add test for the basis inventory automatically adding the revision id.
109
            'revision_id="r1"')
110