~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Vincent Ladeuil
  • Date: 2012-01-18 14:09:19 UTC
  • mto: This revision was merged to the branch mainline in revision 6468.
  • Revision ID: v.ladeuil+lp@free.fr-20120118140919-rlvdrhpc0nq1lbwi
Change set/remove to require a lock for the branch config files.

This means that tests (or any plugin for that matter) do not requires an
explicit lock on the branch anymore to change a single option. This also
means the optimisation becomes "opt-in" and as such won't be as
spectacular as it may be and/or harder to get right (nothing fails
anymore).

This reduces the diff by ~300 lines.

Code/tests that were updating more than one config option is still taking
a lock to at least avoid some IOs and demonstrate the benefits through
the decreased number of hpss calls.

The duplication between BranchStack and BranchOnlyStack will be removed
once the same sharing is in place for local config files, at which point
the Stack class itself may be able to host the changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2007, 2009, 2010 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007, 2009-2012 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
33
33
 
34
34
    def test_mkdir_fails_cleanly(self):
35
35
        """'mkdir' fails cleanly when no working tree is available.
36
 
        https://bugs.edge.launchpad.net/bzr/+bug/138600
 
36
        https://bugs.launchpad.net/bzr/+bug/138600
37
37
        """
38
38
        # Since there is a safety working tree above us, we create a bare repo
39
39
        # here locally.
40
40
        shared_repo = self.make_repository('.')
41
41
        self.run_bzr(['mkdir', 'abc'], retcode=3)
42
 
        self.failIfExists('abc')
43
 
 
44
 
 
45
 
class TestVersioning(TestCaseInTempDir):
 
42
        self.assertPathDoesNotExist('abc')
46
43
 
47
44
    def test_mkdir(self):
48
45
        """Basic 'bzr mkdir' operation"""
49
46
 
50
 
        self.run_bzr('init')
 
47
        self.make_branch_and_tree('.')
51
48
        self.run_bzr(['mkdir', 'foo'])
52
49
        self.assert_(os.path.isdir('foo'))
53
50
 
61
58
 
62
59
        self.assertEquals(len(delta.added), 1)
63
60
        self.assertEquals(delta.added[0][0], 'foo')
64
 
        self.failIf(delta.modified)
 
61
        self.assertFalse(delta.modified)
65
62
 
66
63
    def test_mkdir_in_subdir(self):
67
64
        """'bzr mkdir' operation in subdirectory"""
68
65
 
69
 
        self.run_bzr('init')
 
66
        self.make_branch_and_tree('.')
70
67
        self.run_bzr(['mkdir', 'dir'])
71
68
        self.assert_(os.path.isdir('dir'))
72
69
 
73
 
        os.chdir('dir')
74
70
        self.log('Run mkdir in subdir')
75
 
        self.run_bzr(['mkdir', 'subdir'])
76
 
        self.assert_(os.path.isdir('subdir'))
77
 
        os.chdir('..')
 
71
        self.run_bzr(['mkdir', 'subdir'], working_dir='dir')
 
72
        self.assert_(os.path.isdir('dir/subdir'))
78
73
 
79
74
        wt = WorkingTree.open('.')
80
75
 
85
80
        self.assertEquals(len(delta.added), 2)
86
81
        self.assertEquals(delta.added[0][0], 'dir')
87
82
        self.assertEquals(delta.added[1][0], pathjoin('dir','subdir'))
88
 
        self.failIf(delta.modified)
 
83
        self.assertFalse(delta.modified)
89
84
 
90
85
    def test_mkdir_w_nested_trees(self):
91
86
        """'bzr mkdir' with nested trees"""
92
87
 
93
 
        self.run_bzr('init')
94
 
        os.mkdir('a')
95
 
        os.chdir('a')
96
 
        self.run_bzr('init')
97
 
        os.mkdir('b')
98
 
        os.chdir('b')
99
 
        self.run_bzr('init')
100
 
        os.chdir('../..')
 
88
        self.make_branch_and_tree('.')
 
89
        self.make_branch_and_tree('a')
 
90
        self.make_branch_and_tree('a/b')
101
91
 
102
92
        self.run_bzr(['mkdir', 'dir', 'a/dir', 'a/b/dir'])
103
 
        self.failUnless(os.path.isdir('dir'))
104
 
        self.failUnless(os.path.isdir('a/dir'))
105
 
        self.failUnless(os.path.isdir('a/b/dir'))
 
93
        self.assertTrue(os.path.isdir('dir'))
 
94
        self.assertTrue(os.path.isdir('a/dir'))
 
95
        self.assertTrue(os.path.isdir('a/b/dir'))
106
96
 
