23
24
from bzrlib.inventory import (Inventory, ROOT_ID, InventoryFile,
24
25
InventoryDirectory, InventoryEntry)
25
26
import bzrlib.inventory as inventory
26
from bzrlib.osutils import has_symlinks, rename, pathjoin
27
from bzrlib.osutils import (has_symlinks, rename, pathjoin, is_inside_any,
28
is_inside_or_parent_of_any)
27
29
from bzrlib.tests import TestCase, TestCaseWithTransport
28
30
from bzrlib.transform import TreeTransform
29
31
from bzrlib.uncommit import uncommit
32
34
class TestInventory(TestCase):
34
36
def test_is_within(self):
35
from bzrlib.osutils import is_inside_any
37
38
SRC_FOO_C = pathjoin('src', 'foo.c')
38
39
for dirs, fn in [(['src', 'doc'], SRC_FOO_C),
44
45
for dirs, fn in [(['src'], 'srccontrol'),
45
46
(['src'], 'srccontrol/foo')]:
46
47
self.assertFalse(is_inside_any(dirs, fn))
49
def test_is_within_or_parent(self):
50
for dirs, fn in [(['src', 'doc'], 'src/foo.c'),
51
(['src'], 'src/foo.c'),
52
(['src/bar.c'], 'src'),
53
(['src/bar.c', 'bla/foo.c'], 'src'),
56
self.assert_(is_inside_or_parent_of_any(dirs, fn))
58
for dirs, fn in [(['src'], 'srccontrol'),
59
(['srccontrol/foo.c'], 'src'),
60
(['src'], 'srccontrol/foo')]:
61
self.assertFalse(is_inside_or_parent_of_any(dirs, fn))
48
63
def test_ids(self):
49
64
"""Test detection of files within selected directories."""
79
94
('src/hello.c', 'hello-id'),
80
95
], [(path, ie.file_id) for path, ie in inv.iter_entries()])
97
def test_iter_entries_by_dir(self):
100
for args in [('src', 'directory', 'src-id'),
101
('doc', 'directory', 'doc-id'),
102
('src/hello.c', 'file', 'hello-id'),
103
('src/bye.c', 'file', 'bye-id'),
104
('zz', 'file', 'zz-id'),
105
('src/sub/', 'directory', 'sub-id'),
106
('src/zz.c', 'file', 'zzc-id'),
107
('src/sub/a', 'file', 'a-id'),
108
('Makefile', 'file', 'makefile-id')]:
112
('Makefile', 'makefile-id'),
116
('src/bye.c', 'bye-id'),
117
('src/hello.c', 'hello-id'),
118
('src/sub', 'sub-id'),
119
('src/zz.c', 'zzc-id'),
120
('src/sub/a', 'a-id'),
121
], [(path, ie.file_id) for path, ie in inv.iter_entries_by_dir()])
82
123
def test_version(self):
83
124
"""Inventory remembers the text's version."""
196
237
"old_label", self.tree_1,
197
238
"/dev/null", None, None,
199
self.assertEqual(output.getvalue(), "--- old_label\t\n"
240
self.assertEqual(output.getvalue(), "--- old_label\n"
201
242
"@@ -1,1 +0,0 @@\n"
208
249
"new_label", self.tree_1,
209
250
"/dev/null", None, None,
210
251
output, reverse=True)
211
self.assertEqual(output.getvalue(), "--- /dev/null\t\n"
252
self.assertEqual(output.getvalue(), "--- /dev/null\n"
213
254
"@@ -0,0 +1,1 @@\n"
220
261
"/dev/null", self.tree_1,
221
262
"new_label", self.file_2, self.tree_2,
223
self.assertEqual(output.getvalue(), "--- /dev/null\t\n"
264
self.assertEqual(output.getvalue(), "--- /dev/null\n"
225
266
"@@ -1,1 +1,1 @@\n"
291
332
self.inv_1 = self.branch.repository.get_inventory('1')
292
333
self.file_1 = self.inv_1['fileid']
293
334
self.file_active = self.wt.inventory['fileid']
335
self.builder = self.branch.get_commit_builder([], timestamp=time.time(), revision_id='2')
295
337
def test_snapshot_new_revision(self):
296
338
# This tests that a simple commit with no parents makes a new
297
339
# revision value in the inventory entry
298
self.file_active.snapshot('2', 'subdir/file', {}, self.wt,
299
self.branch.repository.weave_store,
300
self.branch.get_transaction())
340
self.file_active.snapshot('2', 'subdir/file', {}, self.wt, self.builder)
301
341
# expected outcome - file_1 has a revision id of '2', and we can get
302
342
# its text of 'file contents' out of the weave.
303
343
self.assertEqual(self.file_1.revision, '1')
312
352
#This tests that a simple commit does not make a new entry for
313
353
# an unchanged inventory entry
314
354
self.file_active.snapshot('2', 'subdir/file', {'1':self.file_1},
316
self.branch.repository.weave_store,
317
self.branch.get_transaction())
355
self.wt, self.builder)
318
356
self.assertEqual(self.file_1.revision, '1')
319
357
self.assertEqual(self.file_active.revision, '1')
320
358
vf = self.branch.repository.weave_store.get_weave(
341
379
versionfile.clone_text('other', '1', ['1'])
342
380
self.file_active.snapshot('2', 'subdir/file',
343
381
{'1':self.file_1, 'other':other_ie},
345
self.branch.repository.weave_store,
346
self.branch.get_transaction())
382
self.wt, self.builder)
347
383
self.assertEqual(self.file_active.revision, '2')
349
385
def test_snapshot_changed(self):
352
388
self.file_active.name='newname'
353
389
rename('subdir/file', 'subdir/newname')
354
390
self.file_active.snapshot('2', 'subdir/newname', {'1':self.file_1},
356
self.branch.repository.weave_store,
357
self.branch.get_transaction())
391
self.wt, self.builder)
358
392
# expected outcome - file_1 has a revision id of '2'
359
393
self.assertEqual(self.file_active.revision, '2')