/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
1
# Copyright (C) 2006-2012, 2016 Canonical Ltd
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
2
# Authors:  Robert Collins <robert.collins@canonical.com>
2255.13.4 by Martin Pool
merge
3
#           and others
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
4
#
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 2 of the License, or
8
# (at your option) any later version.
9
#
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
4183.7.1 by Sabin Iacob
update FSF mailing address
17
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
18
3136.1.10 by Aaron Bentley
Clean error if filesystem does not support hard-links
19
import errno
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
20
import os
21
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
22
from ... import (
7447.3.1 by Jelmer Vernooij
Move tree reference info functions to workingtree.
23
    branch as _mod_branch,
6059.4.4 by Vincent Ladeuil
Migrate bzr.workingtree.worth_saving_limit to stack-based config.
24
    config,
6472.2.2 by Jelmer Vernooij
Use controldir rather than bzrdir in a couple more places.
25
    controldir,
3287.20.3 by John Arbash Meinel
Aaron recommended to make this a WT_impl test.
26
    errors,
7447.3.1 by Jelmer Vernooij
Move tree reference info functions to workingtree.
27
    merge,
3287.20.3 by John Arbash Meinel
Aaron recommended to make this a WT_impl test.
28
    osutils,
6241.3.1 by Jelmer Vernooij
Support WorkingTree.clone() having its revision argument set to the NULL revision.
29
    revision as _mod_revision,
3287.20.3 by John Arbash Meinel
Aaron recommended to make this a WT_impl test.
30
    tests,
6059.4.4 by Vincent Ladeuil
Migrate bzr.workingtree.worth_saving_limit to stack-based config.
31
    trace,
3287.20.3 by John Arbash Meinel
Aaron recommended to make this a WT_impl test.
32
    urlutils,
5582.4.3 by Jelmer Vernooij
remove more unused imports, avoid relying on a specific set of working tree formats that support references.
33
    )
6670.4.15 by Jelmer Vernooij
Fix per workingtree tests.
34
from...bzr import (
35
    bzrdir,
36
    )
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
37
from ...errors import (
5582.4.3 by Jelmer Vernooij
remove more unused imports, avoid relying on a specific set of working tree formats that support references.
38
    UnsupportedOperation,
39
    PathsNotVersionedError,
40
    )
6670.4.3 by Jelmer Vernooij
Fix more imports.
41
from ...bzr.inventory import Inventory
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
42
from ...mutabletree import MutableTree
43
from ...osutils import pathjoin, getcwd, has_symlinks
44
from ...sixish import (
7045.4.4 by Jelmer Vernooij
Fix more git tests.
45
    StringIO,
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
46
    )
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
47
from .. import (
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
48
    features,
49
    TestSkipped,
50
    TestNotApplicable,
51
    )
7143.15.2 by Jelmer Vernooij
Run autopep8.
52
from . import TestCaseWithWorkingTree
6670.4.3 by Jelmer Vernooij
Fix more imports.
53
from ...bzr.workingtree import (
6653.5.1 by Jelmer Vernooij
Fix some more tests.
54
    InventoryWorkingTree,
55
    )
6846.6.1 by Jelmer Vernooij
Move Tree{Link,File,Directory,Entry} to breezy.tree.
56
from ...tree import (
5582.4.3 by Jelmer Vernooij
remove more unused imports, avoid relying on a specific set of working tree formats that support references.
57
    TreeDirectory,
58
    TreeFile,
59
    TreeLink,
6846.6.1 by Jelmer Vernooij
Move Tree{Link,File,Directory,Entry} to breezy.tree.
60
    )
7490.129.8 by Jelmer Vernooij
Fix imports.
61
from ...bzr.conflicts import ConflictList, TextConflict, ContentsConflict
6846.6.1 by Jelmer Vernooij
Move Tree{Link,File,Directory,Entry} to breezy.tree.
62
from ...workingtree import (
63
    SettingFileIdUnsupported,
5582.4.3 by Jelmer Vernooij
remove more unused imports, avoid relying on a specific set of working tree formats that support references.
64
    WorkingTree,
65
    )
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
66
1711.7.19 by John Arbash Meinel
file:// urls look slightly different on win32
67
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
68
class TestWorkingTree(TestCaseWithWorkingTree):
69
6437.70.6 by John Arbash Meinel
Fix a couple tests that wanted to directly create a wt where the branch was.
70
    def requireBranchReference(self):
71
        test_branch = self.make_branch('test-branch')
72
        try:
73
            # if there is a working tree now, this is not supported.
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
74
            test_branch.controldir.open_workingtree()
6437.70.6 by John Arbash Meinel
Fix a couple tests that wanted to directly create a wt where the branch was.
75
            raise TestNotApplicable("only on trees that can be separate"
7143.15.2 by Jelmer Vernooij
Run autopep8.
76
                                    " from their branch.")
6437.70.6 by John Arbash Meinel
Fix a couple tests that wanted to directly create a wt where the branch was.
77
        except (errors.NoWorkingTree, errors.NotLocalUrl):
78
            pass
79
5516.1.1 by Vincent Ladeuil
TestCaseWithWorkingTree.make_branch_builder respects its relpath parameter.
80
    def test_branch_builder(self):
81
        # Just a smoke test that we get a branch at the specified relpath
82
        builder = self.make_branch_builder('foobar')
7447.3.1 by Jelmer Vernooij
Move tree reference info functions to workingtree.
83
        br = _mod_branch.Branch.open(self.get_url('foobar'))
5516.1.1 by Vincent Ladeuil
TestCaseWithWorkingTree.make_branch_builder respects its relpath parameter.
84
1732.1.8 by John Arbash Meinel
Adding a test for list_files
85
    def test_list_files(self):
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
86
        tree = self.make_branch_and_tree('.')
1732.1.8 by John Arbash Meinel
Adding a test for list_files
87
        self.build_tree(['dir/', 'file'])
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
88
        if has_symlinks():
89
            os.symlink('target', 'symlink')
2255.2.52 by Robert Collins
Dirstate - fix workingtree.list_files to use the public interface to access the trees inventory.
90
        tree.lock_read()
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
91
        files = list(tree.list_files())
2255.2.52 by Robert Collins
Dirstate - fix workingtree.list_files to use the public interface to access the trees inventory.
92
        tree.unlock()
7143.15.2 by Jelmer Vernooij
Run autopep8.
93
        self.assertEqual(
7143.19.7 by Jelmer Vernooij
merge trunk
94
            files.pop(0), ('dir', '?', 'directory', TreeDirectory()))
95
        self.assertEqual(files.pop(0), ('file', '?', 'file', TreeFile()))
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
96
        if has_symlinks():
7143.19.5 by Jelmer Vernooij
Undo removal of kind.
97
            self.assertEqual(
7143.19.7 by Jelmer Vernooij
merge trunk
98
                files.pop(0), ('symlink', '?', 'symlink', TreeLink()))
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
99
1732.1.8 by John Arbash Meinel
Adding a test for list_files
100
    def test_list_files_sorted(self):
101
        tree = self.make_branch_and_tree('.')
1836.1.18 by John Arbash Meinel
Cleaned up the last failing tests. All tests pass again.
102
        self.build_tree(['dir/', 'file', 'dir/file', 'dir/b',
103
                         'dir/subdir/', 'a', 'dir/subfile',
104
                         'zz_dir/', 'zz_dir/subfile'])
7143.19.1 by Jelmer Vernooij
Drop superfluous kind and file_id return values from Tree.list_files.
105
        with tree.lock_read():
7143.19.7 by Jelmer Vernooij
merge trunk
106
            files = [(path, kind) for (path, v, kind, entry)
107
                     in tree.list_files()]
1732.1.8 by John Arbash Meinel
Adding a test for list_files
108
        self.assertEqual([
109
            ('a', 'file'),
110
            ('dir', 'directory'),
111
            ('file', 'file'),
1732.1.25 by John Arbash Meinel
Fix list_files test, we don't need to check if children are empty if we fall off the loop.
112
            ('zz_dir', 'directory'),
1732.1.8 by John Arbash Meinel
Adding a test for list_files
113
            ], files)
114
6861.1.1 by Jelmer Vernooij
More foreign branch test fixes.
115
        with tree.lock_write():
116
            if tree.has_versioned_directories():
117
                tree.add(['dir', 'zz_dir'])
7143.19.5 by Jelmer Vernooij
Undo removal of kind.
118
                files = [(path, kind) for (path, v, kind, entry)
7143.15.2 by Jelmer Vernooij
Run autopep8.
119
                         in tree.list_files()]
6861.1.1 by Jelmer Vernooij
More foreign branch test fixes.
120
                self.assertEqual([
121
                    ('a', 'file'),
122
                    ('dir', 'directory'),
123
                    ('dir/b', 'file'),
124
                    ('dir/file', 'file'),
125
                    ('dir/subdir', 'directory'),
126
                    ('dir/subfile', 'file'),
127
                    ('file', 'file'),
128
                    ('zz_dir', 'directory'),
129
                    ('zz_dir/subfile', 'file'),
130
                    ], files)
131
            else:
132
                tree.add(['dir/b'])
7143.19.7 by Jelmer Vernooij
merge trunk
133
                files = [(path, kind) for (path, v, kind, entry)
7143.15.2 by Jelmer Vernooij
Run autopep8.
134
                         in tree.list_files()]
6861.1.1 by Jelmer Vernooij
More foreign branch test fixes.
135
                self.assertEqual([
136
                    ('a', 'file'),
137
                    ('dir', 'directory'),
138
                    ('dir/b', 'file'),
139
                    ('dir/file', 'file'),
140
                    ('dir/subdir', 'directory'),
141
                    ('dir/subfile', 'file'),
142
                    ('file', 'file'),
143
                    ('zz_dir', 'directory'),
144
                    ], files)
1732.1.8 by John Arbash Meinel
Adding a test for list_files
145
7490.77.2 by Jelmer Vernooij
Split out git and bzr-specific transforms.
146
    def test_transform(self):
7350.3.1 by Jelmer Vernooij
Add Tree.get_transform.
147
        tree = self.make_branch_and_tree('tree')
7490.77.2 by Jelmer Vernooij
Split out git and bzr-specific transforms.
148
        with tree.transform():
7350.3.1 by Jelmer Vernooij
Add Tree.get_transform.
149
            pass
150
1551.10.29 by Aaron Bentley
Fix tree.list_files when file kind changes
151
    def test_list_files_kind_change(self):
152
        tree = self.make_branch_and_tree('tree')
153
        self.build_tree(['tree/filename'])
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
154
        tree.add('filename')
1551.10.29 by Aaron Bentley
Fix tree.list_files when file kind changes
155
        os.unlink('tree/filename')
156
        self.build_tree(['tree/filename/'])
157
        tree.lock_read()
158
        self.addCleanup(tree.unlock)
159
        result = list(tree.list_files())
160
        self.assertEqual(1, len(result))
6861.1.1 by Jelmer Vernooij
More foreign branch test fixes.
161
        if tree.has_versioned_directories():
162
            self.assertEqual(
7404.4.1 by Jelmer Vernooij
Add support for tree references in id2path.
163
                ('filename', 'V', 'directory'),
164
                (result[0][0], result[0][1], result[0][2]))
6861.1.1 by Jelmer Vernooij
More foreign branch test fixes.
165
        else:
166
            self.assertEqual(
7404.4.1 by Jelmer Vernooij
Add support for tree references in id2path.
167
                ('filename', '?', 'directory'),
168
                (result[0][0], result[0][1], result[0][2]))
1551.10.29 by Aaron Bentley
Fix tree.list_files when file kind changes
169
6449.4.5 by Jelmer Vernooij
Review feedback from vila.
170
    def test_get_config_stack(self):
6449.4.1 by Jelmer Vernooij
Add convenience method WorkingTree.get_config_stack().
171
        # Smoke test that all working trees succeed getting a config
172
        wt = self.make_branch_and_tree('.')
6449.4.3 by Jelmer Vernooij
Use WorkingTree.get_config_stack.
173
        conf = wt.get_config_stack()
6449.4.6 by Jelmer Vernooij
Fix typo.
174
        self.assertIsInstance(conf, config.Stack)
6449.4.1 by Jelmer Vernooij
Add convenience method WorkingTree.get_config_stack().
175
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
176
    def test_open_containing(self):
6437.70.7 by John Arbash Meinel
one more test that wanted to have a branch reference
177
        local_wt = self.make_branch_and_tree('.')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
178
        local_url = local_wt.controldir.root_transport.base
6437.70.7 by John Arbash Meinel
one more test that wanted to have a branch reference
179
        local_base = urlutils.local_path_from_url(local_url)
180
        del local_wt
1711.7.28 by John Arbash Meinel
clean up the WorkingTree.open_containing tests
181
182
        # Empty opens '.'
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
183
        wt, relpath = WorkingTree.open_containing()
184
        self.assertEqual('', relpath)
1711.7.28 by John Arbash Meinel
clean up the WorkingTree.open_containing tests
185
        self.assertEqual(wt.basedir + '/', local_base)
186
187
        # '.' opens this dir
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
188
        wt, relpath = WorkingTree.open_containing(u'.')
189
        self.assertEqual('', relpath)
1711.7.28 by John Arbash Meinel
clean up the WorkingTree.open_containing tests
190
        self.assertEqual(wt.basedir + '/', local_base)
191
192
        # './foo' finds '.' and a relpath of 'foo'
193
        wt, relpath = WorkingTree.open_containing('./foo')
194
        self.assertEqual('foo', relpath)
195
        self.assertEqual(wt.basedir + '/', local_base)
196
197
        # abspath(foo) finds '.' and relpath of 'foo'
198
        wt, relpath = WorkingTree.open_containing('./foo')
199
        wt, relpath = WorkingTree.open_containing(getcwd() + '/foo')
200
        self.assertEqual('foo', relpath)
201
        self.assertEqual(wt.basedir + '/', local_base)
202
203
        # can even be a url: finds '.' and relpath of 'foo'
204
        wt, relpath = WorkingTree.open_containing('./foo')
205
        wt, relpath = WorkingTree.open_containing(
7143.15.2 by Jelmer Vernooij
Run autopep8.
206
            urlutils.local_path_to_url(getcwd() + '/foo'))
1711.7.28 by John Arbash Meinel
clean up the WorkingTree.open_containing tests
207
        self.assertEqual('foo', relpath)
208
        self.assertEqual(wt.basedir + '/', local_base)
209
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
210
    def test_basic_relpath(self):
211
        # for comprehensive relpath tests, see whitebox.py.
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
212
        tree = self.make_branch_and_tree('.')
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
213
        self.assertEqual('child',
214
                         tree.relpath(pathjoin(getcwd(), 'child')))
215
216
    def test_lock_locks_branch(self):
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
217
        tree = self.make_branch_and_tree('.')
6437.70.8 by John Arbash Meinel
trivially implement peek_lock_mode.
218
        self.assertEqual(None, tree.branch.peek_lock_mode())
