/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
2052.3.2 by John Arbash Meinel
Change Copyright .. by Canonical to Copyright ... Canonical
1
# Copyright (C) 2006 Canonical Ltd
1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
2
#
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.
7
#
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.
12
#
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
16
17
"""Test for 'bzr mv'"""
18
19
import os
20
2091.3.6 by Aaron Bentley
Add symlink test guards
21
from bzrlib import (
22
    osutils,
23
    workingtree,
24
)
1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
25
from bzrlib.tests import TestCaseWithTransport
26
27
28
class TestMove(TestCaseWithTransport):
29
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'])
35
36
        self.run_bzr('mv', 'a', 'b')
1846.1.2 by Wouter van Heyst
test mv more rigorously
37
        self.failUnlessExists('b')
38
        self.failIfExists('a')
39
1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
40
        self.run_bzr('mv', 'b', 'subdir')
1846.1.2 by Wouter van Heyst
test mv more rigorously
41
        self.failUnlessExists('subdir/b')
42
        self.failIfExists('b')
43
1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
44
        self.run_bzr('mv', 'subdir/b', 'a')
1846.1.2 by Wouter van Heyst
test mv more rigorously
45
        self.failUnlessExists('a')
46
        self.failIfExists('subdir/b')
47
1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
48
        self.run_bzr('mv', 'a', 'c', 'subdir')
1846.1.2 by Wouter van Heyst
test mv more rigorously
49
        self.failUnlessExists('subdir/a')
50
        self.failUnlessExists('subdir/c')
51
        self.failIfExists('a')
52
        self.failIfExists('c')
53
1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
54
        self.run_bzr('mv', 'subdir/a', 'subdir/newa')
1846.1.2 by Wouter van Heyst
test mv more rigorously
55
        self.failUnlessExists('subdir/newa')
56
        self.failIfExists('subdir/a')
1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
57
58
    def test_mv_unversioned(self):
59
        self.build_tree(['unversioned.txt'])
60
        self.run_bzr_error(
61
            ["^bzr: ERROR: can't rename: old name .* is not versioned$"],
62
            'mv', 'unversioned.txt', 'elsewhere')
63
64
    def test_mv_nonexisting(self):
65
        self.run_bzr_error(
66
            ["^bzr: ERROR: can't rename: old working file .* does not exist$"],
67
            'mv', 'doesnotexist', 'somewhereelse')
68
69
    def test_mv_unqualified(self):
70
        self.run_bzr_error(['^bzr: ERROR: missing file argument$'], 'mv')
71
        
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'])
76
77
        self.run_bzr_error(
78
            ["^bzr: ERROR: destination u'sub1' is not a versioned directory$"],
1846.1.2 by Wouter van Heyst
test mv more rigorously
79
            'mv', 'test.txt', 'sub1')
1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
80
        
81
        self.run_bzr_error(
82
            ["^bzr: ERROR: can't determine destination directory id for u'sub1'$"],
1846.1.2 by Wouter van Heyst
test mv more rigorously
83
            'mv', 'test.txt', 'sub1/hello.txt')
1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
84
        
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'])
89
1846.1.2 by Wouter van Heyst
test mv more rigorously
90
        self.run_bzr('mv', 'sub1', 'sub2')
91
        self.failUnlessExists('sub2')
92
        self.failIfExists('sub1')
93
        self.run_bzr('mv', 'hello.txt', 'sub2')
1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
94
        self.failUnlessExists("sub2/hello.txt")
95
        self.failIfExists("hello.txt")
96
97
        tree.read_working_inventory()
98
        tree.commit('commit with some things moved to subdirs')
99
100
        self.build_tree(['sub1/'])
101
        tree.add(['sub1'])
1846.1.2 by Wouter van Heyst
test mv more rigorously
102
        self.run_bzr('mv', 'sub2/hello.txt', 'sub1')
1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
103
        self.failIfExists('sub2/hello.txt')
104
        self.failUnlessExists('sub1/hello.txt')
1846.1.2 by Wouter van Heyst
test mv more rigorously
105
        self.run_bzr('mv', 'sub2', 'sub1')
1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
106
        self.failIfExists('sub2')
107
        self.failUnlessExists('sub1/sub2')
108
1846.1.2 by Wouter van Heyst
test mv more rigorously
109
    def test_mv_relative(self):
1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
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')
114
115
        os.chdir('sub1/sub2')
1846.1.2 by Wouter van Heyst
test mv more rigorously
116
        self.run_bzr('mv', '../hello.txt', '.')
1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
117
        self.failUnlessExists('./hello.txt')
118
        tree.read_working_inventory()
119
        tree.commit('move to parent directory')
120
121
        os.chdir('..')
122
1846.1.2 by Wouter van Heyst
test mv more rigorously
123
        self.run_bzr('mv', 'sub2/hello.txt', '.')
1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
124
        self.failUnlessExists('hello.txt')
1846.1.2 by Wouter van Heyst
test mv more rigorously
125
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('.')
131
        tree.add(['a'])
132
133
        self.run_bzr('move', 'a', 'b')
134
        self.run_bzr('rename', 'b', 'a')
2091.3.2 by Aaron Bentley
Traverse non-terminal symlinks for mv et al
135
136
    def test_mv_through_symlinks(self):
2091.3.6 by Aaron Bentley
Add symlink test guards
137
        if not osutils.has_symlinks():
138
            raise TestSkipped('Symlinks are not supported on this platform')
2091.3.2 by Aaron Bentley
Traverse non-terminal symlinks for mv et al
139
        tree = self.make_branch_and_tree('.')
140
        self.build_tree(['a/', 'a/b'])
141
        os.symlink('a', 'c')
142
        os.symlink('.', 'd')
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'))