5697.1.1
by Jelmer Vernooij
Move WorkingTreeFormat2 to a separate file. |
1 |
# Copyright (C) 2005-2011 Canonical Ltd
|
2 |
# Authors: Robert Collins <robert.collins@canonical.com>
|
|
3 |
#
|
|
4 |
# This program is free software; you can redistribute it and/or modify
|
|
5 |
# it under the terms of the GNU General Public License as published by
|
|
6 |
# the Free Software Foundation; either version 2 of the License, or
|
|
7 |
# (at your option) any later version.
|
|
8 |
#
|
|
9 |
# This program is distributed in the hope that it will be useful,
|
|
10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 |
# GNU General Public License for more details.
|
|
13 |
#
|
|
14 |
# You should have received a copy of the GNU General Public License
|
|
15 |
# along with this program; if not, write to the Free Software
|
|
16 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
17 |
||
6379.6.7
by Jelmer Vernooij
Move importing from future until after doc string, otherwise the doc string will disappear. |
18 |
"""Tests for weave-era working tree formats."""
|
19 |
||
6379.6.3
by Jelmer Vernooij
Use absolute_import. |
20 |
from __future__ import absolute_import |
21 |
||
5697.1.1
by Jelmer Vernooij
Move WorkingTreeFormat2 to a separate file. |
22 |
import os |
23 |
||
24 |
from bzrlib import ( |
|
25 |
conflicts, |
|
26 |
errors, |
|
27 |
)
|
|
28 |
||
29 |
from bzrlib.tests import ( |
|
30 |
TestCaseWithTransport, |
|
31 |
)
|
|
32 |
||
5582.12.6
by Jelmer Vernooij
merge bzr.dev. |
33 |
from bzrlib.plugins.weave_fmt.bzrdir import BzrDirFormat6 |
5697.1.1
by Jelmer Vernooij
Move WorkingTreeFormat2 to a separate file. |
34 |
|
35 |
||
36 |
class TestFormat2WorkingTree(TestCaseWithTransport): |
|
37 |
"""Tests that are specific to format 2 trees."""
|
|
38 |
||
39 |
def create_format2_tree(self, url): |
|
40 |
return self.make_branch_and_tree( |
|
41 |
url, format=BzrDirFormat6()) |
|
42 |
||
43 |
def test_conflicts(self): |
|
44 |
# test backwards compatability
|
|
45 |
tree = self.create_format2_tree('.') |
|
46 |
self.assertRaises(errors.UnsupportedOperation, tree.set_conflicts, |
|
47 |
None) |
|
48 |
file('lala.BASE', 'wb').write('labase') |
|
49 |
expected = conflicts.ContentsConflict('lala') |
|
50 |
self.assertEqual(list(tree.conflicts()), [expected]) |
|
51 |
file('lala', 'wb').write('la') |
|
52 |
tree.add('lala', 'lala-id') |
|
53 |
expected = conflicts.ContentsConflict('lala', file_id='lala-id') |
|
54 |
self.assertEqual(list(tree.conflicts()), [expected]) |
|
55 |
file('lala.THIS', 'wb').write('lathis') |
|
56 |
file('lala.OTHER', 'wb').write('laother') |
|
57 |
# When "text conflict"s happen, stem, THIS and OTHER are text
|
|
58 |
expected = conflicts.TextConflict('lala', file_id='lala-id') |
|
59 |
self.assertEqual(list(tree.conflicts()), [expected]) |
|
60 |
os.unlink('lala.OTHER') |
|
61 |
os.mkdir('lala.OTHER') |
|
62 |
expected = conflicts.ContentsConflict('lala', file_id='lala-id') |
|
63 |
self.assertEqual(list(tree.conflicts()), [expected]) |
|
64 |
||
65 |
def test_detect_conflicts(self): |
|
66 |
"""Conflicts are detected properly"""
|
|
67 |
tree = self.create_format2_tree('.') |
|
68 |
self.build_tree_contents([('hello', 'hello world4'), |
|
69 |
('hello.THIS', 'hello world2'), |
|
70 |
('hello.BASE', 'hello world1'), |
|
71 |
('hello.OTHER', 'hello world3'), |
|
72 |
('hello.sploo.BASE', 'yellowworld'), |
|
73 |
('hello.sploo.OTHER', 'yellowworld2'), |
|
74 |
])
|
|
75 |
tree.lock_read() |
|
76 |
self.assertLength(6, list(tree.list_files())) |
|
77 |
tree.unlock() |
|
78 |
tree_conflicts = tree.conflicts() |
|
79 |
self.assertLength(2, tree_conflicts) |
|
80 |
self.assertTrue('hello' in tree_conflicts[0].path) |
|
81 |
self.assertTrue('hello.sploo' in tree_conflicts[1].path) |
|
82 |
conflicts.restore('hello') |
|
83 |
conflicts.restore('hello.sploo') |
|
84 |
self.assertLength(0, tree.conflicts()) |
|
85 |
self.assertFileEqual('hello world2', 'hello') |
|
86 |
self.assertFalse(os.path.lexists('hello.sploo')) |
|
87 |
self.assertRaises(errors.NotConflicted, conflicts.restore, 'hello') |
|
88 |
self.assertRaises(errors.NotConflicted, |
|
89 |
conflicts.restore, 'hello.sploo') |