7490.133.25 by Jelmer Vernooij
More fixes.
219
        with tree.lock_read():
220
            self.assertEqual('r', tree.branch.peek_lock_mode())
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
221
        self.assertEqual(None, tree.branch.peek_lock_mode())
7490.133.25 by Jelmer Vernooij
More fixes.
222
        with tree.lock_write():
223
            self.assertEqual('w', tree.branch.peek_lock_mode())
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
224
        self.assertEqual(None, tree.branch.peek_lock_mode())
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
225
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
226
    def test_revert(self):
227
        """Test selected-file revert"""
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
228
        tree = self.make_branch_and_tree('.')
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
229
230
        self.build_tree(['hello.txt'])
7143.15.2 by Jelmer Vernooij
Run autopep8.
231
        with open('hello.txt', 'w') as f:
232
            f.write('initial hello')
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
233
1551.7.17 by Aaron Bentley
Switch to PathsNotVersioned, accept extra_trees
234
        self.assertRaises(PathsNotVersionedError,
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
235
                          tree.revert, ['hello.txt'])
236
        tree.add(['hello.txt'])
237
        tree.commit('create initial hello.txt')
238
6973.10.4 by Jelmer Vernooij
Update python3.passing.
239
        self.check_file_contents('hello.txt', b'initial hello')
7143.15.2 by Jelmer Vernooij
Run autopep8.
240
        with open('hello.txt', 'w') as f:
241
            f.write('new hello')
6973.10.4 by Jelmer Vernooij
Update python3.passing.
242
        self.check_file_contents('hello.txt', b'new hello')
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
243
244
        # revert file modified since last revision
245
        tree.revert(['hello.txt'])
6973.10.4 by Jelmer Vernooij
Update python3.passing.
246
        self.check_file_contents('hello.txt', b'initial hello')
247
        self.check_file_contents('hello.txt.~1~', b'new hello')
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
248
249
        # reverting again does not clobber the backup
250
        tree.revert(['hello.txt'])
6973.10.4 by Jelmer Vernooij
Update python3.passing.
251
        self.check_file_contents('hello.txt', b'initial hello')
252
        self.check_file_contents('hello.txt.~1~', b'new hello')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
253
1534.10.28 by Aaron Bentley
Use numbered backup files
254
        # backup files are numbered
7143.15.2 by Jelmer Vernooij
Run autopep8.
255
        with open('hello.txt', 'w') as f:
256
            f.write('new hello2')
1534.10.28 by Aaron Bentley
Use numbered backup files
257
        tree.revert(['hello.txt'])
6973.10.4 by Jelmer Vernooij
Update python3.passing.
258
        self.check_file_contents('hello.txt', b'initial hello')
259
        self.check_file_contents('hello.txt.~1~', b'new hello')
260
        self.check_file_contents('hello.txt.~2~', b'new hello2')
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
261
1558.12.7 by Aaron Bentley
Fixed revert with missing files
262
    def test_revert_missing(self):
263
        # Revert a file that has been deleted since last commit
264
        tree = self.make_branch_and_tree('.')
7143.15.2 by Jelmer Vernooij
Run autopep8.
265
        with open('hello.txt', 'w') as f:
266
            f.write('initial hello')
1558.12.7 by Aaron Bentley
Fixed revert with missing files
267
        tree.add('hello.txt')
268
        tree.commit('added hello.txt')
269
        os.unlink('hello.txt')
270
        tree.remove('hello.txt')
271
        tree.revert(['hello.txt'])
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
272
        self.assertPathExists('hello.txt')
1558.12.7 by Aaron Bentley
Fixed revert with missing files
273
1740.6.1 by Martin Pool
Remove Scratch objects used by doctests
274
    def test_versioned_files_not_unknown(self):
275
        tree = self.make_branch_and_tree('.')
1831.1.1 by Martin Pool
[merge] remove default ignore list & update
276
        self.build_tree(['hello.txt'])
1740.6.1 by Martin Pool
Remove Scratch objects used by doctests
277
        tree.add('hello.txt')
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
278
        self.assertEqual(list(tree.unknowns()),
7143.15.2 by Jelmer Vernooij
Run autopep8.
279
                         [])
1831.1.1 by Martin Pool
[merge] remove default ignore list & update
280
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
281
    def test_unknowns(self):
282
        tree = self.make_branch_and_tree('.')
283
        self.build_tree(['hello.txt',
1534.10.29 by Aaron Bentley
Fixed backup numbering to match GNU standard better
284
                         'hello.txt.~1~'])
6855.4.1 by Jelmer Vernooij
Yet more bees.
285
        self.build_tree_contents([('.bzrignore', b'*.~*\n')])
1765.1.1 by Robert Collins
Remove the default ignores list from bzr, lowering the minimum overhead in bzr add.
286
        tree.add('.bzrignore')
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
287
        self.assertEqual(list(tree.unknowns()),
7143.15.2 by Jelmer Vernooij
Run autopep8.
288
                         ['hello.txt'])
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
289
7199.3.1 by Jelmer Vernooij
Don't report empty directories as changes.
290
    def test_unknowns_empty_dir(self):
291
        tree = self.make_branch_and_tree('.')
292
        self.build_tree(['subdir/', 'subdir/somefile'])
293
        if tree.has_versioned_directories():
294
            self.assertEqual(list(tree.unknowns()), ['subdir'])
295
        else:
296
            self.assertEqual(list(tree.unknowns()), ['subdir/somefile'])
297
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
298
    def test_initialize(self):
299
        # initialize should create a working tree and branch in an existing dir
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
300
        t = self.make_branch_and_tree('.')
7447.3.1 by Jelmer Vernooij
Move tree reference info functions to workingtree.
301
        b = _mod_branch.Branch.open('.')
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
302
        self.assertEqual(t.branch.base, b.base)
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
303
        t2 = WorkingTree.open('.')
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
304
        self.assertEqual(t.basedir, t2.basedir)
305
        self.assertEqual(b.base, t2.branch.base)
306
        # TODO maybe we should check the branch format? not sure if its
307
        # appropriate here.
308
309
    def test_rename_dirs(self):
310
        """Test renaming directories and the files within them."""
311
        wt = self.make_branch_and_tree('.')
312
        b = wt.branch
313
        self.build_tree(['dir/', 'dir/sub/', 'dir/sub/file'])
314
        wt.add(['dir', 'dir/sub', 'dir/sub/file'])
315
316
        wt.commit('create initial state')
317
6165.4.4 by Jelmer Vernooij
Avoid .revision_history().
318
        revid = b.last_revision()
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
319
        self.log('first revision_id is {%s}' % revid)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
320
5807.1.5 by Jelmer Vernooij
Fix more things to use tree objects.
321
        tree = b.repository.revision_tree(revid)
322
        self.log('contents of tree: %r' % list(tree.iter_entries_by_dir()))
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
323
5807.1.5 by Jelmer Vernooij
Fix more things to use tree objects.
324
        self.check_tree_shape(tree, ['dir/', 'dir/sub/', 'dir/sub/file'])
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
325
        wt.rename_one('dir', 'newdir')
326
2255.2.57 by Robert Collins
Dirstate test change: TestWorkingTree.test_rename_dirs should lock around accessing the trees inventory.
327
        wt.lock_read()
5807.1.5 by Jelmer Vernooij
Fix more things to use tree objects.
328
        self.check_tree_shape(wt,
7143.15.2 by Jelmer Vernooij
Run autopep8.
329
                              ['newdir/', 'newdir/sub/', 'newdir/sub/file'])
2255.2.57 by Robert Collins
Dirstate test change: TestWorkingTree.test_rename_dirs should lock around accessing the trees inventory.
330
        wt.unlock()
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
331
        wt.rename_one('newdir/sub', 'newdir/newsub')
2255.2.57 by Robert Collins
Dirstate test change: TestWorkingTree.test_rename_dirs should lock around accessing the trees inventory.
332
        wt.lock_read()
5807.1.5 by Jelmer Vernooij
Fix more things to use tree objects.
333
        self.check_tree_shape(wt, ['newdir/', 'newdir/newsub/',
7143.15.2 by Jelmer Vernooij
Run autopep8.
334
                                   'newdir/newsub/file'])
2255.2.57 by Robert Collins
Dirstate test change: TestWorkingTree.test_rename_dirs should lock around accessing the trees inventory.
335
        wt.unlock()
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
336
337
    def test_add_in_unversioned(self):
338
        """Try to add a file in an unversioned directory.
339
340
        "bzr add" adds the parent as necessary, but simple working tree add
341
        doesn't do that.
342
        """
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
343
        from breezy.errors import NotVersionedError
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
344
        wt = self.make_branch_and_tree('.')
345
        self.build_tree(['foo/',
346
                         'foo/hello'])
6072.1.2 by Jelmer Vernooij
Fix versioned directories tests.
347
        if not wt._format.supports_versioned_directories:
6072.1.1 by Jelmer Vernooij
Various fixes for tests of foreign plugins.
348
            wt.add('foo/hello')
349
        else:
350
            self.assertRaises(NotVersionedError,
351
                              wt.add,
352
                              'foo/hello')
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
353
354
    def test_add_missing(self):
355
        # adding a msising file -> NoSuchFile
356
        wt = self.make_branch_and_tree('.')
357
        self.assertRaises(errors.NoSuchFile, wt.add, 'fpp')
358
359
    def test_remove_verbose(self):
7143.15.2 by Jelmer Vernooij
Run autopep8.
360
        # FIXME the remove api should not print or otherwise depend on the
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
361
        # text UI - RBC 20060124
362
        wt = self.make_branch_and_tree('.')
363
        self.build_tree(['hello'])
364
        wt.add(['hello'])
365
        wt.commit(message='add hello')
7045.4.4 by Jelmer Vernooij
Fix more git tests.
366
        stdout = StringIO()
367
        stderr = StringIO()
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
368
        self.assertEqual(None, self.apply_redirected(None, stdout, stderr,
369
                                                     wt.remove,
370
                                                     ['hello'],
371
                                                     verbose=True))
372
        self.assertEqual('?       hello\n', stdout.getvalue())
373
        self.assertEqual('', stderr.getvalue())
374
375
    def test_clone_trivial(self):
376
        wt = self.make_branch_and_tree('source')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
377
        cloned_dir = wt.controldir.clone('target')
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
378
        cloned = cloned_dir.open_workingtree()
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
379
        self.assertEqual(cloned.get_parent_ids(), wt.get_parent_ids())
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
380
6241.3.1 by Jelmer Vernooij
Support WorkingTree.clone() having its revision argument set to the NULL revision.
381
    def test_clone_empty(self):
382
        wt = self.make_branch_and_tree('source')
7143.15.2 by Jelmer Vernooij
Run autopep8.
383
        cloned_dir = wt.controldir.clone(
384
            'target', revision_id=_mod_revision.NULL_REVISION)
6241.3.1 by Jelmer Vernooij
Support WorkingTree.clone() having its revision argument set to the NULL revision.
385
        cloned = cloned_dir.open_workingtree()
386
        self.assertEqual(cloned.get_parent_ids(), wt.get_parent_ids())
387
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
388
    def test_last_revision(self):
389
        wt = self.make_branch_and_tree('source')
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
390
        self.assertEqual([], wt.get_parent_ids())
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
391
        a = wt.commit('A', allow_pointless=True)
2249.5.7 by John Arbash Meinel
Make sure WorkingTree revision_ids are also returned as utf8 strings
392
        parent_ids = wt.get_parent_ids()
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
393
        self.assertEqual([a], parent_ids)
2249.5.7 by John Arbash Meinel
Make sure WorkingTree revision_ids are also returned as utf8 strings
394
        for parent_id in parent_ids:
7018.3.2 by Jelmer Vernooij
Fix some git tests.
395
            self.assertIsInstance(parent_id, bytes)
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
396
397
    def test_set_last_revision(self):
398
        wt = self.make_branch_and_tree('source')
1908.1.1 by Robert Collins
Relax WorkingTree.set_last-revision to allow any revision to be set.
399
        # set last-revision to one not in the history
6844.1.1 by Jelmer Vernooij
Many more foreign branch fixes.
400
        if wt.branch.repository._format.supports_ghosts:
6973.10.6 by Jelmer Vernooij
Fix tests.
401
            wt.set_last_revision(b'A')
1908.1.1 by Robert Collins
Relax WorkingTree.set_last-revision to allow any revision to be set.
402
        # set it back to None for an empty tree.
6973.10.6 by Jelmer Vernooij
Fix tests.
403
        wt.set_last_revision(b'null:')
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
404
        a = wt.commit('A', allow_pointless=True)
6747.2.2 by Jelmer Vernooij
Fix tests.
405
        self.assertEqual([a], wt.get_parent_ids())
6498.3.4 by Jelmer Vernooij
Remove more .set_revision_history / .revision_history references.
406
        # null: is aways in the branch
6973.10.6 by Jelmer Vernooij
Fix tests.
407
        wt.set_last_revision(b'null:')
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
408
        self.assertEqual([], wt.get_parent_ids())
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
409
        # and now we can set it to 'A'
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
410
        # because some formats mutate the branch to set it on the tree
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
411
        # we need to alter the branch to let this pass.
6498.3.4 by Jelmer Vernooij
Remove more .set_revision_history / .revision_history references.
412
        if getattr(wt.branch, "_set_revision_history", None) is None:
2230.3.27 by Aaron Bentley
Skip arbitrary revision-history test for Branch6
413
            raise TestSkipped("Branch format does not permit arbitrary"
414
                              " history")
6973.10.6 by Jelmer Vernooij
Fix tests.
415
        wt.branch._set_revision_history([a, b'B'])
6747.2.2 by Jelmer Vernooij
Fix tests.
416
        wt.set_last_revision(a)
417
        self.assertEqual([a], wt.get_parent_ids())
6973.10.6 by Jelmer Vernooij
Fix tests.
418
        self.assertRaises(errors.ReservedId, wt.set_last_revision, b'A:')
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
419
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
420
    def test_set_last_revision_different_to_branch(self):
421
        # working tree formats from the meta-dir format and newer support
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
422
        # setting the last revision on a tree independently of that on the
423
        # branch. Its concievable that some future formats may want to
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
424
        # couple them again (i.e. because its really a smart server and
425
        # the working tree will always match the branch). So we test
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
426
        # that formats where initialising a branch does not initialise a
427
        # tree - and thus have separable entities - support skewing the
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
428
        # two things.
6437.70.7 by John Arbash Meinel
one more test that wanted to have a branch reference
429
        self.requireBranchReference()
430
        wt = self.make_branch_and_tree('tree')
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
431
        a = wt.commit('A', allow_pointless=True)
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
432
        wt.set_last_revision(None)
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
433
        self.assertEqual([], wt.get_parent_ids())
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
434
        self.assertEqual(a, wt.branch.last_revision())
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
435
        # and now we can set it back to 'A'
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
436
        wt.set_last_revision(a)
