~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/versioning.py

  • Committer: Martin Pool
  • Date: 2005-09-15 08:57:46 UTC
  • Revision ID: mbp@sourcefrog.net-20050915085746-89170eabc66f8b89
- clean up imports

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
"""Tests of simple versioning operations"""
19
19
 
 
20
# TODO: test adding a file whose directory is not versioned
20
21
# TODO: test trying to commit within a directory that is not yet added
21
22
 
22
23
 
34
35
    
35
36
    def test_mkdir(self): 
36
37
        """Basic 'bzr mkdir' operation"""
 
38
        from bzrlib.commands import run_bzr
37
39
 
38
 
        self.run_bzr('init')
39
 
        self.run_bzr('mkdir', 'foo')
 
40
        run_bzr(['init'])
 
41
        run_bzr(['mkdir', 'foo'])
40
42
        self.assert_(os.path.isdir('foo'))
41
43
 
42
 
        self.run_bzr('mkdir', 'foo', retcode=2)
 
44
        self.assertRaises(OSError, run_bzr, ['mkdir', 'foo'])
43
45
 
44
46
        from bzrlib.diff import compare_trees
45
47
        from bzrlib.branch import Branch
46
 
        b = Branch.open('.')
 
48
        b = Branch('.')
47
49
        
48
50
        delta = compare_trees(b.basis_tree(), b.working_tree())
49
51
 
53
55
        self.assertEquals(delta.added[0][0], 'foo')
54
56
        self.failIf(delta.modified)
55
57
 
56
 
    def test_branch_add_in_unversioned(self):
 
58
    def test_add_in_unversioned(self):
57
59
        """Try to add a file in an unversioned directory.
58
60
 
59
 
        "bzr add" adds the parent as necessary, but simple branch add
60
 
        doesn't do that.
 
61
        smart_add may eventually add the parent as necessary, but simple
 
62
        branch add doesn't do that.
61
63
        """
62
64
        from bzrlib.branch import Branch
63
65
        from bzrlib.errors import NotVersionedError
64
66
 
65
 
        b = Branch.initialize('.')
 
67
        b = Branch('.', init=True)
66
68
 
67
69
        self.build_tree(['foo/',
68
70
                         'foo/hello'])
71
73
                          b.add,
72
74
                          'foo/hello')
73
75
        
74
 
        self.check_branch()
75
 
 
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
 
 
 
76
        self.check_and_upgrade()
 
77
 
 
78
        
120
79
    def test_subdir_add(self):
121
80
        """Add in subdirectory should add only things from there down"""
122
81
        
123
82
        from bzrlib.branch import Branch
 
83
        from bzrlib.commands import run_bzr
124
84
        
125
85
        eq = self.assertEqual
126
86
        ass = self.assert_
127
87
        chdir = os.chdir
128
88
        
129
 
        b = Branch.initialize('.')
 
89
        b = Branch('.', init=True)
130
90
        self.build_tree(['src/', 'README'])
131
91
        
132
92
        eq(sorted(b.unknowns()),
133
93
           ['README', 'src'])
134
94
        
135
 
        self.run_bzr('add', 'src')
 
95
        eq(run_bzr(['add', 'src']), 0)
136
96
        
137
97
        self.build_tree(['src/foo.c'])
138
98
        
139
99
        chdir('src')
140
 
        self.run_bzr('add')
 
100
        eq(run_bzr(['add']), 0)
141
101
        
142
102
        eq(sorted(b.unknowns()), 
143
103
           ['README'])
144
104
        eq(len(b.inventory), 3)
145
105
                
146
106
        chdir('..')
147
 
        self.run_bzr('add')
 
107
        eq(run_bzr(['add']), 0)
148
108
        eq(list(b.unknowns()), [])
149
109
 
150
 
        self.check_branch()
151
 
 
152
 
    def check_branch(self):
 
110
        self.check_and_upgrade()
 
111
 
 
112
 
 
113
    def check_and_upgrade(self):
153
114
        """After all the above changes, run the check and upgrade commands.
154
115
 
155
116
        The upgrade should be a no-op."""
156
 
        b = Branch.open('.')
 
117
        b = Branch('.')
157
118
        debug('branch has %d revisions', b.revno())
158
119
        
159
120
        debug('check branch...')
160
121
        from bzrlib.check import check
161
 
        check(b, False)
 
122
        check(b)
 
123
        
 
124
        debug('upgrade branch...')
 
125
        from bzrlib.upgrade import upgrade
 
126
        upgrade(b)
 
127
        
 
128
        debug('check branch...')
 
129
        from bzrlib.check import check
 
130
        check(b)
162
131
        
163
132
 
164
133
        
 
134
        
165
135
class SubdirCommit(TestCaseInTempDir):
166
136
 
167
137
    def test_subdir_commit(self):
172
142
        self.build_tree(['a/', 'b/'])
173
143
        
174
144
        run_bzr('init')
175
 
        b = Branch.open('.')
 
145
        b = Branch('.')
176
146
        
177
147
        for fn in ('a/one', 'b/two', 'top'):
178
148
            file(fn, 'w').write('old contents')
186
156
        debug('start selective subdir commit')
187
157
        run_bzr('commit', 'a', '-m', 'commit a only')
188
158
        
189
 
        old = b.revision_tree(b.get_rev_id(1))
190
 
        new = b.revision_tree(b.get_rev_id(2))
 
159
        old = b.revision_tree(b.lookup_revision(1))
 
160
        new = b.revision_tree(b.lookup_revision(2))
191
161
        
192
162
        eq(new.get_file_by_path('b/two').read(), 'old contents')
193
163
        eq(new.get_file_by_path('top').read(), 'old contents')
196
166
        os.chdir('a')
197
167
        # commit from here should do nothing
198
168
        run_bzr('commit', '.', '-m', 'commit subdir only', '--unchanged')
199
 
        v3 = b.revision_tree(b.get_rev_id(3))
 
169
        v3 = b.revision_tree(b.lookup_revision(3))
200
170
        eq(v3.get_file_by_path('b/two').read(), 'old contents')
201
171
        eq(v3.get_file_by_path('top').read(), 'old contents')
202
172
        eq(v3.get_file_by_path('a/one').read(), 'new contents')
203
173
                
204
174
        # commit in subdirectory commits whole tree
205
175
        run_bzr('commit', '-m', 'commit whole tree from subdir')
206
 
        v4 = b.revision_tree(b.get_rev_id(4))
 
176
        v4 = b.revision_tree(b.lookup_revision(4))
207
177
        eq(v4.get_file_by_path('b/two').read(), 'new contents')        
208
178
        eq(v4.get_file_by_path('top').read(), 'new contents')
209
179