/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
5186.2.2 by Martin Pool
wrap os.rename to insert the source and destination filenames in any exception that may be raised
1
# Copyright (C) 2006, 2010 Canonical Ltd
1731.2.20 by Aaron Bentley
Add copyright notice to join tests
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
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1731.2.20 by Aaron Bentley
Add copyright notice to join tests
16
17
1731.2.7 by Aaron Bentley
Add join command
18
import os
19
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
20
from breezy import (
5186.2.2 by Martin Pool
wrap os.rename to insert the source and destination filenames in any exception that may be raised
21
    osutils,
22
    tests,
23
    workingtree,
24
    )
1731.2.7 by Aaron Bentley
Add join command
25
26
27
class TestJoin(tests.TestCaseWithTransport):
28
29
    def make_trees(self):
2100.3.17 by Aaron Bentley
Remove get_format_*, make FormatRegistry.register_metadir vary working tree
30
        base_tree = self.make_branch_and_tree('tree',
7143.15.2 by Jelmer Vernooij
Run autopep8.
31
                                              format='development-subtree')
1731.2.7 by Aaron Bentley
Add join command
32
        base_tree.commit('empty commit')
33
        self.build_tree(['tree/subtree/', 'tree/subtree/file1'])
34
        sub_tree = self.make_branch_and_tree('tree/subtree')
6855.4.1 by Jelmer Vernooij
Yet more bees.
35
        sub_tree.add('file1', b'file1-id')
1731.2.7 by Aaron Bentley
Add join command
36
        sub_tree.commit('added file1')
37
        return base_tree, sub_tree
38
39
    def check_success(self, path):
40
        base_tree = workingtree.WorkingTree.open(path)
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
41
        self.assertEqual(b'file1-id', base_tree.path2id('subtree/file1'))
1731.2.7 by Aaron Bentley
Add join command
42
43
    def test_join(self):
44
        base_tree, sub_tree = self.make_trees()
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
45
        self.run_bzr('join tree/subtree')
1731.2.7 by Aaron Bentley
Add join command
46
        self.check_success('tree')
47
48
    def test_join_dot(self):
49
        base_tree, sub_tree = self.make_trees()
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
50
        self.run_bzr('join .', working_dir='tree/subtree')
1731.2.7 by Aaron Bentley
Add join command
51
        self.check_success('tree')
52
53
    def test_join_error(self):
54
        base_tree, sub_tree = self.make_trees()
55
        os.mkdir('tree/subtree2')
5186.2.2 by Martin Pool
wrap os.rename to insert the source and destination filenames in any exception that may be raised
56
        osutils.rename('tree/subtree', 'tree/subtree2/subtree')
2255.2.223 by Martin Pool
add stubbed out join blackbox test
57
        self.run_bzr_error(
58
            ('Cannot join .*subtree.  Parent directory is not versioned',),
7143.15.2 by Jelmer Vernooij
Run autopep8.
59
            'join tree/subtree2/subtree')
2255.2.223 by Martin Pool
add stubbed out join blackbox test
60
        # disabled because this gives an ugly error at present -- mbp 20070306
7143.15.2 by Jelmer Vernooij
Run autopep8.
61
        # self.run_bzr_error(
2255.2.223 by Martin Pool
add stubbed out join blackbox test
62
        ##     ('Cannot join .*subtree.  Parent directory is not versioned',),
7143.15.2 by Jelmer Vernooij
Run autopep8.
63
        # 'join', '--reference', 'tree/subtree2/subtree')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
64
        self.run_bzr_error(('Not a branch:.*subtree2',),
65
                           'join tree/subtree2')
2100.3.11 by Aaron Bentley
Add join --reference support
66
67
    def test_join_reference(self):
68
        """Join can add a reference if --reference is supplied"""
69
        base_tree, sub_tree = self.make_trees()
7358.14.1 by Jelmer Vernooij
Remove Tree.get_root_id() in favour of Tree.path2id('').
70
        subtree_root_id = sub_tree.path2id('')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
71
        self.run_bzr('join . --reference', working_dir='tree/subtree')
2255.2.210 by Robert Collins
Fix test_join with dirstate default.
72
        sub_tree.lock_read()
73
        self.addCleanup(sub_tree.unlock)
7391.3.1 by Jelmer Vernooij
Use id2path in fewer places.
74
        if sub_tree.supports_setting_file_ids():
75
            self.assertEqual(b'file1-id', sub_tree.path2id('file1'))
7397.4.7 by Jelmer Vernooij
Remove Tree.has_id.
76
            self.assertEqual('file1', sub_tree.id2path(b'file1-id'))
7391.3.1 by Jelmer Vernooij
Use id2path in fewer places.
77
            self.assertEqual(subtree_root_id, sub_tree.path2id(''))
78
            self.assertEqual('', sub_tree.id2path(subtree_root_id))
7404.3.1 by Jelmer Vernooij
Add follow_tree_references argument to Tree.iter_entries_by_dir.
79
            self.assertEqual(
80
                sub_tree.path2id('file1'), base_tree.path2id('subtree/file1'))
7391.3.1 by Jelmer Vernooij
Use id2path in fewer places.
81
2255.2.198 by Robert Collins
All test_join tests passing.
82
        base_tree.lock_read()
83
        self.addCleanup(base_tree.unlock)
7391.3.1 by Jelmer Vernooij
Use id2path in fewer places.
84
        self.assertEqual(['subtree'], list(base_tree.iter_references()))
85
        if base_tree.supports_setting_file_ids():
86
            self.assertEqual(b'file1-id', sub_tree.path2id('file1'))
7397.4.8 by Jelmer Vernooij
Fix test.
87
            self.assertEqual('file1', sub_tree.id2path(b'file1-id'))
7391.3.1 by Jelmer Vernooij
Use id2path in fewer places.
88
            self.assertEqual(subtree_root_id, base_tree.path2id('subtree'))
89
            self.assertEqual('subtree', base_tree.id2path(subtree_root_id))
2255.2.235 by Martin Pool
Add blackbox test that join gives clean error when the repository doesn't support rich roots
90
91
    def test_references_check_repository_support(self):
92
        """Users are stopped from adding a reference that can't be committed."""
93
        # in 0.15 the default format has a dirstate workingtree, that can
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
94
        # support tree references, but the default repository format
2255.2.235 by Martin Pool
Add blackbox test that join gives clean error when the repository doesn't support rich roots
95
        # cannot.
96
        tree = self.make_branch_and_tree('tree', format='dirstate')
97
        tree2 = self.make_branch_and_tree('tree/subtree')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
98
        out, err = self.run_bzr('join --reference tree/subtree',
99
                                retcode=3)
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
100
        self.assertContainsRe(err, r"Can't join trees")
101
        self.assertContainsRe(err, r"use brz upgrade")