437
        self.assertEqual([a], wt.get_parent_ids())
438
        self.assertEqual(a, wt.branch.last_revision())
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
439
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
440
    def test_clone_and_commit_preserves_last_revision(self):
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
441
        """Doing a commit into a clone tree does not affect the source."""
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
442
        wt = self.make_branch_and_tree('source')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
443
        cloned_dir = wt.controldir.clone('target')
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
444
        wt.commit('A', allow_pointless=True)
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
445
        self.assertNotEqual(cloned_dir.open_workingtree().get_parent_ids(),
446
                            wt.get_parent_ids())
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
447
448
    def test_clone_preserves_content(self):
449
        wt = self.make_branch_and_tree('source')
2255.2.51 by John Arbash Meinel
simple rewrap for 79 char lines
450
        self.build_tree(['added', 'deleted', 'notadded'],
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
451
                        transport=wt.controldir.transport.clone('..'))
6829.2.1 by Jelmer Vernooij
Avoid passing in file_ids/revision_ids in a few more places.
452
        wt.add('deleted')
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
453
        wt.commit('add deleted')
454
        wt.remove('deleted')
6829.2.1 by Jelmer Vernooij
Avoid passing in file_ids/revision_ids in a few more places.
455
        wt.add('added')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
456
        cloned_dir = wt.controldir.clone('target')
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
457
        cloned = cloned_dir.open_workingtree()
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
458
        cloned_transport = cloned.controldir.transport.clone('..')
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
459
        self.assertFalse(cloned_transport.has('deleted'))
460
        self.assertTrue(cloned_transport.has('added'))
461
        self.assertFalse(cloned_transport.has('notadded'))
6852.3.1 by Jelmer Vernooij
add Tree.is_versioned.
462
        self.assertTrue(cloned.is_versioned('added'))
463
        self.assertFalse(cloned.is_versioned('deleted'))
464
        self.assertFalse(cloned.is_versioned('notadded'))
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
465
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
466
    def test_basis_tree_returns_last_revision(self):
467
        wt = self.make_branch_and_tree('.')
468
        self.build_tree(['foo'])
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
469
        wt.add('foo')
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
470
        a = wt.commit('A')
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
471
        wt.rename_one('foo', 'bar')
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
472
        b = wt.commit('B')
473
        wt.set_parent_ids([b])
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
474
        tree = wt.basis_tree()
2255.2.30 by Robert Collins
Some workingtree_implementations/test_workingtree.py test work - add DirStateRevisionTree.has_filename, locks around appropriate calls in tests.
475
        tree.lock_read()
5784.1.1 by Martin Pool
Stop using failIf, failUnless, etc
476
        self.assertTrue(tree.has_filename('bar'))
2255.2.30 by Robert Collins
Some workingtree_implementations/test_workingtree.py test work - add DirStateRevisionTree.has_filename, locks around appropriate calls in tests.
477
        tree.unlock()
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
478
        wt.set_parent_ids([a])
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
479
        tree = wt.basis_tree()
2255.2.30 by Robert Collins
Some workingtree_implementations/test_workingtree.py test work - add DirStateRevisionTree.has_filename, locks around appropriate calls in tests.
480
        tree.lock_read()
5784.1.1 by Martin Pool
Stop using failIf, failUnless, etc
481
        self.assertTrue(tree.has_filename('foo'))
2255.2.30 by Robert Collins
Some workingtree_implementations/test_workingtree.py test work - add DirStateRevisionTree.has_filename, locks around appropriate calls in tests.
482
        tree.unlock()
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
483
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
484
    def test_clone_tree_revision(self):
485
        # make a tree with a last-revision,
486
        # and clone it with a different last-revision, this should switch
487
        # do it.
488
        #
489
        # also test that the content is merged
490
        # and conflicts recorded.
491
        # This should merge between the trees - local edits should be preserved
492
        # but other changes occured.
493
        # we test this by having one file that does
494
        # not change between two revisions, and another that does -
495
        # if the changed one is not changed, fail,
496
        # if the one that did not change has lost a local change, fail.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
497
        #
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
498
        raise TestSkipped('revision limiting is not implemented yet.')
1508.1.21 by Robert Collins
Implement -r limit for checkout command.
499
500
    def test_initialize_with_revision_id(self):
501
        # a bzrdir can construct a working tree for itself @ a specific revision.
502
        source = self.make_branch_and_tree('source')
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
503
        a = source.commit('a', allow_pointless=True)
504
        source.commit('b', allow_pointless=True)
1508.1.21 by Robert Collins
Implement -r limit for checkout command.
505
        self.build_tree(['new/'])
506
        made_control = self.bzrdir_format.initialize('new')
507
        source.branch.repository.clone(made_control)
508
        source.branch.clone(made_control)
5051.3.10 by Jelmer Vernooij
Pass colocated branch name around in more places.
509
        made_tree = self.workingtree_format.initialize(made_control,
7143.15.2 by Jelmer Vernooij
Run autopep8.
510
                                                       revision_id=a)
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
511
        self.assertEqual([a], made_tree.get_parent_ids())
1508.1.23 by Robert Collins
Test that the working tree last revision is indeed set during commit.
512
6435.1.1 by Jelmer Vernooij
Add post_build_tree hook.
513
    def test_post_build_tree_hook(self):
514
        calls = []
7143.15.2 by Jelmer Vernooij
Run autopep8.
515
6435.1.1 by Jelmer Vernooij
Add post_build_tree hook.
516
        def track_post_build_tree(tree):
517
            calls.append(tree.last_revision())
518
        source = self.make_branch_and_tree('source')
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
519
        a = source.commit('a', allow_pointless=True)
520
        source.commit('b', allow_pointless=True)
6435.1.2 by Jelmer Vernooij
Fix test against wt2.
521
        self.build_tree(['new/'])
522
        made_control = self.bzrdir_format.initialize('new')
523
        source.branch.repository.clone(made_control)
524
        source.branch.clone(made_control)
6435.1.1 by Jelmer Vernooij
Add post_build_tree hook.
525
        MutableTree.hooks.install_named_hook("post_build_tree",
7143.15.2 by Jelmer Vernooij
Run autopep8.
526
                                             track_post_build_tree, "Test")
6435.1.1 by Jelmer Vernooij
Add post_build_tree hook.
527
        made_tree = self.workingtree_format.initialize(made_control,
7143.15.2 by Jelmer Vernooij
Run autopep8.
528
                                                       revision_id=a)
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
529
        self.assertEqual([a], calls)
6435.1.1 by Jelmer Vernooij
Add post_build_tree hook.
530
1508.1.24 by Robert Collins
Add update command for use with checkouts.
531
    def test_update_sets_last_revision(self):
532
        # working tree formats from the meta-dir format and newer support
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
533
        # setting the last revision on a tree independently of that on the
534
        # branch. Its concievable that some future formats may want to
1508.1.24 by Robert Collins
Add update command for use with checkouts.
535
        # couple them again (i.e. because its really a smart server and
536
        # the working tree will always match the branch). So we test
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
537
        # that formats where initialising a branch does not initialise a
538
        # tree - and thus have separable entities - support skewing the
1508.1.24 by Robert Collins
Add update command for use with checkouts.
539
        # two things.
6437.70.14 by John Arbash Meinel
Finish bug #1046697 and run all per_workingtree tests against a checkout.
540
        self.requireBranchReference()
6437.70.6 by John Arbash Meinel
Fix a couple tests that wanted to directly create a wt where the branch was.
541
        wt = self.make_branch_and_tree('tree')
1508.1.24 by Robert Collins
Add update command for use with checkouts.
542
        # create an out of date working tree by making a checkout in this
543
        # current format
544
        self.build_tree(['checkout/', 'tree/file'])
545
        checkout = bzrdir.BzrDirMetaFormat1().initialize('checkout')
6437.70.6 by John Arbash Meinel
Fix a couple tests that wanted to directly create a wt where the branch was.
546
        checkout.set_branch_reference(wt.branch)
1508.1.24 by Robert Collins
Add update command for use with checkouts.
547
        old_tree = self.workingtree_format.initialize(checkout)
548
        # now commit to 'tree'
549
        wt.add('file')
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
550
        a = wt.commit('A')
1508.1.24 by Robert Collins
Add update command for use with checkouts.
551
        # and update old_tree
552
        self.assertEqual(0, old_tree.update())
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
553
        self.assertPathExists('checkout/file')
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
554
        self.assertEqual([a], old_tree.get_parent_ids())
1508.1.24 by Robert Collins
Add update command for use with checkouts.
555
1731.1.33 by Aaron Bentley
Revert no-special-root changes
556
    def test_update_sets_root_id(self):
557
        """Ensure tree root is set properly by update.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
558
1731.1.33 by Aaron Bentley
Revert no-special-root changes
559
        Since empty trees don't have root_ids, but workingtrees do,
560
        an update of a checkout of revision 0 to a new revision,  should set
561
        the root id.
562
        """
563
        wt = self.make_branch_and_tree('tree')
564
        main_branch = wt.branch
565
        # create an out of date working tree by making a checkout in this
566
        # current format
567
        self.build_tree(['checkout/', 'tree/file'])
1731.1.43 by Aaron Bentley
Merge more checkout changes
568
        checkout = main_branch.create_checkout('checkout')
1731.1.33 by Aaron Bentley
Revert no-special-root changes
569
        # now commit to 'tree'
570
        wt.add('file')
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
571
        a = wt.commit('A')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
572
        # and update checkout
1731.1.33 by Aaron Bentley
Revert no-special-root changes
573
        self.assertEqual(0, checkout.update())
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
574
        self.assertPathExists('checkout/file')
7358.14.1 by Jelmer Vernooij
Remove Tree.get_root_id() in favour of Tree.path2id('').
575
        self.assertEqual(wt.path2id(''), checkout.path2id(''))
576
        self.assertNotEqual(None, wt.path2id(''))
1731.1.33 by Aaron Bentley
Revert no-special-root changes
577
4634.123.1 by John Arbash Meinel
Add a failing test for 'update'. When this branch lands, update should work.
578
    def test_update_sets_updated_root_id(self):
579
        wt = self.make_branch_and_tree('tree')
6793.4.1 by Jelmer Vernooij
Improve set_root_id handling.
580
        if not wt._format.supports_setting_file_ids:
581
            self.assertRaises(SettingFileIdUnsupported, wt.set_root_id,
7143.15.2 by Jelmer Vernooij
Run autopep8.
582
                              'first_root_id')
6793.4.1 by Jelmer Vernooij
Improve set_root_id handling.
583
            return
6855.4.1 by Jelmer Vernooij
Yet more bees.
584
        wt.set_root_id(b'first_root_id')
7358.14.1 by Jelmer Vernooij
Remove Tree.get_root_id() in favour of Tree.path2id('').
585
        self.assertEqual(b'first_root_id', wt.path2id(''))
4634.123.1 by John Arbash Meinel
Add a failing test for 'update'. When this branch lands, update should work.
586
        self.build_tree(['tree/file'])
587
        wt.add(['file'])
588
        wt.commit('first')
589
        co = wt.branch.create_checkout('checkout')
6855.4.1 by Jelmer Vernooij
Yet more bees.
590
        wt.set_root_id(b'second_root_id')
4634.123.1 by John Arbash Meinel
Add a failing test for 'update'. When this branch lands, update should work.
591
        wt.commit('second')
7358.14.1 by Jelmer Vernooij
Remove Tree.get_root_id() in favour of Tree.path2id('').
592
        self.assertEqual(b'second_root_id', wt.path2id(''))
4634.123.1 by John Arbash Meinel
Add a failing test for 'update'. When this branch lands, update should work.
593
        self.assertEqual(0, co.update())
7358.14.1 by Jelmer Vernooij
Remove Tree.get_root_id() in favour of Tree.path2id('').
594
        self.assertEqual(b'second_root_id', co.path2id(''))
4634.123.1 by John Arbash Meinel
Add a failing test for 'update'. When this branch lands, update should work.
595
1508.1.24 by Robert Collins
Add update command for use with checkouts.
596
    def test_update_returns_conflict_count(self):
597
        # working tree formats from the meta-dir format and newer support
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
598
        # setting the last revision on a tree independently of that on the
599
        # branch. Its concievable that some future formats may want to
1508.1.24 by Robert Collins
Add update command for use with checkouts.
600
        # couple them again (i.e. because its really a smart server and
601
        # the working tree will always match the branch). So we test
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
602
        # that formats where initialising a branch does not initialise a
603
        # tree - and thus have separable entities - support skewing the
1508.1.24 by Robert Collins
Add update command for use with checkouts.
604
        # two things.
6437.70.6 by John Arbash Meinel
Fix a couple tests that wanted to directly create a wt where the branch was.
605
        self.requireBranchReference()
606
        wt = self.make_branch_and_tree('tree')
1508.1.24 by Robert Collins
Add update command for use with checkouts.
607
        # create an out of date working tree by making a checkout in this
608
        # current format
609
        self.build_tree(['checkout/', 'tree/file'])
610
        checkout = bzrdir.BzrDirMetaFormat1().initialize('checkout')
6437.70.6 by John Arbash Meinel
Fix a couple tests that wanted to directly create a wt where the branch was.
611
        checkout.set_branch_reference(wt.branch)
1508.1.24 by Robert Collins
Add update command for use with checkouts.
612
        old_tree = self.workingtree_format.initialize(checkout)
613
        # now commit to 'tree'
614
        wt.add('file')
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
615
        a = wt.commit('A')
1508.1.24 by Robert Collins
Add update command for use with checkouts.
616
        # and add a file file to the checkout
617
        self.build_tree(['checkout/file'])
618
        old_tree.add('file')
619
        # and update old_tree
620
        self.assertEqual(1, old_tree.update())
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
621
        self.assertEqual([a], old_tree.get_parent_ids())
1508.1.24 by Robert Collins
Add update command for use with checkouts.
622
1534.7.199 by Aaron Bentley
Moved merge/revert tests into test_workingtree.py
623
    def test_merge_revert(self):
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
624
        from breezy.merge import merge_inner
1534.7.199 by Aaron Bentley
Moved merge/revert tests into test_workingtree.py
625
        this = self.make_branch_and_tree('b1')
7143.15.2 by Jelmer Vernooij
Run autopep8.
626
        self.build_tree_contents(
627
            [('b1/a', b'a test\n'), ('b1/b', b'b test\n')])
4789.12.1 by John Arbash Meinel
Fix per_workingtree.test_workingtree.test_merge_revert
628
        this.add(['a', 'b'])
1534.7.199 by Aaron Bentley
Moved merge/revert tests into test_workingtree.py
629
        this.commit(message='')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
630
        base = this.controldir.clone('b2').open_workingtree()
6855.4.1 by Jelmer Vernooij
Yet more bees.
631
        self.build_tree_contents([('b2/a', b'b test\n')])
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
632
        other = this.controldir.clone('b3').open_workingtree()
