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.run_bzr('mv', 'b', 'subdir')
34
self.run_bzr('mv', 'subdir/b', 'a')
35
self.run_bzr('mv', 'a', 'c', 'subdir')
36
self.run_bzr('mv', 'subdir/a', 'subdir/newa')
38
def test_mv_unversioned(self):
39
self.build_tree(['unversioned.txt'])
41
["^bzr: ERROR: can't rename: old name .* is not versioned$"],
42
'mv', 'unversioned.txt', 'elsewhere')
44
def test_mv_nonexisting(self):
46
["^bzr: ERROR: can't rename: old working file .* does not exist$"],
47
'mv', 'doesnotexist', 'somewhereelse')
49
def test_mv_unqualified(self):
50
self.run_bzr_error(['^bzr: ERROR: missing file argument$'], 'mv')
52
def test_mv_newly_added(self):
53
tree = self.make_branch_and_tree('.')
54
self.build_tree(['test.txt'])
55
tree.add(['test.txt'])
57
self.run_bzr('mv', 'test.txt', 'hello.txt')
58
self.failUnlessExists("hello.txt")
59
self.failIfExists("test.txt")
61
def test_mv_invalid(self):
62
tree = self.make_branch_and_tree('.')
63
self.build_tree(['test.txt', 'sub1/'])
64
tree.add(['test.txt'])
67
["^bzr: ERROR: destination u'sub1' is not a versioned directory$"],
68
'rename', 'test.txt', 'sub1')
71
["^bzr: ERROR: can't determine destination directory id for u'sub1'$"],
72
'rename', 'test.txt', 'sub1/hello.txt')
75
["^bzr: ERROR: destination u'sub1' is not a versioned directory$"],
76
'move', 'test.txt', 'sub1')
78
def test_mv_dirs(self):
79
tree = self.make_branch_and_tree('.')
80
self.build_tree(['hello.txt', 'sub1/'])
81
tree.add(['hello.txt', 'sub1'])
83
self.run_bzr('rename', 'sub1', 'sub2')
84
self.run_bzr('move', 'hello.txt', 'sub2')
86
self.failUnlessExists("sub2")
87
self.failUnlessExists("sub2/hello.txt")
88
self.failIfExists("sub1")
89
self.failIfExists("hello.txt")
91
tree.read_working_inventory()
92
tree.commit('commit with some things moved to subdirs')
94
self.build_tree(['sub1/'])
96
self.run_bzr('move', 'sub2/hello.txt', 'sub1')
97
self.failIfExists('sub2/hello.txt')
98
self.failUnlessExists('sub1/hello.txt')
99
self.run_bzr('move', 'sub2', 'sub1')
100
self.failIfExists('sub2')
101
self.failUnlessExists('sub1/sub2')
103
def test_mv_relative(self):
104
self.build_tree(['sub1/', 'sub1/sub2/', 'sub1/hello.txt'])
105
tree = self.make_branch_and_tree('.')
106
tree.add(['sub1', 'sub1/sub2', 'sub1/hello.txt'])
107
tree.commit('initial tree')
109
os.chdir('sub1/sub2')
110
self.run_bzr('move', '../hello.txt', '.')
111
self.failUnlessExists('./hello.txt')
112
tree.read_working_inventory()
113
tree.commit('move to parent directory')
117
self.run_bzr('move', 'sub2/hello.txt', '.')
118
self.failUnlessExists('hello.txt')