1
# Copyright (C) 2006 by Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
"""Test for 'bzr mv'"""
21
from bzrlib.tests import TestCaseWithTransport
24
class TestMove(TestCaseWithTransport):
26
def test_mv_modes(self):
27
"""Test two modes of operation for mv"""
28
tree = self.make_branch_and_tree('.')
29
files = self.build_tree(['a', 'c', 'subdir/'])
30
tree.add(['a', 'c', 'subdir'])
32
self.run_bzr('mv', 'a', 'b')
33
self.failUnlessExists('b')
34
self.failIfExists('a')
36
self.run_bzr('mv', 'b', 'subdir')
37
self.failUnlessExists('subdir/b')
38
self.failIfExists('b')
40
self.run_bzr('mv', 'subdir/b', 'a')
41
self.failUnlessExists('a')
42
self.failIfExists('subdir/b')
44
self.run_bzr('mv', 'a', 'c', 'subdir')
45
self.failUnlessExists('subdir/a')
46
self.failUnlessExists('subdir/c')
47
self.failIfExists('a')
48
self.failIfExists('c')
50
self.run_bzr('mv', 'subdir/a', 'subdir/newa')
51
self.failUnlessExists('subdir/newa')
52
self.failIfExists('subdir/a')
54
def test_mv_unversioned(self):
55
self.build_tree(['unversioned.txt'])
57
["^bzr: ERROR: can't rename: old name .* is not versioned$"],
58
'mv', 'unversioned.txt', 'elsewhere')
60
def test_mv_nonexisting(self):
62
["^bzr: ERROR: can't rename: old working file .* does not exist$"],
63
'mv', 'doesnotexist', 'somewhereelse')
65
def test_mv_unqualified(self):
66
self.run_bzr_error(['^bzr: ERROR: missing file argument$'], 'mv')
68
def test_mv_invalid(self):
69
tree = self.make_branch_and_tree('.')
70
self.build_tree(['test.txt', 'sub1/'])
71
tree.add(['test.txt'])
74
["^bzr: ERROR: destination u'sub1' is not a versioned directory$"],
75
'mv', 'test.txt', 'sub1')
78
["^bzr: ERROR: can't determine destination directory id for u'sub1'$"],
79
'mv', 'test.txt', 'sub1/hello.txt')
81
def test_mv_dirs(self):
82
tree = self.make_branch_and_tree('.')
83
self.build_tree(['hello.txt', 'sub1/'])
84
tree.add(['hello.txt', 'sub1'])
86
self.run_bzr('mv', 'sub1', 'sub2')
87
self.failUnlessExists('sub2')
88
self.failIfExists('sub1')
89
self.run_bzr('mv', 'hello.txt', 'sub2')
90
self.failUnlessExists("sub2/hello.txt")
91
self.failIfExists("hello.txt")
93
tree.read_working_inventory()
94
tree.commit('commit with some things moved to subdirs')
96
self.build_tree(['sub1/'])
98
self.run_bzr('mv', 'sub2/hello.txt', 'sub1')
99
self.failIfExists('sub2/hello.txt')
100
self.failUnlessExists('sub1/hello.txt')
101
self.run_bzr('mv', 'sub2', 'sub1')
102
self.failIfExists('sub2')
103
self.failUnlessExists('sub1/sub2')
105
def test_mv_relative(self):
106
self.build_tree(['sub1/', 'sub1/sub2/', 'sub1/hello.txt'])
107
tree = self.make_branch_and_tree('.')
108
tree.add(['sub1', 'sub1/sub2', 'sub1/hello.txt'])
109
tree.commit('initial tree')
111
os.chdir('sub1/sub2')
112
self.run_bzr('mv', '../hello.txt', '.')
113
self.failUnlessExists('./hello.txt')
114
tree.read_working_inventory()
115
tree.commit('move to parent directory')
119
self.run_bzr('mv', 'sub2/hello.txt', '.')
120
self.failUnlessExists('hello.txt')
122
def test_mv_smoke_aliases(self):
123
# just test that aliases for mv exist, if their behaviour is changed in
124
# the future, then extend the tests.
125
self.build_tree(['a'])
126
tree = self.make_branch_and_tree('.')
129
self.run_bzr('move', 'a', 'b')
130
self.run_bzr('rename', 'b', 'a')