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