~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_versioning.py

Merge from integration

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
import os
24
24
 
25
 
from bzrlib.selftest import BzrTestBase, TestCaseInTempDir
 
25
from bzrlib.tests import BzrTestBase, TestCaseInTempDir
26
26
from bzrlib.branch import Branch
27
 
 
28
 
import logging
29
 
logger = logging.getLogger('bzr.test.versioning')
30
 
debug = logger.debug
 
27
from bzrlib.trace import mutter
31
28
 
32
29
 
33
30
class TestVersioning(TestCaseInTempDir):
53
50
        self.assertEquals(delta.added[0][0], 'foo')
54
51
        self.failIf(delta.modified)
55
52
 
56
 
    def test_branch_add_in_unversioned(self):
 
53
    def test_mkdir_in_subdir(self):
 
54
        """'bzr mkdir' operation in subdirectory"""
 
55
 
 
56
        self.run_bzr('init')
 
57
        self.run_bzr('mkdir', 'dir')
 
58
        self.assert_(os.path.isdir('dir'))
 
59
 
 
60
        os.chdir('dir')
 
61
        self.log('Run mkdir in subdir')
 
62
        self.run_bzr('mkdir', 'subdir')
 
63
        self.assert_(os.path.isdir('subdir'))
 
64
        os.chdir('..')
 
65
 
 
66
        from bzrlib.diff import compare_trees
 
67
        from bzrlib.branch import Branch
 
68
        b = Branch.open('.')
 
69
        
 
70
        delta = compare_trees(b.basis_tree(), b.working_tree())
 
71
 
 
72
        self.log('delta.added = %r' % delta.added)
 
73
 
 
74
        self.assertEquals(len(delta.added), 2)
 
75
        self.assertEquals(delta.added[0][0], 'dir')
 
76
        self.assertEquals(delta.added[1][0], os.path.join('dir','subdir'))
 
77
        self.failIf(delta.modified)
 
78
 
 
79
    def test_mkdir_w_nested_trees(self):
 
80
        """'bzr mkdir' with nested trees"""
 
81
 
 
82
        self.run_bzr('init')
 
83
        os.mkdir('a')
 
84
        os.chdir('a')
 
85
        self.run_bzr('init')
 
86
        os.mkdir('b')
 
87
        os.chdir('b')
 
88
        self.run_bzr('init')
 
89
        os.chdir('../..')
 
90
 
 
91
        self.run_bzr('mkdir', 'dir', 'a/dir', 'a/b/dir')
 
92
        self.failUnless(os.path.isdir('dir'))
 
93
        self.failUnless(os.path.isdir('a/dir'))
 
94
        self.failUnless(os.path.isdir('a/b/dir'))
 
95
 
 
96
        from bzrlib.diff import compare_trees
 
97
        b = Branch.open('.')
 
98
        b_a = Branch.open('a')
 
99
        b_b = Branch.open('a/b')
 
100
        
 
101
        delta = compare_trees(b.basis_tree(), b.working_tree())
 
102
        self.assertEquals(len(delta.added), 1)
 
103
        self.assertEquals(delta.added[0][0], 'dir')
 
104
        self.failIf(delta.modified)
 
105
 
 
106
        delta = compare_trees(b_a.basis_tree(), b_a.working_tree())
 
107
        self.assertEquals(len(delta.added), 1)
 
108
        self.assertEquals(delta.added[0][0], 'dir')
 
109
        self.failIf(delta.modified)
 
110
 
 
111
        delta = compare_trees(b_b.basis_tree(), b_b.working_tree())
 
112
        self.assertEquals(len(delta.added), 1)
 
113
        self.assertEquals(delta.added[0][0], 'dir')
 
114
        self.failIf(delta.modified)
 
115
 
 
116
    def test_working_tree_add_in_unversioned(self):
57
117
        """Try to add a file in an unversioned directory.
58
118
 
59
 
        "bzr add" adds the parent as necessary, but simple branch add
 
119
        "bzr add" adds the parent as necessary, but simple working tree add
60
120
        doesn't do that.
61
121
        """
62
122
        from bzrlib.branch import Branch
63
123
        from bzrlib.errors import NotVersionedError
 
124
        from bzrlib.workingtree import WorkingTree
64
125
 
65
126
        b = Branch.initialize('.')
66
127
 
68
129
                         'foo/hello'])
69
130
 
70
131
        self.assertRaises(NotVersionedError,
71
 
                          b.add,
 
132
                          WorkingTree(b.base, b).add,
72
133
                          'foo/hello')