7143.15.2 by Jelmer Vernooij
Run autopep8.
633
        self.build_tree_contents(
634
            [('b3/a', b'c test\n'), ('b3/c', b'c test\n')])
1534.7.199 by Aaron Bentley
Moved merge/revert tests into test_workingtree.py
635
        other.add('c')
636
7143.15.2 by Jelmer Vernooij
Run autopep8.
637
        self.build_tree_contents(
638
            [('b1/b', b'q test\n'), ('b1/d', b'd test\n')])
4789.12.1 by John Arbash Meinel
Fix per_workingtree.test_workingtree.test_merge_revert
639
        # Note: If we don't lock this before calling merge_inner, then we get a
640
        #       lock-contention failure. This probably indicates something
641
        #       weird going on inside merge_inner. Probably something about
642
        #       calling bt = this_tree.basis_tree() in one lock, and then
643
        #       locking both this_tree and bt separately, causing a dirstate
644
        #       locking race.
645
        this.lock_write()
646
        self.addCleanup(this.unlock)
1534.7.199 by Aaron Bentley
Moved merge/revert tests into test_workingtree.py
647
        merge_inner(this.branch, other, base, this_tree=this)
7029.4.2 by Jelmer Vernooij
Fix more merge tests.
648
        with open('b1/a', 'rb') as a:
4789.12.1 by John Arbash Meinel
Fix per_workingtree.test_workingtree.test_merge_revert
649
            self.assertNotEqual(a.read(), 'a test\n')
2748.3.2 by Aaron Bentley
Fix revert, remove-tree, and various tests to use None for 'no files specified'
650
        this.revert()
7029.4.2 by Jelmer Vernooij
Fix more merge tests.
651
        self.assertFileEqual(b'a test\n', 'b1/a')
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
652
        self.assertPathExists('b1/b.~1~')
6947.2.1 by Jelmer Vernooij
Don't expect unmodified files to be removed when a merge is reverted on working trees that don't support merge_modified.
653
        if this.supports_merge_modified():
654
            self.assertPathDoesNotExist('b1/c')
655
            self.assertPathDoesNotExist('b1/a.~1~')
656
        else:
657
            self.assertPathExists('b1/c')
658
            self.assertPathExists('b1/a.~1~')
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
659
        self.assertPathExists('b1/d')
1534.7.200 by Aaron Bentley
Merge from mainline
660
1587.1.10 by Robert Collins
update updates working tree and branch together.
661
    def test_update_updates_bound_branch_no_local_commits(self):
662
        # doing an update in a tree updates the branch its bound to too.
663
        master_tree = self.make_branch_and_tree('master')
664
        tree = self.make_branch_and_tree('tree')
665
        try:
666
            tree.branch.bind(master_tree.branch)
667
        except errors.UpgradeRequired:
668
            # legacy branches cannot bind
669
            return
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
670
        foo = master_tree.commit('foo', allow_pointless=True)
1587.1.10 by Robert Collins
update updates working tree and branch together.
671
        tree.update()
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
672
        self.assertEqual([foo], tree.get_parent_ids())
673
        self.assertEqual(foo, tree.branch.last_revision())
1587.1.11 by Robert Collins
Local commits appear to be working properly.
674
675
    def test_update_turns_local_commit_into_merge(self):
676
        # doing an update with a few local commits and no master commits
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
677
        # makes pending-merges.
1587.1.13 by Robert Collins
Explain why update pivots more clearly in the relevant test.
678
        # this is done so that 'bzr update; bzr revert' will always produce
679
        # an exact copy of the 'logical branch' - the referenced branch for
680
        # a checkout, and the master for a bound branch.
681
        # its possible that we should instead have 'bzr update' when there
682
        # is nothing new on the master leave the current commits intact and
683
        # alter 'revert' to revert to the master always. But for now, its
684
        # good.
1587.1.11 by Robert Collins
Local commits appear to be working properly.
685
        master_tree = self.make_branch_and_tree('master')
1927.2.1 by Robert Collins
Alter set_pending_merges to shove the left most merge into the trees last-revision if that is not set. Related bugfixes include basis_tree handling ghosts, de-duping the merges with the last-revision and update changing where and how it adds its pending merge.
686
        master_tip = master_tree.commit('first master commit')
1587.1.11 by Robert Collins
Local commits appear to be working properly.
687
        tree = self.make_branch_and_tree('tree')
688
        try:
689
            tree.branch.bind(master_tree.branch)
690
        except errors.UpgradeRequired:
691
            # legacy branches cannot bind
692
            return
1927.2.1 by Robert Collins
Alter set_pending_merges to shove the left most merge into the trees last-revision if that is not set. Related bugfixes include basis_tree handling ghosts, de-duping the merges with the last-revision and update changing where and how it adds its pending merge.
693
        # sync with master
694
        tree.update()
695
        # work locally
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
696
        tree.commit('foo', allow_pointless=True, local=True)
697
        bar = tree.commit('bar', allow_pointless=True, local=True)
1927.2.1 by Robert Collins
Alter set_pending_merges to shove the left most merge into the trees last-revision if that is not set. Related bugfixes include basis_tree handling ghosts, de-duping the merges with the last-revision and update changing where and how it adds its pending merge.
698
        # sync with master prepatory to committing
1587.1.11 by Robert Collins
Local commits appear to be working properly.
699
        tree.update()
1927.2.1 by Robert Collins
Alter set_pending_merges to shove the left most merge into the trees last-revision if that is not set. Related bugfixes include basis_tree handling ghosts, de-duping the merges with the last-revision and update changing where and how it adds its pending merge.
700
        # which should have pivoted the local tip into a merge
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
701
        self.assertEqual([master_tip, bar], tree.get_parent_ids())
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
702
        # and the local branch history should match the masters now.
6165.4.4 by Jelmer Vernooij
Avoid .revision_history().
703
        self.assertEqual(master_tree.branch.last_revision(),
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
704
                         tree.branch.last_revision())
1587.1.11 by Robert Collins
Local commits appear to be working properly.
705
4916.1.7 by Martin Pool
Add per_workingtree test you can update to arbitrary revisions
706
    def test_update_takes_revision_parameter(self):
707
        wt = self.make_branch_and_tree('wt')
6855.4.1 by Jelmer Vernooij
Yet more bees.
708
        self.build_tree_contents([('wt/a', b'old content')])
4916.1.7 by Martin Pool
Add per_workingtree test you can update to arbitrary revisions
709
        wt.add(['a'])
710
        rev1 = wt.commit('first master commit')
6855.4.1 by Jelmer Vernooij
Yet more bees.
711
        self.build_tree_contents([('wt/a', b'new content')])
4916.1.7 by Martin Pool
Add per_workingtree test you can update to arbitrary revisions
712
        rev2 = wt.commit('second master commit')
5243.1.2 by Martin
Point launchpad links in comments at production server rather than edge
713
        # https://bugs.launchpad.net/bzr/+bug/45719/comments/20
4916.1.7 by Martin Pool
Add per_workingtree test you can update to arbitrary revisions
714
        # when adding 'update -r' we should make sure all wt formats support
715
        # it
716
        conflicts = wt.update(revision=rev1)
7029.4.2 by Jelmer Vernooij
Fix more merge tests.
717
        self.assertFileEqual(b'old content', 'wt/a')
4916.1.7 by Martin Pool
Add per_workingtree test you can update to arbitrary revisions
718
        self.assertEqual([rev1], wt.get_parent_ids())
719
2255.2.156 by Martin Pool
Merge WorkingTree implementation back from trunk
720
    def test_merge_modified_detects_corruption(self):
721
        # FIXME: This doesn't really test that it works; also this is not
722
        # implementation-independent. mbp 20070226
1558.3.3 by Aaron Bentley
Fix error handling for merge_modified
723
        tree = self.make_branch_and_tree('master')
6072.1.1 by Jelmer Vernooij
Various fixes for tests of foreign plugins.
724
        if not isinstance(tree, InventoryWorkingTree):
725
            raise TestNotApplicable("merge-hashes is specific to bzr "
7143.15.2 by Jelmer Vernooij
Run autopep8.
726
                                    "working trees")
7029.4.2 by Jelmer Vernooij
Fix more merge tests.
727
        tree._transport.put_bytes('merge-hashes', b'asdfasdf')
1558.3.3 by Aaron Bentley
Fix error handling for merge_modified
728
        self.assertRaises(errors.MergeModifiedFormatError, tree.merge_modified)
1534.10.8 by Aaron Bentley
Implemented conflict_lines in terms of old system on WorkingTree
729
2298.1.1 by Martin Pool
Add test for merge_modified
730
    def test_merge_modified(self):
731
        # merge_modified stores a map from file id to hash
732
        tree = self.make_branch_and_tree('tree')
6855.4.1 by Jelmer Vernooij
Yet more bees.
733
        self.build_tree_contents([('tree/somefile', b'hello')])
6852.3.1 by Jelmer Vernooij
add Tree.is_versioned.
734
        with tree.lock_write():
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
735
            tree.add(['somefile'])
7350.4.1 by Jelmer Vernooij
Use paths as keys in merge modified dictionaries.
736
            d = {'somefile': osutils.sha_string(b'hello')}
6885.2.1 by Jelmer Vernooij
Add WorkingTree.supports_merge_modified.
737
            if tree.supports_merge_modified():
6862.6.1 by Jelmer Vernooij
Allow working trees to not implement set_merge_modified.
738
                tree.set_merge_modified(d)
6885.2.1 by Jelmer Vernooij
Add WorkingTree.supports_merge_modified.
739
                mm = tree.merge_modified()
740
                self.assertEqual(mm, d)
741
            else:
742
                self.assertRaises(
743
                    errors.UnsupportedOperation,
744
                    tree.set_merge_modified, d)
6862.6.1 by Jelmer Vernooij
Allow working trees to not implement set_merge_modified.
745
                mm = tree.merge_modified()
746
                self.assertEqual(mm, {})
6885.2.1 by Jelmer Vernooij
Add WorkingTree.supports_merge_modified.
747
        if tree.supports_merge_modified():
2298.1.1 by Martin Pool
Add test for merge_modified
748
            mm = tree.merge_modified()
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
749
            self.assertEqual(mm, d)
6862.6.1 by Jelmer Vernooij
Allow working trees to not implement set_merge_modified.
750
        else:
751
            mm = tree.merge_modified()
752
            self.assertEqual(mm, {})
2298.1.1 by Martin Pool
Add test for merge_modified
753
1534.10.22 by Aaron Bentley
Got ConflictList implemented
754
    def test_conflicts(self):
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
755
        from breezy.tests.test_conflicts import example_conflicts
1534.10.8 by Aaron Bentley
Implemented conflict_lines in terms of old system on WorkingTree
756
        tree = self.make_branch_and_tree('master')
757
        try:
1534.10.22 by Aaron Bentley
Got ConflictList implemented
758
            tree.set_conflicts(example_conflicts)
1534.10.8 by Aaron Bentley
Implemented conflict_lines in terms of old system on WorkingTree
759
        except UnsupportedOperation:
1534.10.22 by Aaron Bentley
Got ConflictList implemented
760
            raise TestSkipped('set_conflicts not supported')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
761
1534.10.8 by Aaron Bentley
Implemented conflict_lines in terms of old system on WorkingTree
762
        tree2 = WorkingTree.open('master')
1534.10.22 by Aaron Bentley
Got ConflictList implemented
763
        self.assertEqual(tree2.conflicts(), example_conflicts)
7029.4.2 by Jelmer Vernooij
Fix more merge tests.
764
        tree2._transport.put_bytes('conflicts', b'')
3407.2.7 by Martin Pool
Deprecate LockableFiles.put_utf8 and put_bytes.
765
        self.assertRaises(errors.ConflictFormatError,
1955.3.14 by John Arbash Meinel
Correctly fix the workingtree put() test fixes
766
                          tree2.conflicts)
7029.4.2 by Jelmer Vernooij
Fix more merge tests.
767
        tree2._transport.put_bytes('conflicts', b'a')
3407.2.7 by Martin Pool
Deprecate LockableFiles.put_utf8 and put_bytes.
768
        self.assertRaises(errors.ConflictFormatError,
1955.3.14 by John Arbash Meinel
Correctly fix the workingtree put() test fixes
769
                          tree2.conflicts)
1534.10.12 by Aaron Bentley
Merge produces new conflicts
770
771
    def make_merge_conflicts(self):
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
772
        from breezy.merge import merge_inner
1534.10.12 by Aaron Bentley
Merge produces new conflicts
773
        tree = self.make_branch_and_tree('mine')
7143.15.2 by Jelmer Vernooij
Run autopep8.
774
        with open('mine/bloo', 'wb') as f:
775
            f.write(b'one')
776
        with open('mine/blo', 'wb') as f:
777
            f.write(b'on')
2255.2.32 by Robert Collins
Make test_clear_merge_conflicts pass for dirstate. This involved working
778
        tree.add(['bloo', 'blo'])
1534.10.12 by Aaron Bentley
Merge produces new conflicts
779
        tree.commit("blah", allow_pointless=False)
2255.5.3 by John Arbash Meinel
XXX Workaround the DirStateRevisionTree bug until we get a proper fix, tests pass again
780
        base = tree.branch.repository.revision_tree(tree.last_revision())
6472.2.2 by Jelmer Vernooij
Use controldir rather than bzrdir in a couple more places.
781
        controldir.ControlDir.open("mine").sprout("other")
7143.15.2 by Jelmer Vernooij
Run autopep8.
782
        with open('other/bloo', 'wb') as f:
783
            f.write(b'two')
1534.10.12 by Aaron Bentley
Merge produces new conflicts
784
        othertree = WorkingTree.open('other')
785
        othertree.commit('blah', allow_pointless=False)
7143.15.2 by Jelmer Vernooij
Run autopep8.
786
        with open('mine/bloo', 'wb') as f:
787
            f.write(b'three')
1534.10.12 by Aaron Bentley
Merge produces new conflicts
788
        tree.commit("blah", allow_pointless=False)
789
        merge_inner(tree.branch, othertree, base, this_tree=tree)
790
        return tree
791
792
    def test_merge_conflicts(self):
793
        tree = self.make_merge_conflicts()
1534.10.22 by Aaron Bentley
Got ConflictList implemented
794
        self.assertEqual(len(tree.conflicts()), 1)
1534.10.12 by Aaron Bentley
Merge produces new conflicts
795
796
    def test_clear_merge_conflicts(self):
797
        tree = self.make_merge_conflicts()
1534.10.22 by Aaron Bentley
Got ConflictList implemented
798
        self.assertEqual(len(tree.conflicts()), 1)
1534.10.12 by Aaron Bentley
Merge produces new conflicts
799
        try:
7490.129.3 by Jelmer Vernooij
Split out bzr-specific Conflicts code.
800
            tree.set_conflicts([])
1534.10.12 by Aaron Bentley
Merge produces new conflicts
801
        except UnsupportedOperation:
