~bzr-pqm/bzr/bzr.dev

2052.3.2 by John Arbash Meinel
Change Copyright .. by Canonical to Copyright ... Canonical
1
# Copyright (C) 2005 Canonical Ltd
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
2
#
1185.14.8 by Aaron Bentley
Added test_commit.py
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.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
7
#
1185.14.8 by Aaron Bentley
Added test_commit.py
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.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
12
#
1185.14.8 by Aaron Bentley
Added test_commit.py
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
17
18
import os
19
2120.7.2 by Aaron Bentley
Move autoresolve functionality to workingtree
20
from bzrlib import bzrdir
1534.10.4 by Aaron Bentley
Implemented conflict serialization
21
from bzrlib.tests import TestCaseWithTransport, TestCase
1185.14.8 by Aaron Bentley
Added test_commit.py
22
from bzrlib.branch import Branch
1773.4.1 by Martin Pool
Add pyflakes makefile target; fix many warnings
23
from bzrlib.conflicts import (MissingParent, ContentsConflict, TextConflict,
24
        PathConflict, DuplicateID, DuplicateEntry, ParentLoop, UnversionedParent,
25
        ConflictList, 
26
        restore)
1185.35.1 by Aaron Bentley
Implemented conflicts.restore
27
from bzrlib.errors import NotConflicted
1185.14.8 by Aaron Bentley
Added test_commit.py
28
1534.10.4 by Aaron Bentley
Implemented conflict serialization
29
1185.14.8 by Aaron Bentley
Added test_commit.py
30
# TODO: Test commit with some added, and added-but-missing files
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
31
# RBC 20060124 is that not tested in test_commit.py ?
1185.14.8 by Aaron Bentley
Added test_commit.py
32
1666.1.4 by Robert Collins
* 'Metadir' is now the default disk format. This improves behaviour in
33
# The order of 'path' here is important - do not let it
34
# be a sorted list.
2309.4.13 by John Arbash Meinel
Conflicts go through Stanza so the need to be aware of utf8 versus unicode file ids.
35
# u'\xe5' == a with circle
36
# '\xc3\xae' == u'\xee' == i with hat
37
# So these are u'pathg' and 'idg' only with a circle and a hat. (shappo?)
1534.10.22 by Aaron Bentley
Got ConflictList implemented
38
example_conflicts = ConflictList([ 
2309.4.13 by John Arbash Meinel
Conflicts go through Stanza so the need to be aware of utf8 versus unicode file ids.
39
    MissingParent('Not deleting', u'p\xe5thg', '\xc3\xaedg'),
40
    ContentsConflict(u'p\xe5tha', None, '\xc3\xaeda'), 
41
    TextConflict(u'p\xe5tha'),
42
    PathConflict(u'p\xe5thb', u'p\xe5thc', '\xc3\xaedb'),
43
    DuplicateID('Unversioned existing file', u'p\xe5thc', u'p\xe5thc2',
44
                '\xc3\xaedc', '\xc3\xaedc'),
45
    DuplicateEntry('Moved existing file to',  u'p\xe5thdd.moved', u'p\xe5thd',
46
                   '\xc3\xaedd', None),
47
    ParentLoop('Cancelled move', u'p\xe5the', u'p\xe5th2e',
48
               None, '\xc3\xaed2e'),
49
    UnversionedParent('Versioned directory', u'p\xe5thf', '\xc3\xaedf'),
1534.10.22 by Aaron Bentley
Got ConflictList implemented
50
])
1534.10.4 by Aaron Bentley
Implemented conflict serialization
51
52
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
53
class TestConflicts(TestCaseWithTransport):
1185.14.8 by Aaron Bentley
Added test_commit.py
54
55
    def test_conflicts(self):
56
        """Conflicts are detected properly"""
1666.1.4 by Robert Collins
* 'Metadir' is now the default disk format. This improves behaviour in
57
        tree = self.make_branch_and_tree('.',
1773.4.1 by Martin Pool
Add pyflakes makefile target; fix many warnings
58
            format=bzrdir.BzrDirFormat6())
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
59
        b = tree.branch
1185.35.1 by Aaron Bentley
Implemented conflicts.restore
60
        file('hello', 'w').write('hello world4')
61
        file('hello.THIS', 'w').write('hello world2')
62
        file('hello.BASE', 'w').write('hello world1')
63
        file('hello.OTHER', 'w').write('hello world3')
1185.14.8 by Aaron Bentley
Added test_commit.py
64
        file('hello.sploo.BASE', 'w').write('yellow world')
1185.35.1 by Aaron Bentley
Implemented conflicts.restore
65
        file('hello.sploo.OTHER', 'w').write('yellow world2')
2255.2.61 by John Arbash Meinel
Find callers of list_files() and make sure the tree is always locked.
66
        tree.lock_read()
1185.35.1 by Aaron Bentley
Implemented conflicts.restore
67
        self.assertEqual(len(list(tree.list_files())), 6)