107
97
        wt = WorkingTree.open('.')
108
98
        wt_a = WorkingTree.open('a')
111
101
        delta = wt.changes_from(wt.basis_tree())
112
102
        self.assertEquals(len(delta.added), 1)
113
103
        self.assertEquals(delta.added[0][0], 'dir')
114
 
        self.failIf(delta.modified)
 
104
        self.assertFalse(delta.modified)
115
105
 
116
106
        delta = wt_a.changes_from(wt_a.basis_tree())
117
107
        self.assertEquals(len(delta.added), 1)
118
108
        self.assertEquals(delta.added[0][0], 'dir')
119
 
        self.failIf(delta.modified)
 
109
        self.assertFalse(delta.modified)
120
110
 
121
111
        delta = wt_b.changes_from(wt_b.basis_tree())
122
112
        self.assertEquals(len(delta.added), 1)
123
113
        self.assertEquals(delta.added[0][0], 'dir')
124
 
        self.failIf(delta.modified)
125
 
 
126
 
    def check_branch(self):
127
 
        """After all the above changes, run the check and upgrade commands.
128
 
 
129
 
        The upgrade should be a no-op."""
130
 
        b = Branch.open(u'.')
131
 
        mutter('branch has %d revisions', b.revno())
132
 
 
133
 
        mutter('check branch...')
134
 
        from bzrlib.check import check
135
 
        check(b, False)
 
114
        self.assertFalse(delta.modified)
 
115
 
 
116
    def test_mkdir_quiet(self):
 
117
        """'bzr mkdir --quiet' should not print a status message"""
 
118
 
 
119
        self.make_branch_and_tree('.')
 
120
        out, err = self.run_bzr(['mkdir', '--quiet', 'foo'])
 
121
        self.assertEquals('', err)
 
122
        self.assertEquals('', out)
136
123
 
137
124
 
138
125
class SubdirCommit(TestCaseWithTransport):
159
146
        new = b.repository.revision_tree(b.get_rev_id(2))
160
147
        new.lock_read()
161
148
 
162
 
        self.assertEqual(new.get_file_by_path('b/two').read(), 'old contents')
163
 
        self.assertEqual(new.get_file_by_path('top').read(), 'old contents')
164
 
        self.assertEqual(new.get_file_by_path('a/one').read(), 'new contents')
 
149
        def get_text_by_path(tree, path):
 
150
            return tree.get_file_text(tree.path2id(path), path)
 
151
 
 
152
        self.assertEqual(get_text_by_path(new, 'b/two'), 'old contents')
 
153
        self.assertEqual(get_text_by_path(new, 'top'), 'old contents')
 
154
        self.assertEqual(get_text_by_path(new, 'a/one'), 'new contents')
165
155
        new.unlock()
166
156
 
167
 
        os.chdir('a')
168
157
        # commit from here should do nothing
169
 
        self.run_bzr(['commit', '.', '-m', 'commit subdir only', '--unchanged'])
 
158
        self.run_bzr(['commit', '.', '-m', 'commit subdir only', '--unchanged'],
 
159
                     working_dir='a')
170
160
        v3 = b.repository.revision_tree(b.get_rev_id(3))
171
161
        v3.lock_read()
172
 
        self.assertEqual(v3.get_file_by_path('b/two').read(), 'old contents')
173
 
        self.assertEqual(v3.get_file_by_path('top').read(), 'old contents')
174
 
        self.assertEqual(v3.get_file_by_path('a/one').read(), 'new contents')
 
162
        self.assertEqual(get_text_by_path(v3, 'b/two'), 'old contents')
 
163
        self.assertEqual(get_text_by_path(v3, 'top'), 'old contents')
 
164
        self.assertEqual(get_text_by_path(v3, 'a/one'), 'new contents')
175
165
        v3.unlock()
176
166
 
177
167
        # commit in subdirectory commits whole tree
178
 
        self.run_bzr(['commit', '-m', 'commit whole tree from subdir'])
 
168
        self.run_bzr(['commit', '-m', 'commit whole tree from subdir'],
 
169
                     working_dir='a')
179
170
        v4 = b.repository.revision_tree(b.get_rev_id(4))
180
171
        v4.lock_read()
181
 
        self.assertEqual(v4.get_file_by_path('b/two').read(), 'new contents')
182
 
        self.assertEqual(v4.get_file_by_path('top').read(), 'new contents')
 
172
        self.assertEqual(get_text_by_path(v4, 'b/two'), 'new contents')
 
173
        self.assertEqual(get_text_by_path(v4, 'top'), 'new contents')
183
174
        v4.unlock()
184
175
 
185
176
        # TODO: factor out some kind of assert_tree_state() method