129
129
self.assertEqual('directory',
130
130
creator.shelf_transform.final_kind(s_bar_trans_id))
132
def _test_shelve_symlink_creation(self, link_name, link_target):
133
self.requireFeature(tests.SymlinkFeature)
134
tree = self.make_branch_and_tree('.')
136
self.addCleanup(tree.unlock)
137
tree.commit('Empty tree')
138
os.symlink(link_target, link_name)
139
tree.add(link_name, 'foo-id')
140
creator = shelf.ShelfCreator(tree, tree.basis_tree())
141
self.addCleanup(creator.finalize)
142
self.assertEqual([('add file', 'foo-id', 'symlink', link_name)],
143
list(creator.iter_shelvable()))
144
creator.shelve_creation('foo-id')
146
s_trans_id = creator.shelf_transform.trans_id_file_id('foo-id')
147
self.failIfExists(link_name)
148
limbo_name = creator.shelf_transform._limbo_name(s_trans_id)
149
self.assertEqual(link_target, osutils.readlink(limbo_name))
150
ptree = creator.shelf_transform.get_preview_tree()
151
self.assertEqual(link_target, ptree.get_symlink_target('foo-id'))
132
153
def test_shelve_symlink_creation(self):
133
self.requireFeature(tests.SymlinkFeature)
134
tree = self.make_branch_and_tree('.')
136
self.addCleanup(tree.unlock)
137
tree.commit('Empty tree')
138
os.symlink('bar', 'foo')
139
tree.add('foo', 'foo-id')
140
creator = shelf.ShelfCreator(tree, tree.basis_tree())
141
self.addCleanup(creator.finalize)
142
self.assertEqual([('add file', 'foo-id', 'symlink', 'foo')],
143
list(creator.iter_shelvable()))
144
creator.shelve_creation('foo-id')
146
s_trans_id = creator.shelf_transform.trans_id_file_id('foo-id')
147
self.failIfExists('foo')
148
limbo_name = creator.shelf_transform._limbo_name(s_trans_id)
149
self.assertEqual('bar', os.readlink(limbo_name))
151
def test_shelve_symlink_target_change(self):
152
self.requireFeature(tests.SymlinkFeature)
153
tree = self.make_branch_and_tree('.')
155
self.addCleanup(tree.unlock)
156
os.symlink('bar', 'foo')
157
tree.add('foo', 'foo-id')
154
self._test_shelve_symlink_creation('foo', 'bar')
156
def test_shelve_unicode_symlink_creation(self):
157
self.requireFeature(tests.UnicodeFilenameFeature)
158
self._test_shelve_symlink_creation(u'fo\N{Euro Sign}o',
161
def _test_shelve_symlink_target_change(self, link_name,
162
old_target, new_target):
163
self.requireFeature(tests.SymlinkFeature)
164
tree = self.make_branch_and_tree('.')
166
self.addCleanup(tree.unlock)
167
os.symlink(old_target, link_name)
168
tree.add(link_name, 'foo-id')
158
169
tree.commit("commit symlink")
160
os.symlink('baz', 'foo')
171
os.symlink(new_target, link_name)
161
172
creator = shelf.ShelfCreator(tree, tree.basis_tree())
162
173
self.addCleanup(creator.finalize)
163
self.assertEqual([('modify target', 'foo-id', 'foo', 'bar', 'baz')],
174
self.assertEqual([('modify target', 'foo-id', link_name,
175
old_target, new_target)],
164
176
list(creator.iter_shelvable()))
165
177
creator.shelve_modify_target('foo-id')
166
178
creator.transform()
167
self.assertEqual('bar', os.readlink('foo'))
179
self.assertEqual(old_target, osutils.readlink(link_name))
168
180
s_trans_id = creator.shelf_transform.trans_id_file_id('foo-id')
169
181
limbo_name = creator.shelf_transform._limbo_name(s_trans_id)
170
self.assertEqual('baz', os.readlink(limbo_name))
182
self.assertEqual(new_target, osutils.readlink(limbo_name))
183
ptree = creator.shelf_transform.get_preview_tree()
184
self.assertEqual(new_target, ptree.get_symlink_target('foo-id'))
186
def test_shelve_symlink_target_change(self):
187
self._test_shelve_symlink_target_change('foo', 'bar', 'baz')
189
def test_shelve_unicode_symlink_target_change(self):
190
self.requireFeature(tests.UnicodeFilenameFeature)
191
self._test_shelve_symlink_target_change(
192
u'fo\N{Euro Sign}o', u'b\N{Euro Sign}ar', u'b\N{Euro Sign}az')
172
194
def test_shelve_creation_no_contents(self):
173
195
tree = self.make_branch_and_tree('.')