73
134
        
74
135
        self.check_branch()
75
136
 
76
 
    def test_add_in_unversioned(self):
77
 
        """Try to add a file in an unversioned directory.
78
 
 
79
 
        "bzr add" should add the parent(s) as necessary.
80
 
        """
81
 
        from bzrlib.branch import Branch
82
 
        eq = self.assertEqual
83
 
 
84
 
        b = Branch.initialize('.')
85
 
 
86
 
        self.build_tree(['inertiatic/', 'inertiatic/esp'])
87
 
        eq(list(b.unknowns()), ['inertiatic'])
88
 
        self.run_bzr('add', 'inertiatic/esp')
89
 
        eq(list(b.unknowns()), [])
90
 
 
91
 
        # Multiple unversioned parents
92
 
        self.build_tree(['veil/', 'veil/cerpin/', 'veil/cerpin/taxt'])
93
 
        eq(list(b.unknowns()), ['veil'])
94
 
        self.run_bzr('add', 'veil/cerpin/taxt')
95
 
        eq(list(b.unknowns()), [])
96
 
 
97
 
        # Check whacky paths work
98
 
        self.build_tree(['cicatriz/', 'cicatriz/esp'])
99
 
        eq(list(b.unknowns()), ['cicatriz'])
100
 
        self.run_bzr('add', 'inertiatic/../cicatriz/esp')
101
 
        eq(list(b.unknowns()), [])
102
 
 
103
 
    def test_add_in_versioned(self):
104
 
        """Try to add a file in a versioned directory.
105
 
 
106
 
        "bzr add" should do this happily.
107
 
        """
108
 
        from bzrlib.branch import Branch
109
 
        eq = self.assertEqual
110
 
 
111
 
        b = Branch.initialize('.')
112
 
 
113
 
        self.build_tree(['inertiatic/', 'inertiatic/esp'])
114
 
        eq(list(b.unknowns()), ['inertiatic'])
115
 
        self.run_bzr('add', '--no-recurse', 'inertiatic')
116
 
        eq(list(b.unknowns()), ['inertiatic'+os.sep+'esp'])
117
 
        self.run_bzr('add', 'inertiatic/esp')
118
 
        eq(list(b.unknowns()), [])
119
 
 
120
 
    def test_subdir_add(self):
121
 
        """Add in subdirectory should add only things from there down"""
122
 
        
123
 
        from bzrlib.branch import Branch
124
 
        
125
 
        eq = self.assertEqual
126
 
        ass = self.assert_
127
 
        chdir = os.chdir
128
 
        
129
 
        b = Branch.initialize('.')
130
 
        t = b.working_tree()
131
 
        self.build_tree(['src/', 'README'])
132
 
        
133
 
        eq(sorted(b.unknowns()),
134
 
           ['README', 'src'])
135
 
        
136
 
        self.run_bzr('add', 'src')
137
 
        
138
 
        self.build_tree(['src/foo.c'])
139
 
        
140
 
        chdir('src')
141
 
        self.run_bzr('add')
142
 
        
143
 
        eq(sorted(b.unknowns()), 
144
 
           ['README'])
145
 
        eq(len(t.read_working_inventory()), 3)
146
 
                
147
 
        chdir('..')
148
 
        self.run_bzr('add')
149
 
        eq(list(b.unknowns()), [])
150
 
 
151
 
        self.check_branch()
152
 
 
153
137
    def check_branch(self):
154
138
        """After all the above changes, run the check and upgrade commands.
155
139
 
156
140
        The upgrade should be a no-op."""
157
141
        b = Branch.open('.')
158
 
        debug('branch has %d revisions', b.revno())
 
142
        mutter('branch has %d revisions', b.revno())
159
143
        
160
 
        debug('check branch...')
 
144
        mutter('check branch...')
161
145
        from bzrlib.check import check
162
146
        check(b, False)
163
 
        
164
 
 
165
 
        
 
147
 
 
148
 
166
149
class SubdirCommit(TestCaseInTempDir):
167
150
 
168
151
    def test_subdir_commit(self):
184
167
        for fn in ('a/one', 'b/two', 'top'):
185
168
            file(fn, 'w').write('new contents')
186
169
            
187
 
        debug('start selective subdir commit')
 
170
        mutter('start selective subdir commit')
188
171
        run_bzr('commit', 'a', '-m', 'commit a only')
189
172
        
190
173
        old = b.storage.revision_tree(b.get_rev_id(1))