2255.2.61 by John Arbash Meinel
Find callers of list_files() and make sure the tree is always locked.
68
        tree.unlock()
1534.10.22 by Aaron Bentley
Got ConflictList implemented
69
        conflicts = tree.conflicts()
1185.14.8 by Aaron Bentley
Added test_commit.py
70
        self.assertEqual(len(conflicts), 2)
1534.10.20 by Aaron Bentley
Got all tests passing
71
        self.assert_('hello' in conflicts[0].path)
72
        self.assert_('hello.sploo' in conflicts[1].path)
1185.35.1 by Aaron Bentley
Implemented conflicts.restore
73
        restore('hello')
74
        restore('hello.sploo')
1534.10.22 by Aaron Bentley
Got ConflictList implemented
75
        self.assertEqual(len(tree.conflicts()), 0)
1185.35.1 by Aaron Bentley
Implemented conflicts.restore
76
        self.assertFileEqual('hello world2', 'hello')
77
        assert not os.path.lexists('hello.sploo')
78
        self.assertRaises(NotConflicted, restore, 'hello')
79
        self.assertRaises(NotConflicted, restore, 'hello.sploo')
1534.10.4 by Aaron Bentley
Implemented conflict serialization
80
1558.12.9 by Aaron Bentley
Handle resolving conflicts with directories properly
81
    def test_resolve_conflict_dir(self):
82
        tree = self.make_branch_and_tree('.')
83
        b = tree.branch
84
        file('hello', 'w').write('hello world4')
85
        tree.add('hello', 'q')
86
        file('hello.THIS', 'w').write('hello world2')
87
        file('hello.BASE', 'w').write('hello world1')
88
        os.mkdir('hello.OTHER')
89
        l = ConflictList([TextConflict('hello')])
90
        l.remove_files(tree)
91
1534.10.4 by Aaron Bentley
Implemented conflict serialization
92
93
class TestConflictStanzas(TestCase):
1666.1.4 by Robert Collins
* 'Metadir' is now the default disk format. This improves behaviour in
94
1534.10.4 by Aaron Bentley
Implemented conflict serialization
95
    def test_stanza_roundtrip(self):
1666.1.4 by Robert Collins
* 'Metadir' is now the default disk format. This improves behaviour in
96
        # write and read our example stanza.
1534.10.23 by Aaron Bentley
Removed conflicts_to_stanzas and stanzas_to_conflicts
97
        stanza_iter = example_conflicts.to_stanzas()
98
        processed = ConflictList.from_stanzas(stanza_iter)
2309.4.13 by John Arbash Meinel
Conflicts go through Stanza so the need to be aware of utf8 versus unicode file ids.
99
        for o, p in zip(processed, example_conflicts):
1534.10.4 by Aaron Bentley
Implemented conflict serialization
100
            self.assertEqual(o, p)
101
2309.4.13 by John Arbash Meinel
Conflicts go through Stanza so the need to be aware of utf8 versus unicode file ids.
102
            self.assertIsInstance(o.path, unicode)
103
104
            if o.file_id is not None:
105
                self.assertIsInstance(o.file_id, str)
106
2309.4.14 by John Arbash Meinel
The parameter is 'conflict_path' not 'conflict_file_path'
107
            conflict_path = getattr(o, 'conflict_path', None)
108
            if conflict_path is not None:
109
                self.assertIsInstance(conflict_path, unicode)
2309.4.13 by John Arbash Meinel
Conflicts go through Stanza so the need to be aware of utf8 versus unicode file ids.
110
111
            conflict_file_id = getattr(o, 'conflict_file_id', None)
112
            if conflict_file_id is not None:
113
                self.assertIsInstance(conflict_file_id, str)
114
1534.10.4 by Aaron Bentley
Implemented conflict serialization
115
    def test_stanzification(self):
1534.10.23 by Aaron Bentley
Removed conflicts_to_stanzas and stanzas_to_conflicts
116
        for stanza in example_conflicts.to_stanzas():
2309.4.13 by John Arbash Meinel
Conflicts go through Stanza so the need to be aware of utf8 versus unicode file ids.
117
            if 'file_id' in stanza:
118
                # In Stanza form, the file_id has to be unicode.
119
                self.assertStartsWith(stanza['file_id'], u'\xeed')
120
            self.assertStartsWith(stanza['path'], u'p\xe5th')
2309.4.14 by John Arbash Meinel
The parameter is 'conflict_path' not 'conflict_file_path'
121
            if 'conflict_path' in stanza:
122
                self.assertStartsWith(stanza['conflict_path'], u'p\xe5th')
2309.4.13 by John Arbash Meinel
Conflicts go through Stanza so the need to be aware of utf8 versus unicode file ids.
123
            if 'conflict_file_id' in stanza:
124
                self.assertStartsWith(stanza['conflict_file_id'], u'\xeed')