37
55
tree.add(['a', 'c', 'subdir'])
39
57
self.run_bzr('mv', 'a', 'b')
40
self.failUnlessExists('b')
41
self.failIfExists('a')
58
self.assertMoved('a','b')
43
60
self.run_bzr('mv', 'b', 'subdir')
44
self.failUnlessExists('subdir/b')
45
self.failIfExists('b')
61
self.assertMoved('b','subdir/b')
47
63
self.run_bzr('mv', 'subdir/b', 'a')
48
self.failUnlessExists('a')
49
self.failIfExists('subdir/b')
64
self.assertMoved('subdir/b','a')
51
66
self.run_bzr('mv', 'a', 'c', 'subdir')
52
self.failUnlessExists('subdir/a')
53
self.failUnlessExists('subdir/c')
54
self.failIfExists('a')
55
self.failIfExists('c')
67
self.assertMoved('a','subdir/a')
68
self.assertMoved('c','subdir/c')
57
70
self.run_bzr('mv', 'subdir/a', 'subdir/newa')
58
self.failUnlessExists('subdir/newa')
59
self.failIfExists('subdir/a')
71
self.assertMoved('subdir/a','subdir/newa')
61
73
def test_mv_unversioned(self):
62
74
self.build_tree(['unversioned.txt'])
63
75
self.run_bzr_error(
64
["^bzr: ERROR: can't rename: old name .* is not versioned$"],
76
["^bzr: ERROR: Could not rename unversioned.txt => elsewhere."
77
" .*unversioned.txt is not versioned$"],
65
78
'mv', 'unversioned.txt', 'elsewhere')
67
80
def test_mv_nonexisting(self):
68
81
self.run_bzr_error(
69
["^bzr: ERROR: can't rename: old working file .* does not exist$"],
82
["^bzr: ERROR: Could not rename doesnotexist => somewhereelse."
83
" .*doesnotexist is not versioned$"],
70
84
'mv', 'doesnotexist', 'somewhereelse')
72
86
def test_mv_unqualified(self):
91
106
tree.add(['hello.txt', 'sub1'])
93
108
self.run_bzr('mv', 'sub1', 'sub2')
94
self.failUnlessExists('sub2')
95
self.failIfExists('sub1')
109
self.assertMoved('sub1','sub2')
96
111
self.run_bzr('mv', 'hello.txt', 'sub2')
97
self.failUnlessExists("sub2/hello.txt")
98
self.failIfExists("hello.txt")
112
self.assertMoved('hello.txt','sub2/hello.txt')
100
114
tree.read_working_inventory()
101
tree.commit('commit with some things moved to subdirs')
103
116
self.build_tree(['sub1/'])
104
117
tree.add(['sub1'])
105
118
self.run_bzr('mv', 'sub2/hello.txt', 'sub1')
106
self.failIfExists('sub2/hello.txt')
107
self.failUnlessExists('sub1/hello.txt')
119
self.assertMoved('sub2/hello.txt','sub1/hello.txt')
108
121
self.run_bzr('mv', 'sub2', 'sub1')
109
self.failIfExists('sub2')
110
self.failUnlessExists('sub1/sub2')
122
self.assertMoved('sub2','sub1/sub2')
112
124
def test_mv_relative(self):
113
125
self.build_tree(['sub1/', 'sub1/sub2/', 'sub1/hello.txt'])
114
126
tree = self.make_branch_and_tree('.')
115
127
tree.add(['sub1', 'sub1/sub2', 'sub1/hello.txt'])
116
tree.commit('initial tree')
118
129
os.chdir('sub1/sub2')
119
130
self.run_bzr('mv', '../hello.txt', '.')
120
131
self.failUnlessExists('./hello.txt')
121
132
tree.read_working_inventory()
122
tree.commit('move to parent directory')
126
135
self.run_bzr('mv', 'sub2/hello.txt', '.')
127
self.failUnlessExists('hello.txt')
137
self.assertMoved('sub1/sub2/hello.txt','sub1/hello.txt')
129
139
def test_mv_smoke_aliases(self):
130
140
# just test that aliases for mv exist, if their behaviour is changed in
147
157
self.run_bzr('mv', 'c/b', 'b')
148
158
tree = workingtree.WorkingTree.open('.')
149
159
self.assertEqual('b-id', tree.path2id('b'))
161
def test_mv_already_moved_file(self):
162
"""Test bzr mv original_file to moved_file.
164
Tests if a file which has allready been moved by an external tool,
165
is handled correctly by bzr mv.
166
Setup: a is in the working tree, b does not exist.
167
User does: mv a b; bzr mv a b
169
self.build_tree(['a'])
170
tree = self.make_branch_and_tree('.')
174
self.run_bzr('mv', 'a', 'b')
175
self.assertMoved('a','b')
177
def test_mv_already_moved_file_to_versioned_target(self):
178
"""Test bzr mv existing_file to versioned_file.
180
Tests if an attempt to move an existing versioned file
181
to another versiond file will fail.
182
Setup: a and b are in the working tree.
183
User does: rm b; mv a b; bzr mv a b
185
self.build_tree(['a', 'b'])
186
tree = self.make_branch_and_tree('.')
192
["^bzr: ERROR: Could not move a => b. b is already versioned$"],
194
#check that nothing changed
195
self.failIfExists('a')
196
self.failUnlessExists('b')
198
def test_mv_already_moved_file_into_subdir(self):
199
"""Test bzr mv original_file to versioned_directory/file.
201
Tests if a file which has already been moved into a versioned
202
directory by an external tool, is handled correctly by bzr mv.
203
Setup: a and sub/ are in the working tree.
204
User does: mv a sub/a; bzr mv a sub/a
206
self.build_tree(['a', 'sub/'])
207
tree = self.make_branch_and_tree('.')
208
tree.add(['a', 'sub'])
210
os.rename('a', 'sub/a')
211
self.run_bzr('mv', 'a', 'sub/a')
212
self.assertMoved('a','sub/a')
214
def test_mv_already_moved_file_into_unversioned_subdir(self):
215
"""Test bzr mv original_file to unversioned_directory/file.
217
Tests if an attempt to move an existing versioned file
218
into an unversioned directory will fail.
219
Setup: a is in the working tree, sub/ is not.
220
User does: mv a sub/a; bzr mv a sub/a
222
self.build_tree(['a', 'sub/'])
223
tree = self.make_branch_and_tree('.')
226
os.rename('a', 'sub/a')
228
["^bzr: ERROR: Could not move a => a: sub is not versioned$"],
230
self.failIfExists('a')
231
self.failUnlessExists('sub/a')
233
def test_mv_already_moved_files_into_subdir(self):
234
"""Test bzr mv original_files to versioned_directory.
236
Tests if files which has already been moved into a versioned
237
directory by an external tool, is handled correctly by bzr mv.
238
Setup: a1, a2, sub are in the working tree.
239
User does: mv a1 sub/.; bzr mv a1 a2 sub
241
self.build_tree(['a1', 'a2', 'sub/'])
242
tree = self.make_branch_and_tree('.')
243
tree.add(['a1', 'a2', 'sub'])
245
os.rename('a1', 'sub/a1')
246
self.run_bzr('mv', 'a1', 'a2', 'sub')
247
self.assertMoved('a1','sub/a1')
248
self.assertMoved('a2','sub/a2')
250
def test_mv_already_moved_files_into_unversioned_subdir(self):
251
"""Test bzr mv original_file to unversioned_directory.
253
Tests if an attempt to move existing versioned file
254
into an unversioned directory will fail.
255
Setup: a1, a2 are in the working tree, sub is not.
256
User does: mv a1 sub/.; bzr mv a1 a2 sub
258
self.build_tree(['a1', 'a2', 'sub/'])
259
tree = self.make_branch_and_tree('.')
260
tree.add(['a1', 'a2'])
262
os.rename('a1', 'sub/a1')
264
["^bzr: ERROR: Could not move to sub. sub is not versioned$"],
265
'mv', 'a1', 'a2', 'sub')
266
self.failIfExists('a1')
267
self.failUnlessExists('sub/a1')
268
self.failUnlessExists('a2')
269
self.failIfExists('sub/a2')
271
def test_mv_already_moved_file_forcing_after(self):
272
"""Test bzr mv versioned_file to unversioned_file.
274
Tests if an attempt to move an existing versioned file to an existing
275
unversioned file will fail, informing the user to use the --after
276
option to force this.
277
Setup: a is in the working tree, b not versioned.
278
User does: mv a b; touch a; bzr mv a b
280
self.build_tree(['a', 'b'])
281
tree = self.make_branch_and_tree('.')
285
self.build_tree(['a']) #touch a
287
["^bzr: ERROR: Could not rename a => b because both files exist."
288
" \(Use --after to update the Bazaar id\)$"],
290
self.failUnlessExists('a')
291
self.failUnlessExists('b')
293
def test_mv_already_moved_file_using_after(self):
294
"""Test bzr mv --after versioned_file to unversioned_file.
296
Tests if an existing versioned file can be forced to move to an
297
existing unversioned file using the --after option. With the result
298
that bazaar considers the unversioned_file to be moved from
299
versioned_file and versioned_file will become unversioned.
300
Setup: a is in the working tree and b exists.
301
User does: mv a b; touch a; bzr mv a b --after
302
Resulting in a => b and a is unknown.
304
self.build_tree(['a', 'b'])
305
tree = self.make_branch_and_tree('.')
308
self.build_tree(['a']) #touch a
310
self.run_bzr('mv', 'a', 'b', '--after')
311
self.failUnlessExists('a')
312
self.assertNotInWorkingTree('a')#a should be unknown now.
313
self.failUnlessExists('b')
314
self.assertInWorkingTree('b')
316
def test_mv_already_moved_files_forcing_after(self):
317
"""Test bzr mv versioned_files to directory/unversioned_file.
319
Tests if an attempt to move an existing versioned file to an existing
320
unversioned file in some other directory will fail, informing the user
321
to use the --after option to force this.
323
Setup: a1, a2, sub are versioned and in the working tree,
324
sub/a1, sub/a2 are in working tree.
325
User does: mv a* sub; touch a1; touch a2; bzr mv a1 a2 sub
327
self.build_tree(['a1', 'a2', 'sub/', 'sub/a1', 'sub/a2'])
328
tree = self.make_branch_and_tree('.')
329
tree.add(['a1', 'a2', 'sub'])
330
os.rename('a1', 'sub/a1')
331
os.rename('a2', 'sub/a2')
332
self.build_tree(['a1']) #touch a1
333
self.build_tree(['a2']) #touch a2
336
["^bzr: ERROR: Could not rename a1 => sub/a1 because both files exist."
337
" \(Use --after to update the Bazaar id\)$"],
338
'mv', 'a1', 'a2', 'sub')
339
self.failUnlessExists('a1')
340
self.failUnlessExists('a2')
341
self.failUnlessExists('sub/a1')
342
self.failUnlessExists('sub/a2')
344
def test_mv_already_moved_files_using_after(self):
345
"""Test bzr mv --after versioned_file to directory/unversioned_file.
347
Tests if an existing versioned file can be forced to move to an
348
existing unversioned file in some other directory using the --after
349
option. With the result that bazaar considers
350
directory/unversioned_file to be moved from versioned_file and
351
versioned_file will become unversioned.
353
Setup: a1, a2, sub are versioned and in the working tree,
354
sub/a1, sub/a2 are in working tree.
355
User does: mv a* sub; touch a1; touch a2; bzr mv a1 a2 sub --after
357
self.build_tree(['a1', 'a2', 'sub/', 'sub/a1', 'sub/a2'])
358
tree = self.make_branch_and_tree('.')
359
tree.add(['a1', 'a2', 'sub'])
360
os.rename('a1', 'sub/a1')
361
os.rename('a2', 'sub/a2')
362
self.build_tree(['a1']) #touch a1
363
self.build_tree(['a2']) #touch a2
365
self.run_bzr('mv', 'a1', 'a2', 'sub', '--after')
366
self.failUnlessExists('a1')
367
self.failUnlessExists('a2')
368
self.failUnlessExists('sub/a1')
369
self.failUnlessExists('sub/a2')
370
self.assertInWorkingTree('sub/a1')
371
self.assertInWorkingTree('sub/a2')