30
30
wt = self.make_branch_and_tree('b1')
31
31
wt.lock_tree_write()
32
32
self.addCleanup(wt.unlock)
33
self.assertEqual(len(wt.all_file_ids()), 1)
33
self.assertEqual(len(list(wt.all_versioned_paths())), 1)
34
34
with open('b1/a', 'wb') as f: f.write('a test\n')
36
self.assertEqual(len(wt.all_file_ids()), 2)
36
self.assertEqual(len(list(wt.all_versioned_paths())), 2)
37
37
wt.flush() # workaround revert doing wt._write_inventory for now.
40
self.assertEqual(len(wt.all_file_ids()), 1)
40
self.assertEqual(len(list(wt.all_versioned_paths())), 1)
43
43
class TestApplyInventoryDelta(TestCaseWithWorkingTree):
54
54
self.addCleanup(wt.unlock)
55
55
root_id = wt.get_root_id()
56
wt.apply_inventory_delta([(None, 'bar/foo', 'foo-id',
57
inventory.InventoryFile('foo-id', 'foo', parent_id='bar-id')),
58
(None, 'bar', 'bar-id', inventory.InventoryDirectory('bar-id',
56
wt.apply_inventory_delta([(None, 'bar/foo', b'foo-id',
57
inventory.InventoryFile(b'foo-id', 'foo', parent_id=b'bar-id')),
58
(None, 'bar', b'bar-id', inventory.InventoryDirectory(b'bar-id',
59
59
'bar', parent_id=root_id))])
60
self.assertEqual('bar/foo', wt.id2path('foo-id'))
61
self.assertEqual('bar', wt.id2path('bar-id'))
60
self.assertEqual('bar/foo', wt.id2path(b'foo-id'))
61
self.assertEqual('bar', wt.id2path(b'bar-id'))
63
63
def test_remove(self):
64
64
wt = self.make_branch_and_tree('.')
66
66
self.addCleanup(wt.unlock)
67
67
self.build_tree(['foo/', 'foo/bar'])
68
wt.add(['foo', 'foo/bar'], ['foo-id', 'bar-id'])
69
wt.apply_inventory_delta([('foo', None, 'foo-id', None),
70
('foo/bar', None, 'bar-id', None)])
71
self.assertIs(None, wt.path2id('foo'))
68
wt.add(['foo', 'foo/bar'], [b'foo-id', b'bar-id'])
69
wt.apply_inventory_delta([('foo', None, b'foo-id', None),
70
('foo/bar', None, b'bar-id', None)])
71
self.assertFalse(wt.is_versioned('foo'))
73
73
def test_rename_dir_with_children(self):
74
74
wt = self.make_branch_and_tree('.')
77
77
self.addCleanup(wt.unlock)
78
78
self.build_tree(['foo/', 'foo/bar'])
79
79
wt.add(['foo', 'foo/bar'],
81
wt.apply_inventory_delta([('foo', 'baz', 'foo-id',
82
inventory.InventoryDirectory('foo-id', 'baz', root_id))])
80
[b'foo-id', b'bar-id'])
81
wt.apply_inventory_delta([('foo', 'baz', b'foo-id',
82
inventory.InventoryDirectory(b'foo-id', 'baz', root_id))])
83
83
# foo/bar should have been followed the rename of its parent to baz/bar
84
self.assertEqual('baz', wt.id2path('foo-id'))
85
self.assertEqual('baz/bar', wt.id2path('bar-id'))
84
self.assertEqual('baz', wt.id2path(b'foo-id'))
85
self.assertEqual('baz/bar', wt.id2path(b'bar-id'))
87
87
def test_rename_dir_with_children_with_children(self):
88
88
wt = self.make_branch_and_tree('.')
91
91
self.addCleanup(wt.unlock)
92
92
self.build_tree(['foo/', 'foo/bar/', 'foo/bar/baz'])
93
93
wt.add(['foo', 'foo/bar', 'foo/bar/baz'],
94
['foo-id', 'bar-id', 'baz-id'])
95
wt.apply_inventory_delta([('foo', 'quux', 'foo-id',
96
inventory.InventoryDirectory('foo-id', 'quux', root_id))])
94
[b'foo-id', b'bar-id', b'baz-id'])
95
wt.apply_inventory_delta([('foo', 'quux', b'foo-id',
96
inventory.InventoryDirectory(b'foo-id', 'quux', root_id))])
97
97
# foo/bar/baz should have been followed the rename of its parent's
98
98
# parent to quux/bar/baz
99
self.assertEqual('quux/bar/baz', wt.id2path('baz-id'))
99
self.assertEqual('quux/bar/baz', wt.id2path(b'baz-id'))
101
101
def test_rename_file(self):
102
102
wt = self.make_branch_and_tree('.')
104
104
self.addCleanup(wt.unlock)
105
105
self.build_tree(['foo/', 'foo/bar', 'baz/'])
106
106
wt.add(['foo', 'foo/bar', 'baz'],
107
['foo-id', 'bar-id', 'baz-id'])
108
wt.apply_inventory_delta([('foo/bar', 'baz/bar', 'bar-id',
109
inventory.InventoryFile('bar-id', 'bar', 'baz-id'))])
110
self.assertEqual('baz/bar', wt.id2path('bar-id'))
107
[b'foo-id', b'bar-id', b'baz-id'])
108
wt.apply_inventory_delta([('foo/bar', 'baz/bar', b'bar-id',
109
inventory.InventoryFile(b'bar-id', 'bar', b'baz-id'))])
110
self.assertEqual('baz/bar', wt.id2path(b'bar-id'))
112
112
def test_rename_swap(self):
113
113
"""Test the swap-names edge case.
121
121
self.addCleanup(wt.unlock)
122
122
self.build_tree(['foo/', 'foo/bar', 'baz/', 'baz/qux'])
123
123
wt.add(['foo', 'foo/bar', 'baz', 'baz/qux'],
124
['foo-id', 'bar-id', 'baz-id', 'qux-id'])
125
wt.apply_inventory_delta([('foo', 'baz', 'foo-id',
126
inventory.InventoryDirectory('foo-id', 'baz', root_id)),
127
('baz', 'foo', 'baz-id',
128
inventory.InventoryDirectory('baz-id', 'foo', root_id))])
129
self.assertEqual('baz/bar', wt.id2path('bar-id'))
130
self.assertEqual('foo/qux', wt.id2path('qux-id'))
124
[b'foo-id', b'bar-id', b'baz-id', b'qux-id'])
125
wt.apply_inventory_delta([('foo', 'baz', b'foo-id',
126
inventory.InventoryDirectory(b'foo-id', 'baz', root_id)),
127
('baz', 'foo', b'baz-id',
128
inventory.InventoryDirectory(b'baz-id', 'foo', root_id))])
129
self.assertEqual('baz/bar', wt.id2path(b'bar-id'))
130
self.assertEqual('foo/qux', wt.id2path(b'qux-id'))
132
132
def test_child_rename_ordering(self):
133
133
"""Test the rename-parent, move child edge case.
139
139
root_id = wt.get_root_id()
140
140
self.build_tree(['dir/', 'dir/child', 'other/'])
141
141
wt.add(['dir', 'dir/child', 'other'],
142
['dir-id', 'child-id', 'other-id'])
142
[b'dir-id', b'child-id', b'other-id'])
143
143
# this delta moves dir-id to dir2 and reparents
144
144
# child-id to a parent of other-id
145
wt.apply_inventory_delta([('dir', 'dir2', 'dir-id',
146
inventory.InventoryDirectory('dir-id', 'dir2', root_id)),
147
('dir/child', 'other/child', 'child-id',
148
inventory.InventoryFile('child-id', 'child', 'other-id'))])
149
self.assertEqual('dir2', wt.id2path('dir-id'))
150
self.assertEqual('other/child', wt.id2path('child-id'))
145
wt.apply_inventory_delta([('dir', 'dir2', b'dir-id',
146
inventory.InventoryDirectory(b'dir-id', 'dir2', root_id)),
147
('dir/child', 'other/child', b'child-id',
148
inventory.InventoryFile(b'child-id', 'child', b'other-id'))])
149
self.assertEqual('dir2', wt.id2path(b'dir-id'))
150
self.assertEqual('other/child', wt.id2path(b'child-id'))
152
152
def test_replace_root(self):
153
153
wt = self.make_branch_and_tree('.')
170
170
if not base.supports_tree_reference():
171
171
raise tests.TestNotApplicable("wt doesn't support nested trees")
172
172
# We add it as a directory, but it becomes a tree-reference
173
base.add(['subdir'], ['subdir-id'], ['directory'])
173
base.add(['subdir'], [b'subdir-id'], ['directory'])
174
174
subdir = self.make_branch_and_tree('base/subdir')
175
175
self.addCleanup(base.lock_read().unlock)
176
176
# Note: we aren't strict about ie.kind being 'directory' here, what we
177
177
# are strict about is that wt.inventory should match
178
178
# wt.current_dirstate()'s idea about what files are where.
179
ie = base.inventory['subdir-id']
179
ie = base.inventory[b'subdir-id']
180
180
self.assertEqual('directory', ie.kind)
181
path, ie = next(base.iter_entries_by_dir(['subdir-id']))
181
path, ie = next(base.iter_entries_by_dir(specific_files=['subdir']))
182
182
self.assertEqual('subdir', path)
183
183
self.assertEqual('tree-reference', ie.kind)