1
# Copyright (C) 2006 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'"""
25
from bzrlib.tests import TestCaseWithTransport
28
class TestMove(TestCaseWithTransport):
30
def test_mv_modes(self):
31
"""Test two modes of operation for mv"""
32
tree = self.make_branch_and_tree('.')
33
files = self.build_tree(['a', 'c', 'subdir/'])
34
tree.add(['a', 'c', 'subdir'])
36
self.run_bzr('mv', 'a', 'b')
37
self.failUnlessExists('b')
38
self.failIfExists('a')
40
self.run_bzr('mv', 'b', 'subdir')
41
self.failUnlessExists('subdir/b')
42
self.failIfExists('b')
44
self.run_bzr('mv', 'subdir/b', 'a')
45
self.failUnlessExists('a')
46
self.failIfExists('subdir/b')
48
self.run_bzr('mv', 'a', 'c', 'subdir')
49
self.failUnlessExists('subdir/a')
50
self.failUnlessExists('subdir/c')
51
self.failIfExists('a')
52
self.failIfExists('c')
54
self.run_bzr('mv', 'subdir/a', 'subdir/newa')
55
self.failUnlessExists('subdir/newa')
56
self.failIfExists('subdir/a')
58
def test_mv_unversioned(self):
59
self.build_tree(['unversioned.txt'])
61
["^bzr: ERROR: can't rename: old name .* is not versioned$"],
62
'mv', 'unversioned.txt', 'elsewhere')
64
def test_mv_nonexisting(self):
66
["^bzr: ERROR: can't rename: old working file .* does not exist$"],
67
'mv', 'doesnotexist', 'somewhereelse')
69
def test_mv_unqualified(self):
70
self.run_bzr_error(['^bzr: ERROR: missing file argument$'], 'mv')
72
def test_mv_invalid(self):
73
tree = self.make_branch_and_tree('.')
74
self.build_tree(['test.txt', 'sub1/'])
75
tree.add(['test.txt'])
78
["^bzr: ERROR: destination u'sub1' is not a versioned directory$"],
79
'mv', 'test.txt', 'sub1')
82
["^bzr: ERROR: can't determine destination directory id for u'sub1'$"],
83
'mv', 'test.txt', 'sub1/hello.txt')
85
def test_mv_dirs(self):
86
tree = self.make_branch_and_tree('.')
87
self.build_tree(['hello.txt', 'sub1/'])
88
tree.add(['hello.txt', 'sub1'])
90
self.run_bzr('mv', 'sub1', 'sub2')
91
self.failUnlessExists('sub2')
92
self.failIfExists('sub1')
93
self.run_bzr('mv', 'hello.txt', 'sub2')
94
self.failUnlessExists("sub2/hello.txt")
95
self.failIfExists("hello.txt")
97
tree.read_working_inventory()
98
tree.commit('commit with some things moved to subdirs')
100
self.build_tree(['sub1/'])
102
self.run_bzr('mv', 'sub2/hello.txt', 'sub1')
103
self.failIfExists('sub2/hello.txt')
104
self.failUnlessExists('sub1/hello.txt')
105
self.run_bzr('mv', 'sub2', 'sub1')
106
self.failIfExists('sub2')
107
self.failUnlessExists('sub1/sub2')
109
def test_mv_relative(self):
110
self.build_tree(['sub1/', 'sub1/sub2/', 'sub1/hello.txt'])
111
tree = self.make_branch_and_tree('.')
112
tree.add(['sub1', 'sub1/sub2', 'sub1/hello.txt'])
113
tree.commit('initial tree')
115
os.chdir('sub1/sub2')
116
self.run_bzr('mv', '../hello.txt', '.')
117
self.failUnlessExists('./hello.txt')
118
tree.read_working_inventory()
119
tree.commit('move to parent directory')
123
self.run_bzr('mv', 'sub2/hello.txt', '.')
124
self.failUnlessExists('hello.txt')
126
def test_mv_smoke_aliases(self):
127
# just test that aliases for mv exist, if their behaviour is changed in
128
# the future, then extend the tests.
129
self.build_tree(['a'])
130
tree = self.make_branch_and_tree('.')
133
self.run_bzr('move', 'a', 'b')
134
self.run_bzr('rename', 'b', 'a')
136
def test_mv_through_symlinks(self):
137
if not osutils.has_symlinks():
138
raise TestSkipped('Symlinks are not supported on this platform')
139
tree = self.make_branch_and_tree('.')
140
self.build_tree(['a/', 'a/b'])
143
tree.add(['a', 'a/b', 'c'], ['a-id', 'b-id', 'c-id'])
144
self.run_bzr('mv', 'c/b', 'b')
145
tree = workingtree.WorkingTree.open('.')
146
self.assertEqual('b-id', tree.path2id('b'))