~bzr-pqm/bzr/bzr.dev

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# Copyright (C) 2006, 2007, 2009, 2010, 2011 Canonical Ltd
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

from bzrlib import (
    conflicts,
    tests,
    workingtree,
    )
from bzrlib.tests import script, features


def make_tree_with_conflicts(test, this_path='this', other_path='other',
        prefix='my'):
    this_tree = test.make_branch_and_tree(this_path)
    test.build_tree_contents([
        ('%s/%sfile' % (this_path, prefix), 'this content\n'),
        ('%s/%s_other_file' % (this_path, prefix), 'this content\n'),
        ('%s/%sdir/' % (this_path, prefix),),
        ])
    this_tree.add(prefix+'file')
    this_tree.add(prefix+'_other_file')
    this_tree.add(prefix+'dir')
    this_tree.commit(message="new")
    other_tree = this_tree.bzrdir.sprout(other_path).open_workingtree()
    test.build_tree_contents([
        ('%s/%sfile' % (other_path, prefix), 'contentsb\n'),
        ('%s/%s_other_file' % (other_path, prefix), 'contentsb\n'),
        ])
    other_tree.rename_one(prefix+'dir', prefix+'dir2')
    other_tree.commit(message="change")
    test.build_tree_contents([
        ('%s/%sfile' % (this_path, prefix), 'contentsa2\n'),
        ('%s/%s_other_file' % (this_path, prefix), 'contentsa2\n'),
        ])
    this_tree.rename_one(prefix+'dir', prefix+'dir3')
    this_tree.commit(message='change')
    this_tree.merge_from_branch(other_tree.branch)
    return this_tree, other_tree


class TestConflicts(script.TestCaseWithTransportAndScript):

    def setUp(self):
        super(TestConflicts, self).setUp()
        make_tree_with_conflicts(self, 'branch', 'other')

    def test_conflicts(self):
        self.run_script("""\
$ cd branch
$ bzr conflicts
Text conflict in my_other_file
Path conflict: mydir3 / mydir2
Text conflict in myfile
""")

    def test_conflicts_text(self):
        self.run_script("""\
$ cd branch
$ bzr conflicts --text
my_other_file
myfile
""")

    def test_conflicts_directory(self):
        self.run_script("""\
$ bzr conflicts  -d branch
Text conflict in my_other_file
Path conflict: mydir3 / mydir2
Text conflict in myfile
""")


class TestUnicodePaths(tests.TestCaseWithTransport):
    """Unicode characters in conflicts should be displayed properly"""

    _test_needs_features = [features.UnicodeFilenameFeature]
    encoding = "UTF-8"

    def _as_output(self, text):
        return text

    def test_messages(self):
        """Conflict messages involving non-ascii paths are displayed okay"""
        make_tree_with_conflicts(self, "branch", prefix=u"\xA7")
        out, err = self.run_bzr(["conflicts", "-d", "branch"],
            encoding=self.encoding)
        self.assertEqual(out.decode(self.encoding),
            u"Text conflict in \xA7_other_file\n"
            u"Path conflict: \xA7dir3 / \xA7dir2\n"
            u"Text conflict in \xA7file\n")
        self.assertEqual(err, "")

    def test_text_conflict_paths(self):
        """Text conflicts on non-ascii paths are displayed okay"""
        make_tree_with_conflicts(self, "branch", prefix=u"\xA7")
        out, err = self.run_bzr(["conflicts", "-d", "branch", "--text"],
            encoding=self.encoding)
        self.assertEqual(out.decode(self.encoding),
            u"\xA7_other_file\n"
            u"\xA7file\n")
        self.assertEqual(err, "")


class TestUnicodePathsOnAsciiTerminal(TestUnicodePaths):
    """Undisplayable unicode characters in conflicts should be escaped"""

    encoding = "ascii"

    def setUp(self):
        self.skip("Need to decide if replacing is the desired behaviour")

    def _as_output(self, text):
        return text.encode(self.encoding, "replace")