2949.5.1 by Alexander Belchenko
selftest: use SymlinkFeature instead of TestSkipped where appropriate
802
            raise TestSkipped('unsupported operation')
1534.10.22 by Aaron Bentley
Got ConflictList implemented
803
        self.assertEqual(tree.conflicts(), ConflictList())
1534.10.14 by Aaron Bentley
Made revert clear conflicts
804
1551.7.11 by Aaron Bentley
Add WorkingTree.add_conflicts
805
    def test_add_conflicts(self):
806
        tree = self.make_branch_and_tree('tree')
807
        try:
808
            tree.add_conflicts([TextConflict('path_a')])
809
        except UnsupportedOperation:
2949.5.1 by Alexander Belchenko
selftest: use SymlinkFeature instead of TestSkipped where appropriate
810
            raise TestSkipped('unsupported operation')
1551.7.13 by Aaron Bentley
Switched from actual, expected to expected, actual, for John.
811
        self.assertEqual(ConflictList([TextConflict('path_a')]),
812
                         tree.conflicts())
1551.7.11 by Aaron Bentley
Add WorkingTree.add_conflicts
813
        tree.add_conflicts([TextConflict('path_a')])
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
814
        self.assertEqual(ConflictList([TextConflict('path_a')]),
1551.7.13 by Aaron Bentley
Switched from actual, expected to expected, actual, for John.
815
                         tree.conflicts())
1551.7.11 by Aaron Bentley
Add WorkingTree.add_conflicts
816
        tree.add_conflicts([ContentsConflict('path_a')])
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
817
        self.assertEqual(ConflictList([ContentsConflict('path_a'),
1551.7.13 by Aaron Bentley
Switched from actual, expected to expected, actual, for John.
818
                                       TextConflict('path_a')]),
819
                         tree.conflicts())
1551.7.11 by Aaron Bentley
Add WorkingTree.add_conflicts
820
        tree.add_conflicts([TextConflict('path_b')])
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
821
        self.assertEqual(ConflictList([ContentsConflict('path_a'),
1551.7.11 by Aaron Bentley
Add WorkingTree.add_conflicts
822
                                       TextConflict('path_a'),
1551.7.13 by Aaron Bentley
Switched from actual, expected to expected, actual, for John.
823
                                       TextConflict('path_b')]),
824
                         tree.conflicts())
1551.7.11 by Aaron Bentley
Add WorkingTree.add_conflicts
825
1534.10.14 by Aaron Bentley
Made revert clear conflicts
826
    def test_revert_clear_conflicts(self):
827
        tree = self.make_merge_conflicts()
1534.10.22 by Aaron Bentley
Got ConflictList implemented
828
        self.assertEqual(len(tree.conflicts()), 1)
1534.10.14 by Aaron Bentley
Made revert clear conflicts
829
        tree.revert(["blo"])
1534.10.22 by Aaron Bentley
Got ConflictList implemented
830
        self.assertEqual(len(tree.conflicts()), 1)
1534.10.14 by Aaron Bentley
Made revert clear conflicts
831
        tree.revert(["bloo"])
1534.10.22 by Aaron Bentley
Got ConflictList implemented
832
        self.assertEqual(len(tree.conflicts()), 0)
1534.10.14 by Aaron Bentley
Made revert clear conflicts
833
834
    def test_revert_clear_conflicts2(self):
835
        tree = self.make_merge_conflicts()
1534.10.22 by Aaron Bentley
Got ConflictList implemented
836
        self.assertEqual(len(tree.conflicts()), 1)
2748.3.2 by Aaron Bentley
Fix revert, remove-tree, and various tests to use None for 'no files specified'
837
        tree.revert()
1534.10.22 by Aaron Bentley
Got ConflictList implemented
838
        self.assertEqual(len(tree.conflicts()), 0)
1624.3.22 by Olaf Conradi
Merge bzr.dev
839
1624.3.19 by Olaf Conradi
New call get_format_description to give a user-friendly description of a
840
    def test_format_description(self):
841
        tree = self.make_branch_and_tree('tree')
842
        text = tree._format.get_format_description()
5784.1.1 by Martin Pool
Stop using failIf, failUnless, etc
843
        self.assertTrue(len(text))
1681.1.1 by Robert Collins
Make WorkingTree.branch a read only property. (Robert Collins)
844
6844.1.2 by Jelmer Vernooij
Add supports_leftmost_parent_id_as_ghost.
845
    def test_format_leftmost_parent_id_as_ghost(self):
846
        tree = self.make_branch_and_tree('tree')
847
        self.assertIn(
7143.15.2 by Jelmer Vernooij
Run autopep8.
848
            tree._format.supports_leftmost_parent_id_as_ghost, (True, False))
6844.1.2 by Jelmer Vernooij
Add supports_leftmost_parent_id_as_ghost.
849
1681.1.1 by Robert Collins
Make WorkingTree.branch a read only property. (Robert Collins)
850
    def test_branch_attribute_is_not_settable(self):
851
        # the branch attribute is an aspect of the working tree, not a
852
        # configurable attribute
853
        tree = self.make_branch_and_tree('tree')
7143.15.2 by Jelmer Vernooij
Run autopep8.
854
1681.1.1 by Robert Collins
Make WorkingTree.branch a read only property. (Robert Collins)
855
        def set_branch():
856
            tree.branch = tree.branch
857
        self.assertRaises(AttributeError, set_branch)
858
1713.3.1 by Robert Collins
Smoke tests for tree.list_files and bzr ignored when a versioned file matches an ignore rule.
859
    def test_list_files_versioned_before_ignored(self):
860
        """A versioned file matching an ignore rule should not be ignored."""
861
        tree = self.make_branch_and_tree('.')
862
        self.build_tree(['foo.pyc'])
863
        # ensure that foo.pyc is ignored
6855.4.1 by Jelmer Vernooij
Yet more bees.
864
        self.build_tree_contents([('.bzrignore', b'foo.pyc')])
6829.2.1 by Jelmer Vernooij
Avoid passing in file_ids/revision_ids in a few more places.
865
        tree.add('foo.pyc')
866
        anid = tree.path2id('foo.pyc')
2255.2.52 by Robert Collins
Dirstate - fix workingtree.list_files to use the public interface to access the trees inventory.
867
        tree.lock_read()
1713.3.1 by Robert Collins
Smoke tests for tree.list_files and bzr ignored when a versioned file matches an ignore rule.
868
        files = sorted(list(tree.list_files()))
2255.2.52 by Robert Collins
Dirstate - fix workingtree.list_files to use the public interface to access the trees inventory.
869
        tree.unlock()
7143.19.1 by Jelmer Vernooij
Drop superfluous kind and file_id return values from Tree.list_files.
870
        self.assertEqual(
7143.19.8 by Jelmer Vernooij
Fix flake8ness.
871
            (u'.bzrignore', '?', 'file', None),
872
            (files[0][0], files[0][1], files[0][2],
873
                getattr(files[0][3], 'file_id', None)))
7143.19.1 by Jelmer Vernooij
Drop superfluous kind and file_id return values from Tree.list_files.
874
        self.assertEqual(
7143.19.8 by Jelmer Vernooij
Fix flake8ness.
875
            (u'foo.pyc', 'V', 'file', anid),
876
            (files[1][0], files[1][1], files[1][2], files[1][3].file_id))
1713.3.1 by Robert Collins
Smoke tests for tree.list_files and bzr ignored when a versioned file matches an ignore rule.
877
        self.assertEqual(2, len(files))
1711.8.2 by John Arbash Meinel
Test that WorkingTree locks Branch before self, and unlocks self before Branch
878
1830.3.7 by John Arbash Meinel
Check that WorkingTree.add does the right thing.
879
    def test_non_normalized_add_accessible(self):
880
        try:
881
            self.build_tree([u'a\u030a'])
882
        except UnicodeError:
883
            raise TestSkipped('Filesystem does not support unicode filenames')
884
        tree = self.make_branch_and_tree('.')
885
        orig = osutils.normalized_filename
886
        osutils.normalized_filename = osutils._accessible_normalized_filename
887
        try:
888
            tree.add([u'a\u030a'])
7143.19.7 by Jelmer Vernooij
merge trunk
889
            with tree.lock_read():
890
                self.assertEqual([('', 'directory'), (u'\xe5', 'file')],
891
                                 [(path, ie.kind) for path, ie in
892
                                  tree.iter_entries_by_dir()])
1830.3.7 by John Arbash Meinel
Check that WorkingTree.add does the right thing.
893
        finally:
894
            osutils.normalized_filename = orig
895
896
    def test_non_normalized_add_inaccessible(self):
897
        try:
898
            self.build_tree([u'a\u030a'])
899
        except UnicodeError:
900
            raise TestSkipped('Filesystem does not support unicode filenames')
901
        tree = self.make_branch_and_tree('.')
902
        orig = osutils.normalized_filename
903
        osutils.normalized_filename = osutils._inaccessible_normalized_filename
904
        try:
905
            self.assertRaises(errors.InvalidNormalization,
7143.15.2 by Jelmer Vernooij
Run autopep8.
906
                              tree.add, [u'a\u030a'])
1830.3.7 by John Arbash Meinel
Check that WorkingTree.add does the right thing.
907
        finally:
908
            osutils.normalized_filename = orig
2123.3.9 by Steffen Eichenberg
added tests for deprecated API workingtree.move
909
1852.15.14 by Robert Collins
test that WorkingTree._write_inventory works as expected by the current code.
910
    def test__write_inventory(self):
7143.19.5 by Jelmer Vernooij
Undo removal of kind.
911
        # The private interface _write_inventory is currently used by
912
        # transform.
1852.15.14 by Robert Collins
test that WorkingTree._write_inventory works as expected by the current code.
913
        tree = self.make_branch_and_tree('.')
5807.1.2 by Jelmer Vernooij
Skip some inventory-specific tests for non-inventory working trees.
914
        if not isinstance(tree, InventoryWorkingTree):
915
            raise TestNotApplicable("_write_inventory does not exist on "
7143.15.2 by Jelmer Vernooij
Run autopep8.
916
                                    "non-inventory working trees")
1852.15.14 by Robert Collins
test that WorkingTree._write_inventory works as expected by the current code.
917
        # if we write write an inventory then do a walkdirs we should get back
918
        # missing entries, and actual, and unknowns as appropriate.
919
        self.build_tree(['present', 'unknown'])
7358.14.1 by Jelmer Vernooij
Remove Tree.get_root_id() in favour of Tree.path2id('').
920
        inventory = Inventory(tree.path2id(''))
6973.13.2 by Jelmer Vernooij
Fix some more tests.
921
        inventory.add_path('missing', 'file', b'missing-id')
922
        inventory.add_path('present', 'file', b'present-id')
2255.2.28 by Robert Collins
TestWorkingTree.test__write_inventory needs to lock the tree before calling _write_inventory for dirstate.
923
        # there is no point in being able to write an inventory to an unlocked
924
        # tree object - its a low level api not a convenience api.
925
        tree.lock_write()
1852.15.14 by Robert Collins
test that WorkingTree._write_inventory works as expected by the current code.
926
        tree._write_inventory(inventory)
2255.2.28 by Robert Collins
TestWorkingTree.test__write_inventory needs to lock the tree before calling _write_inventory for dirstate.
927
        tree.unlock()
7143.19.7 by Jelmer Vernooij
merge trunk
928
        with tree.lock_read():
1852.15.14 by Robert Collins
test that WorkingTree._write_inventory works as expected by the current code.
929
            present_stat = os.lstat('present')
930
            unknown_stat = os.lstat('unknown')
931
            expected_results = [
7490.121.1 by Jelmer Vernooij
Drop file ids from the Tree.walkdirs API.
932
                ('',
933
                 [('missing', 'missing', 'unknown', None, 'file'),
7143.15.2 by Jelmer Vernooij
Run autopep8.
934
                  ('present', 'present', 'file',
7490.121.1 by Jelmer Vernooij
Drop file ids from the Tree.walkdirs API.
935
                   present_stat, 'file'),
936
                  ('unknown', 'unknown', 'file', unknown_stat, None),
7143.15.2 by Jelmer Vernooij
Run autopep8.
937
                  ]
938
                 )]
1852.15.14 by Robert Collins
test that WorkingTree._write_inventory works as expected by the current code.
939
            self.assertEqual(expected_results, list(tree.walkdirs()))
2255.7.56 by Robert Collins
Document behaviour of tree.path2id("path/").
940
941
    def test_path2id(self):
2255.7.62 by Robert Collins
Update the Tree.filter_unversioned_files docstring to reflect what the existing implementations actually do, and change the WorkingTree4 implementation to match a newly created test for it.
942
        # smoke test for path2id
2255.7.56 by Robert Collins
Document behaviour of tree.path2id("path/").
943
        tree = self.make_branch_and_tree('.')
944
        self.build_tree(['foo'])
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
945
        if tree.supports_setting_file_ids():
6855.4.1 by Jelmer Vernooij
Yet more bees.
946
            tree.add(['foo'], [b'foo-id'])
947
            self.assertEqual(b'foo-id', tree.path2id('foo'))
6745.1.2 by Jelmer Vernooij
s/compatability/compatibility/
948
            # the next assertion is for backwards compatibility with
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
949
            # WorkingTree3, though its probably a bad idea, it makes things
950
            # work. Perhaps it should raise a deprecation warning?
6855.4.1 by Jelmer Vernooij
Yet more bees.
951
            self.assertEqual(b'foo-id', tree.path2id('foo/'))
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
952
        else:
953
            tree.add(['foo'])
6821.2.2 by Jelmer Vernooij
More foreign fixes.
954
            if tree.branch.repository._format.supports_versioned_directories:
955
                self.assertIsInstance(str, tree.path2id('foo'))
956
            else:
957
                self.skipTest('format does not support versioning directories')
2255.7.62 by Robert Collins
Update the Tree.filter_unversioned_files docstring to reflect what the existing implementations actually do, and change the WorkingTree4 implementation to match a newly created test for it.
958
959
    def test_filter_unversioned_files(self):
960
        # smoke test for filter_unversioned_files
961
        tree = self.make_branch_and_tree('.')
962
        paths = ['here-and-versioned', 'here-and-not-versioned',
7143.15.2 by Jelmer Vernooij
Run autopep8.
963
                 'not-here-and-versioned', 'not-here-and-not-versioned']
2255.7.62 by Robert Collins
Update the Tree.filter_unversioned_files docstring to reflect what the existing implementations actually do, and change the WorkingTree4 implementation to match a newly created test for it.
964
        tree.add(['here-and-versioned', 'not-here-and-versioned'],
7143.15.2 by Jelmer Vernooij
Run autopep8.
965
                 kinds=['file', 'file'])
2255.7.62 by Robert Collins
Update the Tree.filter_unversioned_files docstring to reflect what the existing implementations actually do, and change the WorkingTree4 implementation to match a newly created test for it.
966
        self.build_tree(['here-and-versioned', 'here-and-not-versioned'])
