/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
2255.2.195 by Robert Collins
Fix set_reference_revision on dirstate format trees.
1
# Copyright (C) 2007 Canonical Ltd
2
# Authors:  Robert Collins <robert.collins@canonical.com>
3
#
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
4183.7.1 by Sabin Iacob
update FSF mailing address
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2255.2.195 by Robert Collins
Fix set_reference_revision on dirstate format trees.
17
18
6670.4.3 by Jelmer Vernooij
Fix more imports.
19
from breezy.bzr import (
5786.1.2 by John Arbash Meinel
Change a test a bit.
20
    inventory,
6926.2.10 by Jelmer Vernooij
Fix inventory tree test.
21
    inventorytree,
5786.1.2 by John Arbash Meinel
Change a test a bit.
22
    )
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
23
from breezy.tests import TestNotApplicable
24
from breezy.transform import TreeTransform
25
from breezy.tests.per_workingtree import TestCaseWithWorkingTree
2255.2.195 by Robert Collins
Fix set_reference_revision on dirstate format trees.
26
27
28
class TestNestedSupport(TestCaseWithWorkingTree):
29
4100.2.1 by Aaron Bentley
Disable autodetection of tree references
30
    def make_branch_and_tree(self, path):
31
        tree = TestCaseWithWorkingTree.make_branch_and_tree(self, path)
32
        if not tree.supports_tree_reference():
33
            raise TestNotApplicable('Tree references not supported')
34
        return tree
35
6926.2.10 by Jelmer Vernooij
Fix inventory tree test.
36
    def test_set_get_inventory_tree_reference(self):
2255.2.195 by Robert Collins
Fix set_reference_revision on dirstate format trees.
37
        """This tests that setting a tree reference is persistent."""
38
        tree = self.make_branch_and_tree('.')
6926.2.10 by Jelmer Vernooij
Fix inventory tree test.
39
        if not isinstance(tree, inventorytree.InventoryTree):
40
            raise TestNotApplicable('not an inventory tree')
2255.2.195 by Robert Collins
Fix set_reference_revision on dirstate format trees.
41
        transform = TreeTransform(tree)
42
        trans_id = transform.new_directory('reference', transform.root,
7143.15.2 by Jelmer Vernooij
Run autopep8.
43
                                           b'subtree-id')
6926.2.3 by Jelmer Vernooij
bees
44
        transform.set_tree_reference(b'subtree-revision', trans_id)
2255.2.195 by Robert Collins
Fix set_reference_revision on dirstate format trees.
45
        transform.apply()
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
46
        tree = tree.controldir.open_workingtree()
2255.2.195 by Robert Collins
Fix set_reference_revision on dirstate format trees.
47
        tree.lock_read()
48
        self.addCleanup(tree.unlock)
6973.13.2 by Jelmer Vernooij
Fix some more tests.
49
        self.assertEqual(b'subtree-revision',
7143.15.2 by Jelmer Vernooij
Run autopep8.
50
                         tree.root_inventory.get_entry(b'subtree-id').reference_revision)
1551.10.26 by Aaron Bentley
Allow extract when tree is locked
51
52
    def test_extract_while_locked(self):
53
        tree = self.make_branch_and_tree('.')
54
        tree.lock_write()
55
        self.addCleanup(tree.unlock)
56
        self.build_tree(['subtree/'])
6856 by Jelmer Vernooij
Merge lp:~jelmer/brz/is-versioned.
57
        tree.add(['subtree'])
58
        subtree = tree.extract('subtree')
4100.2.1 by Aaron Bentley
Disable autodetection of tree references
59
4100.2.3 by Aaron Bentley
Avoid autodetecting tree references in _comparison_data.
60
    def prepare_with_subtree(self):
4100.2.1 by Aaron Bentley
Disable autodetection of tree references
61
        tree = self.make_branch_and_tree('.')
62
        tree.lock_write()
4100.2.3 by Aaron Bentley
Avoid autodetecting tree references in _comparison_data.
63
        self.addCleanup(tree.unlock)
4100.2.1 by Aaron Bentley
Disable autodetection of tree references
64
        subtree = self.make_branch_and_tree('subtree')
6926.2.7 by Jelmer Vernooij
Fixes.
65
        subtree.commit('dummy')
6926.2.6 by Jelmer Vernooij
Don't specify file ids.
66
        tree.add(['subtree'])
4100.2.3 by Aaron Bentley
Avoid autodetecting tree references in _comparison_data.
67
        return tree
68
69
    def test_comparison_data_does_not_autodetect_subtree(self):
70
        tree = self.prepare_with_subtree()
6855.4.1 by Jelmer Vernooij
Yet more bees.
71
        ie = inventory.InventoryDirectory(b'subtree-id', 'subtree',
5786.1.2 by John Arbash Meinel
Change a test a bit.
72
                                          tree.path2id(''))
4100.2.3 by Aaron Bentley
Avoid autodetecting tree references in _comparison_data.
73
        self.assertEqual('directory',
5786.1.2 by John Arbash Meinel
Change a test a bit.
74
                         tree._comparison_data(ie, 'subtree')[0])
75
6926.2.7 by Jelmer Vernooij
Fixes.
76
    def test_may_not_autodetect_subtree(self):
5786.1.2 by John Arbash Meinel
Change a test a bit.
77
        tree = self.prepare_with_subtree()
6926.2.7 by Jelmer Vernooij
Fixes.
78
        self.assertIn(tree.kind('subtree'), ('directory', 'tree-reference'))
5786.1.2 by John Arbash Meinel
Change a test a bit.
79
80
    def test_iter_entries_by_dir_autodetects_subtree(self):
81
        tree = self.prepare_with_subtree()
6885.6.1 by Jelmer Vernooij
Support specific_files argument to Tree.iter_entries_by_dir.
82
        path, ie = next(tree.iter_entries_by_dir(specific_files=['subtree']))
5786.1.2 by John Arbash Meinel
Change a test a bit.
83
        self.assertEqual('tree-reference', ie.kind)