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 (
26
TestCaseWithTransport,
31
class TestMove(TestCaseWithTransport):
33
def test_mv_modes(self):
34
"""Test two modes of operation for mv"""
35
tree = self.make_branch_and_tree('.')
36
files = self.build_tree(['a', 'c', 'subdir/'])
37
tree.add(['a', 'c', 'subdir'])
39
self.run_bzr('mv', 'a', 'b')
40
self.failUnlessExists('b')
41
self.failIfExists('a')
43
self.run_bzr('mv', 'b', 'subdir')
44
self.failUnlessExists('subdir/b')
45
self.failIfExists('b')
47
self.run_bzr('mv', 'subdir/b', 'a')
48
self.failUnlessExists('a')
49
self.failIfExists('subdir/b')
51
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')
57
self.run_bzr('mv', 'subdir/a', 'subdir/newa')
58
self.failUnlessExists('subdir/newa')
59
self.failIfExists('subdir/a')
61
def test_mv_unversioned(self):
62
self.build_tree(['unversioned.txt'])
64
["^bzr: ERROR: can't rename: old name .* is not versioned$"],
65
'mv', 'unversioned.txt', 'elsewhere')
67
def test_mv_nonexisting(self):
69
["^bzr: ERROR: can't rename: old working file .* does not exist$"],
70
'mv', 'doesnotexist', 'somewhereelse')
72
def test_mv_unqualified(self):
73
self.run_bzr_error(['^bzr: ERROR: missing file argument$'], 'mv')
75
def test_mv_invalid(self):
76
tree = self.make_branch_and_tree('.')
77
self.build_tree(['test.txt', 'sub1/'])
78
tree.add(['test.txt'])
81
["^bzr: ERROR: destination u'sub1' is not a versioned directory$"],
82
'mv', 'test.txt', 'sub1')
85
["^bzr: ERROR: can't determine destination directory id for u'sub1'$"],
86
'mv', 'test.txt', 'sub1/hello.txt')
88
def test_mv_dirs(self):
89
tree = self.make_branch_and_tree('.')
90
self.build_tree(['hello.txt', 'sub1/'])
91
tree.add(['hello.txt', 'sub1'])
93
self.run_bzr('mv', 'sub1', 'sub2')
94
self.failUnlessExists('sub2')
95
self.failIfExists('sub1')
96
self.run_bzr('mv', 'hello.txt', 'sub2')
97
self.failUnlessExists("sub2/hello.txt")
98
self.failIfExists("hello.txt")
100
tree.read_working_inventory()
101
tree.commit('commit with some things moved to subdirs')
103
self.build_tree(['sub1/'])
105
self.run_bzr('mv', 'sub2/hello.txt', 'sub1')
106
self.failIfExists('sub2/hello.txt')
107
self.failUnlessExists('sub1/hello.txt')
108
self.run_bzr('mv', 'sub2', 'sub1')
109
self.failIfExists('sub2')
110
self.failUnlessExists('sub1/sub2')
112
def test_mv_relative(self):
113
self.build_tree(['sub1/', 'sub1/sub2/', 'sub1/hello.txt'])
114
tree = self.make_branch_and_tree('.')
115
tree.add(['sub1', 'sub1/sub2', 'sub1/hello.txt'])
116
tree.commit('initial tree')
118
os.chdir('sub1/sub2')
119
self.run_bzr('mv', '../hello.txt', '.')
120
self.failUnlessExists('./hello.txt')
121
tree.read_working_inventory()
122
tree.commit('move to parent directory')
126
self.run_bzr('mv', 'sub2/hello.txt', '.')
127
self.failUnlessExists('hello.txt')
129
def test_mv_smoke_aliases(self):
130
# just test that aliases for mv exist, if their behaviour is changed in
131
# the future, then extend the tests.
132
self.build_tree(['a'])
133
tree = self.make_branch_and_tree('.')
136
self.run_bzr('move', 'a', 'b')
137
self.run_bzr('rename', 'b', 'a')
139
def test_mv_through_symlinks(self):
140
if not osutils.has_symlinks():
141
raise TestSkipped('Symlinks are not supported on this platform')
142
tree = self.make_branch_and_tree('.')
143
self.build_tree(['a/', 'a/b'])
146
tree.add(['a', 'a/b', 'c'], ['a-id', 'b-id', 'c-id'])
147
self.run_bzr('mv', 'c/b', 'b')
148
tree = workingtree.WorkingTree.open('.')
149
self.assertEqual('b-id', tree.path2id('b'))