967
        tree.lock_read()
968
        self.addCleanup(tree.unlock)
969
        self.assertEqual(
6619.3.12 by Jelmer Vernooij
Use 2to3 set_literal fixer.
970
            {'not-here-and-not-versioned', 'here-and-not-versioned'},
2255.7.62 by Robert Collins
Update the Tree.filter_unversioned_files docstring to reflect what the existing implementations actually do, and change the WorkingTree4 implementation to match a newly created test for it.
971
            tree.filter_unversioned_files(paths))
2255.2.200 by Martin Pool
Add simple test for WorkingTree.kind
972
973
    def test_detect_real_kind(self):
974
        # working trees report the real kind of the file on disk, not the kind
975
        # they had when they were first added
976
        # create one file of every interesting type
977
        tree = self.make_branch_and_tree('.')
4100.2.2 by Aaron Bentley
Remove locking decorator
978
        tree.lock_write()
979
        self.addCleanup(tree.unlock)
2255.2.200 by Martin Pool
Add simple test for WorkingTree.kind
980
        self.build_tree(['file', 'directory/'])
981
        names = ['file', 'directory']
982
        if has_symlinks():
983
            os.symlink('target', 'symlink')
984
            names.append('symlink')
6809.4.7 by Jelmer Vernooij
Swap arguments for get_symlink_target and kind/stored_kind.
985
        tree.add(names)
2255.2.200 by Martin Pool
Add simple test for WorkingTree.kind
986
        # now when we first look, we should see everything with the same kind
987
        # with which they were initially added
988
        for n in names:
6809.4.7 by Jelmer Vernooij
Swap arguments for get_symlink_target and kind/stored_kind.
989
            actual_kind = tree.kind(n)
2255.2.200 by Martin Pool
Add simple test for WorkingTree.kind
990
            self.assertEqual(n, actual_kind)
991
        # move them around so the names no longer correspond to the types
992
        os.rename(names[0], 'tmp')
993
        for i in range(1, len(names)):
7143.15.2 by Jelmer Vernooij
Run autopep8.
994
            os.rename(names[i], names[i - 1])
2255.2.200 by Martin Pool
Add simple test for WorkingTree.kind
995
        os.rename('tmp', names[-1])
2255.2.202 by Martin Pool
WorkingTree_4.kind should report tree-references if they're
996
        # now look and expect to see the correct types again
997
        for i in range(len(names)):
7143.15.2 by Jelmer Vernooij
Run autopep8.
998
            actual_kind = tree.kind(names[i - 1])
2255.2.202 by Martin Pool
WorkingTree_4.kind should report tree-references if they're
999
            expected_kind = names[i]
1000
            self.assertEqual(expected_kind, actual_kind)
2499.3.1 by Aaron Bentley
Fix Workingtree4.get_file_sha1 on missing files
1001
3146.8.4 by Aaron Bentley
Eliminate direct use of inventory from transform application
1002
    def test_stored_kind_with_missing(self):
1003
        tree = self.make_branch_and_tree('tree')
1004
        tree.lock_write()
1005
        self.addCleanup(tree.unlock)
1006
        self.build_tree(['tree/a', 'tree/b/'])
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
1007
        tree.add(['a', 'b'])
3146.8.4 by Aaron Bentley
Eliminate direct use of inventory from transform application
1008
        os.unlink('tree/a')
1009
        os.rmdir('tree/b')
6809.4.7 by Jelmer Vernooij
Swap arguments for get_symlink_target and kind/stored_kind.
1010
        self.assertEqual('file', tree.stored_kind('a'))
6816.1.1 by Jelmer Vernooij
Avoid passing in file ids.
1011
        if tree.branch.repository._format.supports_versioned_directories:
6809.4.26 by Jelmer Vernooij
Merge trunk.
1012
            self.assertEqual('directory', tree.stored_kind('b'))
3146.8.4 by Aaron Bentley
Eliminate direct use of inventory from transform application
1013
7490.133.20 by Jelmer Vernooij
Some more test fixes.
1014
    def test_stored_kind_nonexistent(self):
1015
        tree = self.make_branch_and_tree('tree')
1016
        tree.lock_write()
1017
        self.assertRaises(errors.NoSuchFile, tree.stored_kind, 'a')
1018
        self.addCleanup(tree.unlock)
1019
        self.build_tree(['tree/a'])
1020
        self.assertRaises(errors.NoSuchFile, tree.stored_kind, 'a')
1021
        tree.add(['a'])
1022
        self.assertIs('file', tree.stored_kind('a'))
1023
2499.3.1 by Aaron Bentley
Fix Workingtree4.get_file_sha1 on missing files
1024
    def test_missing_file_sha1(self):
1025
        """If a file is missing, its sha1 should be reported as None."""
1026
        tree = self.make_branch_and_tree('.')
1027
        tree.lock_write()
1028
        self.addCleanup(tree.unlock)
1029
        self.build_tree(['file'])
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
1030
        tree.add('file')
2499.3.1 by Aaron Bentley
Fix Workingtree4.get_file_sha1 on missing files
1031
        tree.commit('file added')
1032
        os.unlink('file')
6809.4.5 by Jelmer Vernooij
Swap arguments for get_file_*.
1033
        self.assertIs(None, tree.get_file_sha1('file'))
1551.15.56 by Aaron Bentley
Raise NoSuchId when get_file_sha1 is invoked with a baed file id
1034
1035
    def test_no_file_sha1(self):
6809.4.13 by Jelmer Vernooij
Fix tests.
1036
        """If a file is not present, get_file_sha1 should raise NoSuchFile"""
1551.15.56 by Aaron Bentley
Raise NoSuchId when get_file_sha1 is invoked with a baed file id
1037
        tree = self.make_branch_and_tree('.')
1038
        tree.lock_write()
1039
        self.addCleanup(tree.unlock)
6809.4.13 by Jelmer Vernooij
Fix tests.
1040
        self.assertRaises(errors.NoSuchFile, tree.get_file_sha1,
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
1041
                          'nonexistant')
1551.15.56 by Aaron Bentley
Raise NoSuchId when get_file_sha1 is invoked with a baed file id
1042
        self.build_tree(['file'])
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
1043
        tree.add('file')
1551.15.56 by Aaron Bentley
Raise NoSuchId when get_file_sha1 is invoked with a baed file id
1044
        tree.commit('foo')
1045
        tree.remove('file')
6809.4.13 by Jelmer Vernooij
Fix tests.
1046
        self.assertRaises(errors.NoSuchFile, tree.get_file_sha1,
6809.4.5 by Jelmer Vernooij
Swap arguments for get_file_*.
1047
                          'file')
3034.4.5 by Aaron Bentley
Add workingtree test for case_insensitive var
1048
1049
    def test_case_sensitive(self):
1050
        """If filesystem is case-sensitive, tree should report this.
1051
1052
        We check case-sensitivity by creating a file with a lowercase name,
1053
        then testing whether it exists with an uppercase name.
1054
        """
3034.4.9 by Alexander Belchenko
skip test_workingtree.TestWorkingTree.test_case_sensitive for WT2
1055
        self.build_tree(['filename'])
3034.4.5 by Aaron Bentley
Add workingtree test for case_insensitive var
1056
        if os.path.exists('FILENAME'):
1057
            case_sensitive = False
1058
        else:
1059
            case_sensitive = True
1060
        tree = self.make_branch_and_tree('test')
1061
        self.assertEqual(case_sensitive, tree.case_sensitive)
6113.1.1 by Jelmer Vernooij
Skip some tests against foreign formats.
1062
        if not isinstance(tree, InventoryWorkingTree):
1063
            raise TestNotApplicable("get_format_string is only available "
1064
                                    "on bzr working trees")
5632.1.1 by John Arbash Meinel
Make case_sensitive_filename an attribute of the format.
1065
        # now we cheat, and make a file that matches the case-sensitive name
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
1066
        t = tree.controldir.get_workingtree_transport(None)
5632.1.1 by John Arbash Meinel
Make case_sensitive_filename an attribute of the format.
1067
        try:
1068
            content = tree._format.get_format_string()
1069
        except NotImplementedError:
1070
            # All-in-one formats didn't have a separate format string.
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
1071
            content = tree.controldir._format.get_format_string()
5632.1.1 by John Arbash Meinel
Make case_sensitive_filename an attribute of the format.
1072
        t.put_bytes(tree._format.case_sensitive_filename, content)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
1073
        tree = tree.controldir.open_workingtree()
5632.1.1 by John Arbash Meinel
Make case_sensitive_filename an attribute of the format.
1074
        self.assertFalse(tree.case_sensitive)
3146.8.2 by Aaron Bentley
Introduce iter_all_file_ids, to avoid hitting Inventory for this case
1075
6379.7.1 by Jelmer Vernooij
Add and use WorkingTree._supports_executable.
1076
    def test_supports_executable(self):
1077
        self.build_tree(['filename'])
1078
        tree = self.make_branch_and_tree('.')
1079
        tree.add('filename')
1080
        self.assertIsInstance(tree._supports_executable(), bool)
1081
        if tree._supports_executable():
1082
            tree.lock_read()
1083
            try:
6809.4.4 by Jelmer Vernooij
Swap arguments for Tree.is_executable.
1084
                self.assertFalse(tree.is_executable('filename'))
6379.7.1 by Jelmer Vernooij
Add and use WorkingTree._supports_executable.
1085
            finally:
1086
                tree.unlock()
6619.3.14 by Jelmer Vernooij
Convert some octal numbers to new notations.
1087
            os.chmod('filename', 0o755)
6379.7.1 by Jelmer Vernooij
Add and use WorkingTree._supports_executable.
1088
            self.addCleanup(tree.lock_read().unlock)
6809.4.4 by Jelmer Vernooij
Swap arguments for Tree.is_executable.
1089
            self.assertTrue(tree.is_executable('filename'))
6379.7.1 by Jelmer Vernooij
Add and use WorkingTree._supports_executable.
1090
        else:
1091
            self.addCleanup(tree.lock_read().unlock)
6809.4.4 by Jelmer Vernooij
Swap arguments for Tree.is_executable.
1092
            self.assertFalse(tree.is_executable('filename'))
6379.7.1 by Jelmer Vernooij
Add and use WorkingTree._supports_executable.
1093
3146.8.16 by Aaron Bentley
Updates from review
1094
    def test_all_file_ids_with_missing(self):
3146.8.2 by Aaron Bentley
Introduce iter_all_file_ids, to avoid hitting Inventory for this case
1095
        tree = self.make_branch_and_tree('tree')
1096
        tree.lock_write()
1097
        self.addCleanup(tree.unlock)
1098
        self.build_tree(['tree/a', 'tree/b'])
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
1099
        tree.add(['a', 'b'])
3146.8.2 by Aaron Bentley
Introduce iter_all_file_ids, to avoid hitting Inventory for this case
1100
        os.unlink('tree/a')
7170.3.1 by Jelmer Vernooij
Make Tree.all_file_ids optional.
1101
        try:
1102
            self.assertEqual(
7183.2.1 by Martin
Fix E999 lint error for Python 2 flake8
1103
                {'a', 'b', ''},
1104
                set(tree.all_versioned_paths()))
7170.3.1 by Jelmer Vernooij
Make Tree.all_file_ids optional.
1105
        except errors.UnsupportedOperation:
1106
            raise TestNotApplicable('tree does not support all_file_ids')
3146.8.19 by Aaron Bentley
Merge with bzr.dev
1107
3136.1.10 by Aaron Bentley
Clean error if filesystem does not support hard-links
1108
    def test_sprout_hardlink(self):
3619.6.9 by Mark Hammond
Move check for os.link to the start of the test
1109
        real_os_link = getattr(os, 'link', None)
1110
        if real_os_link is None:
1111
            raise TestNotApplicable("This platform doesn't provide os.link")
3136.1.10 by Aaron Bentley
Clean error if filesystem does not support hard-links
1112
        source = self.make_branch_and_tree('source')
1113
        self.build_tree(['source/file'])
1114
        source.add('file')
1115
        source.commit('added file')
7143.15.2 by Jelmer Vernooij
Run autopep8.
1116
3136.1.10 by Aaron Bentley
Clean error if filesystem does not support hard-links
1117
        def fake_link(source, target):
1118
            raise OSError(errno.EPERM, 'Operation not permitted')
1119
        os.link = fake_link
1120
        try:
1121
            # Hard-link support is optional, so supplying hardlink=True may
1122
            # or may not raise an exception.  But if it does, it must be
1123
            # HardLinkNotSupported
1124
            try:
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
1125
                source.controldir.sprout('target', accelerator_tree=source,
7143.15.2 by Jelmer Vernooij
Run autopep8.
1126
                                         hardlink=True)
3136.1.10 by Aaron Bentley
Clean error if filesystem does not support hard-links
1127
            except errors.HardLinkNotSupported:
1128
                pass
1129
        finally:
1130
            os.link = real_os_link
3287.20.3 by John Arbash Meinel
Aaron recommended to make this a WT_impl test.
1131
1132
4985.3.18 by Vincent Ladeuil
Start rewriting the test.
1133
class TestWorkingTreeUpdate(TestCaseWithWorkingTree):
1134
1135
    def make_diverged_master_branch(self):
1136
        """
1137
        B: wt.branch.last_revision()
1138
        M: wt.branch.get_master_branch().last_revision()
1139
        W: wt.last_revision()
1140
1141
1142
            1
1143
            |\
1144
          B-2 3
1145
            | |
1146
            4 5-M
1147
            |
1148
            W
6162.3.2 by Jelmer Vernooij
Add WorkingTreeFormat.get_controldir_for_branch().
1149
        """
1150
        format = self.workingtree_format.get_controldir_for_branch()
1151
        builder = self.make_branch_builder(".", format=format)
4985.3.18 by Vincent Ladeuil
Start rewriting the test.
1152
        builder.start_series()
6821.2.2 by Jelmer Vernooij
More foreign fixes.
1153
        revids = {}
4985.3.18 by Vincent Ladeuil
Start rewriting the test.
1154
        # mainline
6821.2.2 by Jelmer Vernooij
More foreign fixes.
1155
        revids['1'] = builder.build_snapshot(
6816.2.1 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
1156
            None,
6883.22.13 by Jelmer Vernooij
Actually pass in None file-ids to BranchBuilder.
1157
            [('add', ('', None, 'directory', '')),
7045.1.13 by Jelmer Vernooij
Fix a few more tests.
1158
             ('add', ('file1', None, 'file', b'file1 content\n'))])
4985.3.18 by Vincent Ladeuil
Start rewriting the test.
1159
        # branch
6821.2.2 by Jelmer Vernooij
More foreign fixes.
1160
        revids['2'] = builder.build_snapshot([revids['1']], [])
1161
        revids['4'] = builder.build_snapshot(
1162
            [revids['1']],
7045.1.13 by Jelmer Vernooij
Fix a few more tests.
1163
            [('add', ('file4', None, 'file', b'file4 content\n'))])
