1
 
# Copyright (C) 2006, 2010 Canonical Ltd
 
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.
 
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.
 
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
29
 
class TestJoin(tests.TestCaseWithTransport):
 
32
 
        base_tree = self.make_branch_and_tree('tree',
 
33
 
            format='dirstate-with-subtree')
 
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')
 
37
 
        sub_tree.set_root_id('subtree-root-id')
 
38
 
        sub_tree.add('file1', 'file1-id')
 
39
 
        sub_tree.commit('added file1')
 
40
 
        return base_tree, sub_tree
 
42
 
    def check_success(self, path):
 
43
 
        base_tree = workingtree.WorkingTree.open(path)
 
44
 
        self.assertEqual('file1-id', base_tree.path2id('subtree/file1'))
 
47
 
        base_tree, sub_tree = self.make_trees()
 
48
 
        self.run_bzr('join tree/subtree')
 
49
 
        self.check_success('tree')
 
51
 
    def test_join_dot(self):
 
52
 
        base_tree, sub_tree = self.make_trees()
 
53
 
        self.run_bzr('join .', working_dir='tree/subtree')
 
54
 
        self.check_success('tree')
 
56
 
    def test_join_error(self):
 
57
 
        base_tree, sub_tree = self.make_trees()
 
58
 
        os.mkdir('tree/subtree2')
 
59
 
        osutils.rename('tree/subtree', 'tree/subtree2/subtree')
 
61
 
            ('Cannot join .*subtree.  Parent directory is not versioned',),
 
62
 
             'join tree/subtree2/subtree')
 
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')
 
67
 
        self.run_bzr_error(('Not a branch:.*subtree2',),
 
70
 
    def test_join_reference(self):
 
71
 
        """Join can add a reference if --reference is supplied"""
 
72
 
        base_tree, sub_tree = self.make_trees()
 
73
 
        self.run_bzr('join . --reference', working_dir='tree/subtree')
 
75
 
        self.addCleanup(sub_tree.unlock)
 
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'))
 
82
 
        self.addCleanup(base_tree.unlock)
 
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'))
 
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
 
90
 
        # support tree references, but the default repository format
 
92
 
        tree = self.make_branch_and_tree('tree', format='dirstate')
 
93
 
        tree2 = self.make_branch_and_tree('tree/subtree')
 
94
 
        out, err = self.run_bzr('join --reference tree/subtree',
 
96
 
        self.assertContainsRe(err, r"Can't join trees")
 
97
 
        self.assertContainsRe(err, r"use bzr upgrade")