~bzr-pqm/bzr/bzr.dev

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
5186.2.2 by Martin Pool
wrap os.rename to insert the source and destination filenames in any exception that may be raised
20
from bzrlib import (
21
    bzrdir,
22
    osutils,
23
    repository,
24
    tests,
25
    workingtree,
26
    )
1731.2.7 by Aaron Bentley
Add join command
27
28
29
class TestJoin(tests.TestCaseWithTransport):
30
31
    def make_trees(self):
2100.3.17 by Aaron Bentley
Remove get_format_*, make FormatRegistry.register_metadir vary working tree
32
        base_tree = self.make_branch_and_tree('tree',
2255.2.208 by Robert Collins
Remove more references to 'experimental' formats.
33
            format='dirstate-with-subtree')
1731.2.7 by Aaron Bentley
Add join command
34
        base_tree.commit('empty commit')
35
        self.build_tree(['tree/subtree/', 'tree/subtree/file1'])
36
        sub_tree = self.make_branch_and_tree('tree/subtree')
2100.3.11 by Aaron Bentley
Add join --reference support
37
        sub_tree.set_root_id('subtree-root-id')
1731.2.7 by Aaron Bentley
Add join command
38
        sub_tree.add('file1', 'file1-id')
39
        sub_tree.commit('added file1')
40
        return base_tree, sub_tree
41
42
    def check_success(self, path):
43
        base_tree = workingtree.WorkingTree.open(path)
44
        self.assertEqual('file1-id', base_tree.path2id('subtree/file1'))
45
46
    def test_join(self):
47
        base_tree, sub_tree = self.make_trees()
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
48
        self.run_bzr('join tree/subtree')
1731.2.7 by Aaron Bentley
Add join command
49
        self.check_success('tree')
50
51
    def test_join_dot(self):
52
        base_tree, sub_tree = self.make_trees()
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
53
        self.run_bzr('join .', working_dir='tree/subtree')
1731.2.7 by Aaron Bentley
Add join command
54
        self.check_success('tree')
55
56
    def test_join_error(self):
57
        base_tree, sub_tree = self.make_trees()
58
        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
59
        osutils.rename('tree/subtree', 'tree/subtree2/subtree')
2255.2.223 by Martin Pool
add stubbed out join blackbox test
60
        self.run_bzr_error(
61
            ('Cannot join .*subtree.  Parent directory is not versioned',),
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
62
             'join tree/subtree2/subtree')
2255.2.223 by Martin Pool
add stubbed out join blackbox test
63
        # disabled because this gives an ugly error at present -- mbp 20070306
64
        ## self.run_bzr_error(
65
        ##     ('Cannot join .*subtree.  Parent directory is not versioned',),
66
        ##      'join', '--reference', 'tree/subtree2/subtree')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
67
        self.run_bzr_error(('Not a branch:.*subtree2',),
68
                           'join tree/subtree2')
2100.3.11 by Aaron Bentley
Add join --reference support
69
70
    def test_join_reference(self):
71
        """Join can add a reference if --reference is supplied"""
72
        base_tree, sub_tree = self.make_trees()
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
73
        self.run_bzr('join . --reference', working_dir='tree/subtree')
2255.2.210 by Robert Collins
Fix test_join with dirstate default.
74
        sub_tree.lock_read()
75
        self.addCleanup(sub_tree.unlock)
2100.3.11 by Aaron Bentley
Add join --reference support
76
        self.assertEqual('file1-id', sub_tree.path2id('file1'))
77
        self.assertTrue('file1-id' in sub_tree)
78
        self.assertEqual('subtree-root-id', sub_tree.path2id(''))
79
        self.assertEqual('', sub_tree.id2path('subtree-root-id'))
80
        self.assertIs(None, base_tree.path2id('subtree/file1'))
2255.2.198 by Robert Collins
All test_join tests passing.
81
        base_tree.lock_read()
82
        self.addCleanup(base_tree.unlock)
2100.3.11 by Aaron Bentley
Add join --reference support
83
        self.assertTrue('file1-id' not in base_tree)
84
        self.assertEqual('subtree-root-id', base_tree.path2id('subtree'))
85
        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
86
87
    def test_references_check_repository_support(self):
88
        """Users are stopped from adding a reference that can't be committed."""
89
        # 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
90
        # 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
91
        # cannot.
92
        tree = self.make_branch_and_tree('tree', format='dirstate')
93
        tree2 = self.make_branch_and_tree('tree/subtree')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
94
        out, err = self.run_bzr('join --reference tree/subtree',
95
                                retcode=3)
96
        self.assertContainsRe(err, r"Can't join trees")
97
        self.assertContainsRe(err, r"use bzr upgrade")
2255.2.235 by Martin Pool
Add blackbox test that join gives clean error when the repository doesn't support rich roots
98
99