4985.3.18 by Vincent Ladeuil
Start rewriting the test.
1164
        # master
6821.2.2 by Jelmer Vernooij
More foreign fixes.
1165
        revids['3'] = builder.build_snapshot([revids['1']], [])
1166
        revids['5'] = builder.build_snapshot(
1167
            [revids['3']],
7045.1.13 by Jelmer Vernooij
Fix a few more tests.
1168
            [('add', ('file5', None, 'file', b'file5 content\n'))])
4985.3.18 by Vincent Ladeuil
Start rewriting the test.
1169
        builder.finish_series()
6821.2.2 by Jelmer Vernooij
More foreign fixes.
1170
        return (builder, builder._branch.last_revision(), revids)
4985.3.18 by Vincent Ladeuil
Start rewriting the test.
1171
4985.3.21 by Vincent Ladeuil
Final cleanup.
1172
    def make_checkout_and_master(self, builder, wt_path, master_path, wt_revid,
1173
                                 master_revid=None, branch_revid=None):
1174
        """Build a lightweight checkout and its master branch."""
1175
        if master_revid is None:
1176
            master_revid = wt_revid
1177
        if branch_revid is None:
1178
            branch_revid = master_revid
4985.3.18 by Vincent Ladeuil
Start rewriting the test.
1179
        final_branch = builder.get_branch()
1180
        # The master branch
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
1181
        master = final_branch.controldir.sprout(master_path,
7143.15.2 by Jelmer Vernooij
Run autopep8.
1182
                                                master_revid).open_branch()
4985.3.21 by Vincent Ladeuil
Final cleanup.
1183
        # The checkout
1184
        wt = self.make_branch_and_tree(wt_path)
1185
        wt.pull(final_branch, stop_revision=wt_revid)
7143.15.2 by Jelmer Vernooij
Run autopep8.
1186
        wt.branch.pull(
1187
            final_branch, stop_revision=branch_revid, overwrite=True)
4985.3.18 by Vincent Ladeuil
Start rewriting the test.
1188
        try:
4985.3.21 by Vincent Ladeuil
Final cleanup.
1189
            wt.branch.bind(master)
4985.3.18 by Vincent Ladeuil
Start rewriting the test.
1190
        except errors.UpgradeRequired:
4985.3.21 by Vincent Ladeuil
Final cleanup.
1191
            raise TestNotApplicable(
1192
                "Can't bind %s" % wt.branch._format.__class__)
1193
        return wt, master
4985.3.18 by Vincent Ladeuil
Start rewriting the test.
1194
1195
    def test_update_remove_commit(self):
1196
        """Update should remove revisions when the branch has removed
1197
        some commits.
1198
1199
        We want to revert 4, so that strating with the
1200
        make_diverged_master_branch() graph the final result should be
1201
        equivalent to:
1202
1203
           1
1204
           |\
1205
           3 2
1206
           | |\
1207
        MB-5 | 4
1208
           |/
1209
           W
1210
1211
        And the changes in 4 have been removed from the WT.
1212
        """
6821.2.2 by Jelmer Vernooij
More foreign fixes.
1213
        builder, tip, revids = self.make_diverged_master_branch()
4985.3.21 by Vincent Ladeuil
Final cleanup.
1214
        wt, master = self.make_checkout_and_master(
6821.2.2 by Jelmer Vernooij
More foreign fixes.
1215
            builder, 'checkout', 'master', revids['4'],
1216
            master_revid=tip, branch_revid=revids['2'])
4985.3.19 by Vincent Ladeuil
Make the test more precise.
1217
        # First update the branch
1218
        old_tip = wt.branch.update()
6821.2.2 by Jelmer Vernooij
More foreign fixes.
1219
        self.assertEqual(revids['2'], old_tip)
4985.3.18 by Vincent Ladeuil
Start rewriting the test.
1220
        # No conflicts should occur
4985.3.21 by Vincent Ladeuil
Final cleanup.
1221
        self.assertEqual(0, wt.update(old_tip=old_tip))
4985.3.19 by Vincent Ladeuil
Make the test more precise.
1222
        # We are in sync with the master
1223
        self.assertEqual(tip, wt.branch.last_revision())
4985.3.20 by Vincent Ladeuil
Remove the blackbox test and fix typo.
1224
        # We have the right parents ready to be committed
6821.2.2 by Jelmer Vernooij
More foreign fixes.
1225
        self.assertEqual([revids['5'], revids['2']],
1226
                         wt.get_parent_ids())
4985.3.18 by Vincent Ladeuil
Start rewriting the test.
1227
4985.3.21 by Vincent Ladeuil
Final cleanup.
1228
    def test_update_revision(self):
6821.2.2 by Jelmer Vernooij
More foreign fixes.
1229
        builder, tip, revids = self.make_diverged_master_branch()
4985.3.21 by Vincent Ladeuil
Final cleanup.
1230
        wt, master = self.make_checkout_and_master(
6821.2.2 by Jelmer Vernooij
More foreign fixes.
1231
            builder, 'checkout', 'master', revids['4'],
1232
            master_revid=tip, branch_revid=revids['2'])
1233
        self.assertEqual(0, wt.update(revision=revids['1']))
1234
        self.assertEqual(revids['1'], wt.last_revision())
4985.3.21 by Vincent Ladeuil
Final cleanup.
1235
        self.assertEqual(tip, wt.branch.last_revision())
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
1236
        self.assertPathExists('checkout/file1')
1237
        self.assertPathDoesNotExist('checkout/file4')
1238
        self.assertPathDoesNotExist('checkout/file5')
4985.3.21 by Vincent Ladeuil
Final cleanup.
1239
4985.3.18 by Vincent Ladeuil
Start rewriting the test.
1240
3287.20.3 by John Arbash Meinel
Aaron recommended to make this a WT_impl test.
1241
class TestIllegalPaths(TestCaseWithWorkingTree):
1242
1243
    def test_bad_fs_path(self):
3638.3.14 by Vincent Ladeuil
Make test_bad_fs_path not applicable on OSX.
1244
        if osutils.normalizes_filenames():
1245
            # You *can't* create an illegal filename on OSX.
1246
            raise tests.TestNotApplicable('OSX normalizes filenames')
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
1247
        self.requireFeature(features.UTF8Filesystem)
3287.20.3 by John Arbash Meinel
Aaron recommended to make this a WT_impl test.
1248
        # We require a UTF8 filesystem, because otherwise we would need to get
1249
        # tricky to figure out how to create an illegal filename.
1250
        # \xb5 is an illegal path because it should be \xc2\xb5 for UTF-8
1251
        tree = self.make_branch_and_tree('tree')
6883.14.3 by Jelmer Vernooij
Merge badfs test fix.
1252
        self.build_tree(['tree/subdir/', 'tree/subdir/somefile'])
1253
        tree.add(['subdir', 'subdir/somefile'])
3287.20.3 by John Arbash Meinel
Aaron recommended to make this a WT_impl test.
1254
7058.4.5 by Jelmer Vernooij
Fix bad_fs_path.
1255
        with open(b'tree/subdir/m\xb5', 'wb') as f:
6973.7.5 by Jelmer Vernooij
s/file/open.
1256
            f.write(b'trivial\n')
3287.20.3 by John Arbash Meinel
Aaron recommended to make this a WT_impl test.
1257
1258
        tree.lock_read()
1259
        self.addCleanup(tree.unlock)
1260
        basis = tree.basis_tree()
1261
        basis.lock_read()
1262
        self.addCleanup(basis.unlock)
1263
1264
        e = self.assertListRaises(errors.BadFilenameEncoding,
1265
                                  tree.iter_changes, tree.basis_tree(),
6883.14.3 by Jelmer Vernooij
Merge badfs test fix.
1266
                                  want_unversioned=True)
3287.20.3 by John Arbash Meinel
Aaron recommended to make this a WT_impl test.
1267
        # We should display the relative path
7058.4.5 by Jelmer Vernooij
Fix bad_fs_path.
1268
        self.assertEqual(b'subdir/m\xb5', e.filename)
3287.20.3 by John Arbash Meinel
Aaron recommended to make this a WT_impl test.
1269
        self.assertEqual(osutils._fs_enc, e.fs_encoding)
5158.6.5 by Martin Pool
Implement ControlComponent on WorkingTree
1270
1271
1272
class TestControlComponent(TestCaseWithWorkingTree):
1273
    """WorkingTree implementations adequately implement ControlComponent."""
6059.4.4 by Vincent Ladeuil
Migrate bzr.workingtree.worth_saving_limit to stack-based config.
1274
5158.6.5 by Martin Pool
Implement ControlComponent on WorkingTree
1275
    def test_urls(self):
1276
        wt = self.make_branch_and_tree('wt')
1277
        self.assertIsInstance(wt.user_url, str)
1278
        self.assertEqual(wt.user_url, wt.user_transport.base)
1279
        self.assertEqual(wt.control_url, wt.control_transport.base)
5807.4.7 by John Arbash Meinel
Add a config setting.
1280
1281
1282
class TestWorthSavingLimit(TestCaseWithWorkingTree):
1283
1284
    def make_wt_with_worth_saving_limit(self):
1285
        wt = self.make_branch_and_tree('wt')
1286
        if getattr(wt, '_worth_saving_limit', None) is None:
1287
            raise tests.TestNotApplicable('no _worth_saving_limit for'
1288
                                          ' this tree type')
1289
        wt.lock_write()
1290
        self.addCleanup(wt.unlock)
1291
        return wt
1292
1293
    def test_not_set(self):
1294
        # Default should be 10
1295
        wt = self.make_wt_with_worth_saving_limit()
1296
        self.assertEqual(10, wt._worth_saving_limit())
1297
        ds = wt.current_dirstate()
1298
        self.assertEqual(10, ds._worth_saving_limit)
1299
1300
    def test_set_in_branch(self):
1301
        wt = self.make_wt_with_worth_saving_limit()
6449.4.3 by Jelmer Vernooij
Use WorkingTree.get_config_stack.
1302
        conf = wt.get_config_stack()
6059.4.4 by Vincent Ladeuil
Migrate bzr.workingtree.worth_saving_limit to stack-based config.
1303
        conf.set('bzr.workingtree.worth_saving_limit', '20')
5807.4.7 by John Arbash Meinel
Add a config setting.
1304
        self.assertEqual(20, wt._worth_saving_limit())
1305
        ds = wt.current_dirstate()
1306
        self.assertEqual(10, ds._worth_saving_limit)
1307
1308
    def test_invalid(self):
1309
        wt = self.make_wt_with_worth_saving_limit()
6449.4.3 by Jelmer Vernooij
Use WorkingTree.get_config_stack.
1310
        conf = wt.get_config_stack()
6059.4.4 by Vincent Ladeuil
Migrate bzr.workingtree.worth_saving_limit to stack-based config.
1311
        conf.set('bzr.workingtree.worth_saving_limit', 'a')
5807.4.7 by John Arbash Meinel
Add a config setting.
1312
        # If the config entry is invalid, default to 10
6059.4.4 by Vincent Ladeuil
Migrate bzr.workingtree.worth_saving_limit to stack-based config.
1313
        warnings = []
7143.15.2 by Jelmer Vernooij
Run autopep8.
1314
6059.4.4 by Vincent Ladeuil
Migrate bzr.workingtree.worth_saving_limit to stack-based config.
1315
        def warning(*args):
1316
            warnings.append(args[0] % args[1:])
1317
        self.overrideAttr(trace, 'warning', warning)
5807.4.7 by John Arbash Meinel
Add a config setting.
1318
        self.assertEqual(10, wt._worth_saving_limit())
6059.4.4 by Vincent Ladeuil
Migrate bzr.workingtree.worth_saving_limit to stack-based config.
1319
        self.assertLength(1, warnings)
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
1320
        self.assertEqual('Value "a" is not valid for'
7143.15.2 by Jelmer Vernooij
Run autopep8.
1321
                         ' "bzr.workingtree.worth_saving_limit"',
1322
                         warnings[0])
5993.3.1 by Jelmer Vernooij
Add WorkingTreeFormat.supports_versioned_directories attribute.
1323
1324
1325
class TestFormatAttributes(TestCaseWithWorkingTree):
1326
1327
    def test_versioned_directories(self):
1328
        self.assertSubset(
1329
            [self.workingtree_format.supports_versioned_directories],
1330
            (True, False))
6741.1.1 by Jelmer Vernooij
Add WorkingTreeFormat.supports_setting_file_ids.
1331
1332
    def test_supports_setting_file_ids(self):
1333
        self.assertSubset(
1334
            [self.workingtree_format.supports_setting_file_ids],
1335
            (True, False))
6772.3.2 by Jelmer Vernooij
Add flag for store uncommitted in working tree formats.
1336
1337
    def test_supports_store_uncommitted(self):
1338
        self.assertSubset(
1339
            [self.workingtree_format.supports_store_uncommitted],
1340
            (True, False))
7447.3.1 by Jelmer Vernooij
Move tree reference info functions to workingtree.
1341
1342
1343
class TestReferenceLocation(TestCaseWithWorkingTree):
1344
1345
    def test_reference_parent(self):
1346
        tree = self.make_branch_and_tree('tree')
1347
        subtree = self.make_branch_and_tree('tree/subtree')
1348
        subtree.commit('a change')
1349
        try:
1350
            tree.add_reference(subtree)
1351
        except errors.UnsupportedOperation:
1352
            raise tests.TestNotApplicable('Tree cannot hold references.')
7447.3.3 by Jelmer Vernooij
Fix some blackbox tests.
1353
        if not getattr(tree.branch._format, 'supports_reference_locations', False):
1354
            raise tests.TestNotApplicable('Branch cannot hold reference locations.')
1355
        tree.commit('Add reference.')
1356
        reference_parent = tree.reference_parent(
7447.3.1 by Jelmer Vernooij
Move tree reference info functions to workingtree.
1357
            urlutils.relative_url(
1358
                urlutils.strip_segment_parameters(tree.branch.user_url),
1359
                urlutils.strip_segment_parameters(subtree.branch.user_url)))
1360
        self.assertEqual(subtree.branch.user_url, reference_parent.user_url)
1361
1362
    def test_reference_parent_accepts_possible_transports(self):
1363
        tree = self.make_branch_and_tree('tree')
1364
        subtree = self.make_branch_and_tree('tree/subtree')
1365
        subtree.commit('a change')
1366
        try:
1367
            tree.add_reference(subtree)
1368
        except errors.UnsupportedOperation:
1369
            raise tests.TestNotApplicable('Tree cannot hold references.')
7447.3.3 by Jelmer Vernooij
Fix some blackbox tests.
1370
        if not getattr(tree.branch._format, 'supports_reference_locations', False):
1371
            raise tests.TestNotApplicable('Branch cannot hold reference locations.')
1372
        tree.commit('Add reference')
