/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.tests.per_workingtree import TestCaseWithWorkingTree
2255.2.195 by Robert Collins
Fix set_reference_revision on dirstate format trees.
25
26
27
class TestNestedSupport(TestCaseWithWorkingTree):
28
4100.2.1 by Aaron Bentley
Disable autodetection of tree references
29
    def make_branch_and_tree(self, path):
30
        tree = TestCaseWithWorkingTree.make_branch_and_tree(self, path)
31
        if not tree.supports_tree_reference():
32
            raise TestNotApplicable('Tree references not supported')
33
        return tree
34
6926.2.10 by Jelmer Vernooij
Fix inventory tree test.
35
    def test_set_get_inventory_tree_reference(self):
2255.2.195 by Robert Collins
Fix set_reference_revision on dirstate format trees.
36
        """This tests that setting a tree reference is persistent."""
37
        tree = self.make_branch_and_tree('.')
6926.2.10 by Jelmer Vernooij
Fix inventory tree test.
38
        if not isinstance(tree, inventorytree.InventoryTree):
39
            raise TestNotApplicable('not an inventory tree')
7490.77.2 by Jelmer Vernooij
Split out git and bzr-specific transforms.
40
        transform = tree.transform()
2255.2.195 by Robert Collins
Fix set_reference_revision on dirstate format trees.
41
        trans_id = transform.new_directory('reference', transform.root,
7143.15.2 by Jelmer Vernooij
Run autopep8.
42
                                           b'subtree-id')
6926.2.3 by Jelmer Vernooij
bees
43
        transform.set_tree_reference(b'subtree-revision', trans_id)
2255.2.195 by Robert Collins
Fix set_reference_revision on dirstate format trees.
44
        transform.apply()
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
45
        tree = tree.controldir.open_workingtree()
2255.2.195 by Robert Collins
Fix set_reference_revision on dirstate format trees.
46
        tree.lock_read()
47
        self.addCleanup(tree.unlock)
6973.13.2 by Jelmer Vernooij
Fix some more tests.
48
        self.assertEqual(b'subtree-revision',
7143.15.2 by Jelmer Vernooij
Run autopep8.
49
                         tree.root_inventory.get_entry(b'subtree-id').reference_revision)
1551.10.26 by Aaron Bentley
Allow extract when tree is locked
50
51
    def test_extract_while_locked(self):
52
        tree = self.make_branch_and_tree('.')
53
        tree.lock_write()
54
        self.addCleanup(tree.unlock)
55
        self.build_tree(['subtree/'])
6856 by Jelmer Vernooij
Merge lp:~jelmer/brz/is-versioned.
56
        tree.add(['subtree'])
57
        subtree = tree.extract('subtree')
4100.2.1 by Aaron Bentley
Disable autodetection of tree references
58
4100.2.3 by Aaron Bentley
Avoid autodetecting tree references in _comparison_data.
59
    def prepare_with_subtree(self):
4100.2.1 by Aaron Bentley
Disable autodetection of tree references
60
        tree = self.make_branch_and_tree('.')
61
        tree.lock_write()
4100.2.3 by Aaron Bentley
Avoid autodetecting tree references in _comparison_data.
62
        self.addCleanup(tree.unlock)
4100.2.1 by Aaron Bentley
Disable autodetection of tree references
63
        subtree = self.make_branch_and_tree('subtree')
6926.2.7 by Jelmer Vernooij
Fixes.
64
        subtree.commit('dummy')
6926.2.6 by Jelmer Vernooij
Don't specify file ids.
65
        tree.add(['subtree'])
4100.2.3 by Aaron Bentley
Avoid autodetecting tree references in _comparison_data.
66
        return tree
67
68
    def test_comparison_data_does_not_autodetect_subtree(self):
69
        tree = self.prepare_with_subtree()
6855.4.1 by Jelmer Vernooij
Yet more bees.
70
        ie = inventory.InventoryDirectory(b'subtree-id', 'subtree',
5786.1.2 by John Arbash Meinel
Change a test a bit.
71
                                          tree.path2id(''))
4100.2.3 by Aaron Bentley
Avoid autodetecting tree references in _comparison_data.
72
        self.assertEqual('directory',
5786.1.2 by John Arbash Meinel
Change a test a bit.
73
                         tree._comparison_data(ie, 'subtree')[0])
74
6926.2.7 by Jelmer Vernooij
Fixes.
75
    def test_may_not_autodetect_subtree(self):
5786.1.2 by John Arbash Meinel
Change a test a bit.
76
        tree = self.prepare_with_subtree()
6926.2.7 by Jelmer Vernooij
Fixes.
77
        self.assertIn(tree.kind('subtree'), ('directory', 'tree-reference'))
5786.1.2 by John Arbash Meinel
Change a test a bit.
78
79
    def test_iter_entries_by_dir_autodetects_subtree(self):
80
        tree = self.prepare_with_subtree()
6885.6.1 by Jelmer Vernooij
Support specific_files argument to Tree.iter_entries_by_dir.
81
        path, ie = next(tree.iter_entries_by_dir(specific_files=['subtree']))
5786.1.2 by John Arbash Meinel
Change a test a bit.
82
        self.assertEqual('tree-reference', ie.kind)