7447.3.1 by Jelmer Vernooij
Move tree reference info functions to workingtree.
1373
        reference_parent = tree.reference_parent(
1374
            urlutils.relative_url(
1375
                urlutils.strip_segment_parameters(tree.branch.user_url),
1376
                urlutils.strip_segment_parameters(subtree.branch.user_url)),
1377
            possible_transports=[subtree.controldir.root_transport])
1378
1379
    def test_get_reference_info(self):
1380
        tree = self.make_branch_and_tree('branch')
1381
        try:
1382
            loc = tree.get_reference_info('file')
1383
        except errors.UnsupportedOperation:
1384
            raise tests.TestNotApplicable('Branch cannot hold references.')
1385
        self.assertIs(None, loc)
1386
1387
    def test_set_reference_info(self):
7447.4.2 by Jelmer Vernooij
Merge tree reference fixes.
1388
        self.make_tree_with_reference('branch', 'path/to/location')
7447.3.1 by Jelmer Vernooij
Move tree reference info functions to workingtree.
1389
1390
    def test_set_get_reference_info(self):
7447.4.2 by Jelmer Vernooij
Merge tree reference fixes.
1391
        tree = self.make_tree_with_reference('branch', 'path/to/location')
7447.3.1 by Jelmer Vernooij
Move tree reference info functions to workingtree.
1392
        # Create a new instance to ensure storage is permanent
1393
        tree = WorkingTree.open('branch')
1394
        branch_location = tree.get_reference_info('path/to/file')
7447.3.4 by Jelmer Vernooij
Fix tests.
1395
        self.assertEqual(
7449.2.10 by Jelmer Vernooij
Fix tests.
1396
            urlutils.join(urlutils.strip_segment_parameters(tree.branch.user_url), 'path/to/location'),
1397
            urlutils.join(urlutils.strip_segment_parameters(tree.branch.user_url), branch_location))
7447.3.1 by Jelmer Vernooij
Move tree reference info functions to workingtree.
1398
1399
    def test_set_null_reference_info(self):
1400
        tree = self.make_branch_and_tree('branch')
7447.4.2 by Jelmer Vernooij
Merge tree reference fixes.
1401
        self.build_tree(['branch/file'])
1402
        tree.add(['file'])
7447.3.1 by Jelmer Vernooij
Move tree reference info functions to workingtree.
1403
        try:
7447.4.2 by Jelmer Vernooij
Merge tree reference fixes.
1404
            tree.set_reference_info('file', 'path/to/location')
7447.3.1 by Jelmer Vernooij
Move tree reference info functions to workingtree.
1405
        except errors.UnsupportedOperation:
1406
            raise tests.TestNotApplicable('Branch cannot hold references.')
7447.4.2 by Jelmer Vernooij
Merge tree reference fixes.
1407
        tree.set_reference_info('file', None)
1408
        branch_location = tree.get_reference_info('file')
7447.3.1 by Jelmer Vernooij
Move tree reference info functions to workingtree.
1409
        self.assertIs(None, branch_location)
1410
1411
    def test_set_null_reference_info_when_null(self):
1412
        tree = self.make_branch_and_tree('branch')
1413
        try:
1414
            branch_location = tree.get_reference_info('file')
1415
        except errors.UnsupportedOperation:
1416
            raise tests.TestNotApplicable('Branch cannot hold references.')
1417
        self.assertIs(None, branch_location)
7447.4.2 by Jelmer Vernooij
Merge tree reference fixes.
1418
        self.build_tree(['branch/file'])
1419
        tree.add(['file'])
1420
        try:
1421
            tree.set_reference_info('file', None)
1422
        except errors.UnsupportedOperation:
1423
            raise tests.TestNotApplicable('Branch cannot hold references.')
7447.3.1 by Jelmer Vernooij
Move tree reference info functions to workingtree.
1424
1425
    def make_tree_with_reference(self, location, reference_location):
1426
        tree = self.make_branch_and_tree(location)
7447.4.2 by Jelmer Vernooij
Merge tree reference fixes.
1427
        self.build_tree(
1428
            [os.path.join(location, name)
1429
             for name in ['path/', 'path/to/', 'path/to/file']])
1430
        tree.add(['path', 'path/to', 'path/to/file'])
7447.3.1 by Jelmer Vernooij
Move tree reference info functions to workingtree.
1431
        try:
1432
            tree.set_reference_info('path/to/file', reference_location)
1433
        except errors.UnsupportedOperation:
1434
            raise tests.TestNotApplicable('Branch cannot hold references.')
7447.3.4 by Jelmer Vernooij
Fix tests.
1435
        tree.commit('commit reference')
7447.3.1 by Jelmer Vernooij
Move tree reference info functions to workingtree.
1436
        return tree
1437
1438
    def test_reference_parent_from_reference_info_(self):
1439
        referenced_branch = self.make_branch('reference_branch')
1440
        tree = self.make_tree_with_reference('branch', referenced_branch.base)
1441
        parent = tree.reference_parent('path/to/file')
1442
        self.assertEqual(parent.base, referenced_branch.base)
1443
1444
    def test_branch_relative_reference_location(self):
7447.4.2 by Jelmer Vernooij
Merge tree reference fixes.
1445
        tree = self.make_tree_with_reference('branch', '../reference_branch')
7447.3.1 by Jelmer Vernooij
Move tree reference info functions to workingtree.
1446
        referenced_branch = self.make_branch('reference_branch')
1447
        parent = tree.reference_parent('path/to/file')
1448
        self.assertEqual(parent.base, referenced_branch.base)
1449
1450
    def test_sprout_copies_reference_location(self):
1451
        tree = self.make_tree_with_reference('branch', '../reference')
1452
        new_tree = tree.branch.controldir.sprout('new-branch').open_workingtree()
7447.3.4 by Jelmer Vernooij
Fix tests.
1453
        self.assertEqual(
7449.2.8 by Jelmer Vernooij
Merge storing of reference information by file id.
1454
            urlutils.join(urlutils.strip_segment_parameters(tree.branch.user_url),
1455
                          '../reference'),
7447.3.4 by Jelmer Vernooij
Fix tests.
1456
            urlutils.join(urlutils.strip_segment_parameters(new_tree.branch.user_url),
1457
                          new_tree.get_reference_info('path/to/file')))
7447.3.1 by Jelmer Vernooij
Move tree reference info functions to workingtree.
1458
1459
    def test_clone_copies_reference_location(self):
1460
        tree = self.make_tree_with_reference('branch', '../reference')
1461
        new_tree = tree.controldir.clone('new-branch').open_workingtree()
7447.3.4 by Jelmer Vernooij
Fix tests.
1462
        self.assertEqual(
7449.2.8 by Jelmer Vernooij
Merge storing of reference information by file id.
1463
            urlutils.join(urlutils.strip_segment_parameters(tree.branch.user_url), '../reference'),
7447.3.4 by Jelmer Vernooij
Fix tests.
1464
            urlutils.join(urlutils.strip_segment_parameters(new_tree.branch.user_url),
1465
                          new_tree.get_reference_info('path/to/file')))
7447.3.1 by Jelmer Vernooij
Move tree reference info functions to workingtree.
1466
1467
    def test_copied_locations_are_rebased(self):
1468
        tree = self.make_tree_with_reference('branch', 'reference')
1469
        new_tree = tree.controldir.sprout(
1470
            'branch/new-branch').open_workingtree()
7447.3.4 by Jelmer Vernooij
Fix tests.
1471
        self.assertEqual(
7449.2.8 by Jelmer Vernooij
Merge storing of reference information by file id.
1472
            urlutils.join(urlutils.strip_segment_parameters(tree.branch.user_url),
1473
                          'reference'),
7447.3.4 by Jelmer Vernooij
Fix tests.
1474
            urlutils.join(urlutils.strip_segment_parameters(new_tree.branch.user_url),
1475
                          new_tree.get_reference_info('path/to/file')))
7447.3.1 by Jelmer Vernooij
Move tree reference info functions to workingtree.
1476
1477
    def test_update_references_retains_old_references(self):
1478
        tree = self.make_tree_with_reference('branch', 'reference')
1479
        new_tree = self.make_tree_with_reference(
1480
            'new_branch', 'reference2')
1481
        new_tree.branch.update_references(tree.branch)
7447.3.4 by Jelmer Vernooij
Fix tests.
1482
        self.assertEqual(
7449.2.8 by Jelmer Vernooij
Merge storing of reference information by file id.
1483
            urlutils.join(
1484
                urlutils.strip_segment_parameters(tree.branch.user_url),
1485
                'reference'),
7447.3.4 by Jelmer Vernooij
Fix tests.
1486
            urlutils.join(
1487
                urlutils.strip_segment_parameters(tree.branch.user_url),
1488
                tree.get_reference_info('path/to/file')))
7447.3.1 by Jelmer Vernooij
Move tree reference info functions to workingtree.
1489
1490
    def test_update_references_retains_known_references(self):
1491
        tree = self.make_tree_with_reference('branch', 'reference')
1492
        new_tree = self.make_tree_with_reference(
1493
            'new_branch', 'reference2')
1494
        new_tree.branch.update_references(tree.branch)
7447.3.4 by Jelmer Vernooij
Fix tests.
1495
        self.assertEqual(
7449.2.8 by Jelmer Vernooij
Merge storing of reference information by file id.
1496
            urlutils.join(
1497
                urlutils.strip_segment_parameters(tree.branch.user_url),
1498
                'reference'),
7447.3.4 by Jelmer Vernooij
Fix tests.
1499
            urlutils.join(
1500
                urlutils.strip_segment_parameters(tree.branch.user_url),
1501
                tree.get_reference_info('path/to/file')))
7447.3.1 by Jelmer Vernooij
Move tree reference info functions to workingtree.
1502
1503
    def test_update_references_skips_known_references(self):
1504
        tree = self.make_tree_with_reference('branch', 'reference')
1505
        new_tree = tree.controldir.sprout(
1506
            'branch/new-branch').open_workingtree()
7447.4.2 by Jelmer Vernooij
Merge tree reference fixes.
1507
        self.build_tree(['branch/new-branch/foo'])
1508
        new_tree.add('foo')
7447.3.4 by Jelmer Vernooij
Fix tests.
1509
        new_tree.set_reference_info('foo', '../foo')
7447.3.1 by Jelmer Vernooij
Move tree reference info functions to workingtree.
1510
        new_tree.branch.update_references(tree.branch)
7447.3.4 by Jelmer Vernooij
Fix tests.
1511
        self.assertEqual(
7449.2.8 by Jelmer Vernooij
Merge storing of reference information by file id.
1512
            urlutils.join(
1513
                urlutils.strip_segment_parameters(tree.branch.user_url),
1514
                'reference'),
7447.3.4 by Jelmer Vernooij
Fix tests.
1515
            urlutils.join(
1516
                urlutils.strip_segment_parameters(tree.branch.user_url),
1517
                tree.get_reference_info('path/to/file')))
7447.3.1 by Jelmer Vernooij
Move tree reference info functions to workingtree.
1518
1519
    def test_pull_updates_references(self):
1520
        tree = self.make_tree_with_reference('branch', 'reference')
1521
        new_tree = tree.controldir.sprout(
1522
            'branch/new-branch').open_workingtree()
7447.4.2 by Jelmer Vernooij
Merge tree reference fixes.
1523
        self.build_tree(['branch/new-branch/foo'])
1524
        new_tree.add('foo')
7447.3.4 by Jelmer Vernooij
Fix tests.
1525
        new_tree.set_reference_info('foo', '../foo')
1526
        new_tree.commit('set reference')
7447.3.1 by Jelmer Vernooij
Move tree reference info functions to workingtree.
1527
        tree.pull(new_tree.branch)
7447.3.4 by Jelmer Vernooij
Fix tests.
1528
        self.assertEqual(
7449.2.10 by Jelmer Vernooij
Fix tests.
1529
            urlutils.join(urlutils.strip_segment_parameters(new_tree.branch.user_url), '../foo'),
7447.3.4 by Jelmer Vernooij
Fix tests.
1530
            urlutils.join(tree.branch.user_url, tree.get_reference_info('foo')))
7447.3.1 by Jelmer Vernooij
Move tree reference info functions to workingtree.
1531
1532
    def test_push_updates_references(self):
1533
        tree = self.make_tree_with_reference('branch', 'reference')
1534
        new_tree = tree.controldir.sprout(
1535
            'branch/new-branch').open_workingtree()
7447.4.2 by Jelmer Vernooij
Merge tree reference fixes.
1536
        self.build_tree(['branch/new-branch/foo'])
1537
        new_tree.add(['foo'])
7447.3.4 by Jelmer Vernooij
Fix tests.
1538
        new_tree.set_reference_info('foo', '../foo')
1539
        new_tree.commit('add reference')
1540
        tree.pull(new_tree.branch)
1541
        tree.update()
1542
        self.assertEqual(
7449.2.10 by Jelmer Vernooij
Fix tests.
1543
            urlutils.join(urlutils.strip_segment_parameters(new_tree.branch.user_url), '../foo'),
1544
            urlutils.join(urlutils.strip_segment_parameters(tree.branch.user_url), tree.get_reference_info('foo')))
7447.3.1 by Jelmer Vernooij
Move tree reference info functions to workingtree.
1545
1546
    def test_merge_updates_references(self):
7447.3.4 by Jelmer Vernooij
Fix tests.
1547
        orig_tree = self.make_tree_with_reference('branch', 'reference')
1548
        tree = orig_tree.controldir.sprout('tree').open_workingtree()
7447.3.1 by Jelmer Vernooij
Move tree reference info functions to workingtree.
1549
        tree.commit('foo')
7447.3.4 by Jelmer Vernooij
Fix tests.
1550
        orig_tree.pull(tree.branch)
1551
        checkout = orig_tree.branch.create_checkout('checkout', lightweight=True)
7447.3.1 by Jelmer Vernooij
Move tree reference info functions to workingtree.
1552
        checkout.commit('bar')
1553
        tree.lock_write()
1554
        self.addCleanup(tree.unlock)
1555
        merger = merge.Merger.from_revision_ids(tree,
7447.3.4 by Jelmer Vernooij
Fix tests.
1556
                                                orig_tree.branch.last_revision(),
1557
                                                other_branch=orig_tree.branch)
7447.3.1 by Jelmer Vernooij
Move tree reference info functions to workingtree.
1558
        merger.merge_type = merge.Merge3Merger
1559
        merger.do_merge()
7447.3.4 by Jelmer Vernooij
Fix tests.
1560
        self.assertEqual(
7449.2.8 by Jelmer Vernooij
Merge storing of reference information by file id.
1561
            urlutils.join(urlutils.strip_segment_parameters(orig_tree.branch.user_url), 'reference'),
7447.3.4 by Jelmer Vernooij
Fix tests.
1562
            urlutils.join(urlutils.strip_segment_parameters(tree.branch.user_url), tree.get_reference_info('path/to/file')))