/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

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

  • Committer: Martin
  • Date: 2009-11-11 13:19:07 UTC
  • mto: This revision was merged to the branch mainline in revision 4853.
  • Revision ID: gzlist@googlemail.com-20091111131907-jiwjd7yb6yeohsfz
Read potential bundles all in one go, then chop up again for the parsing code

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
"""Black-box tests for bzr missing.
2
 
"""
 
1
# Copyright (C) 2005, 2008 Canonical Ltd
 
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
16
 
 
17
"""Black-box tests for bzr missing."""
3
18
 
4
19
import os
5
20
 
 
21
from bzrlib import osutils
 
22
 
6
23
from bzrlib.branch import Branch
7
 
from bzrlib.tests import TestCaseInTempDir
8
 
 
9
 
class TestMissing(TestCaseInTempDir):
 
24
from bzrlib.tests import TestCaseWithTransport
 
25
 
 
26
 
 
27
class TestMissing(TestCaseWithTransport):
 
28
 
 
29
    def assertMessages(self, out, must_have=(), must_not_have=()):
 
30
        """Check if commit messages are in or not in the output"""
 
31
        for m in must_have:
 
32
            self.assertContainsRe(out, r'\nmessage:\n  %s\n' % m)
 
33
        for m in must_not_have:
 
34
            self.assertNotContainsRe(out, r'\nmessage:\n  %s\n' % m)
 
35
 
 
36
    def test_missing_quiet(self):
 
37
        # <https://bugs.launchpad.net/bzr/+bug/284748>
 
38
        # create a source branch
 
39
        #
 
40
        # XXX: This still needs a test that missing is quiet when there are
 
41
        # missing revisions.
 
42
        a_tree = self.make_branch_and_tree('.')
 
43
        self.build_tree_contents([('a', 'initial\n')])
 
44
        a_tree.add('a')
 
45
        a_tree.commit(message='initial')
 
46
 
 
47
        out, err = self.run_bzr('missing -q .')
 
48
        self.assertEqual('', out)
 
49
        self.assertEqual('', err)
 
50
 
10
51
    def test_missing(self):
11
52
        missing = "You are missing 1 revision(s):"
12
53
 
13
54
        # create a source branch
14
 
        os.mkdir('a')
15
 
        os.chdir('a')
16
 
        self.capture('init')
17
 
        open('a', 'wb').write('initial\n')
18
 
        self.capture('add a')
19
 
        self.capture('commit -m inital')
 
55
        a_tree = self.make_branch_and_tree('a')
 
56
        self.build_tree_contents([('a/a', 'initial\n')])
 
57
        a_tree.add('a')
 
58
        a_tree.commit(message='initial')
20
59
 
21
60
        # clone and add a differing revision
22
 
        self.capture('branch . ../b')
23
 
        os.chdir('../b')
24
 
        open('a', 'ab').write('more\n')
25
 
        self.capture('commit -m more')
 
61
        b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
 
62
        self.build_tree_contents([('b/a', 'initial\nmore\n')])
 
63
        b_tree.commit(message='more')
26
64
 
27
 
        # compare a against b
28
 
        os.chdir('../a')
29
 
        lines = self.capture('missing ../b', retcode=1).splitlines()
 
65
        # run missing in a against b
 
66
        # this should not require missing to take out a write lock on a
 
67
        # or b. So we take a write lock on both to test that at the same
 
68
        # time. This may let the test pass while the default branch is an
 
69
        # os-locking branch, but it will trigger failures with lockdir based
 
70
        # branches.
 
71
        a_branch = a_tree.branch
 
72
        a_branch.lock_write()
 
73
        b_branch = b_tree.branch
 
74
        b_branch.lock_write()
 
75
        os.chdir('a')
 
76
        out,err = self.run_bzr('missing ../b', retcode=1)
 
77
        lines = out.splitlines()
30
78
        # we're missing the extra revision here
31
79
        self.assertEqual(missing, lines[0])
 
80
        # and we expect 8 lines of output which we trust at the moment to be
 
81
        # good.
32
82
        self.assertEqual(8, len(lines))
 
83
        # we do not expect any error output.
 
84
        self.assertEqual('', err)
 
85
        # unlock the branches for the rest of the test
 
86
        a_branch.unlock()
 
87
        b_branch.unlock()
33
88
 
34
89
        # get extra revision from b
35
 
        self.capture('merge ../b')
36
 
        self.capture('commit -m merge')
 
90
        a_tree.merge_from_branch(b_branch)
 
91
        a_tree.commit(message='merge')
37
92
 
38
93
        # compare again, but now we have the 'merge' commit extra
39
 
        lines = self.capture('missing ../b', retcode=1).splitlines()
 
94
        lines = self.run_bzr('missing ../b', retcode=1)[0].splitlines()
40
95
        self.assertEqual("You have 1 extra revision(s):", lines[0])
41
96
        self.assertEqual(8, len(lines))
42
 
        lines2 = self.capture('missing ../b --mine-only', retcode=1)
 
97
        lines2 = self.run_bzr('missing ../b --mine-only', retcode=1)[0]
43
98
        lines2 = lines2.splitlines()
44
99
        self.assertEqual(lines, lines2)
45
 
        lines3 = self.capture('missing ../b --theirs-only', retcode=1)
46
 
        lines3 = lines3.splitlines()
47
 
        self.assertEqual(0, len(lines3))
 
100
        lines3 = self.run_bzr('missing ../b --theirs-only', retcode=0)[0]
 
101
        self.assertEqualDiff('Other branch is up to date.\n', lines3)
48
102
 
49
 
        # relative to a, missing the 'merge' commit 
 
103
        # relative to a, missing the 'merge' commit
50
104
        os.chdir('../b')
51
 
        lines = self.capture('missing ../a', retcode=1).splitlines()
 
105
        lines = self.run_bzr('missing ../a', retcode=1)[0].splitlines()
52
106
        self.assertEqual(missing, lines[0])
53
107
        self.assertEqual(8, len(lines))
54
 
        lines2 = self.capture('missing ../a --theirs-only', retcode=1)
 
108
        lines2 = self.run_bzr('missing ../a --theirs-only', retcode=1)[0]
55
109
        lines2 = lines2.splitlines()
56
110
        self.assertEqual(lines, lines2)
57
 
        lines3 = self.capture('missing ../a --mine-only', retcode=1)
58
 
        lines3 = lines3.splitlines()
59
 
        self.assertEqual(0, len(lines3))
60
 
        lines4 = self.capture('missing ../a --short', retcode=1)
 
111
        lines3 = self.run_bzr('missing ../a --mine-only', retcode=0)[0]
 
112
        self.assertEqualDiff('This branch is up to date.\n', lines3)
 
113
        lines4 = self.run_bzr('missing ../a --short', retcode=1)[0]
61
114
        lines4 = lines4.splitlines()
62
115
        self.assertEqual(4, len(lines4))
63
 
        lines5 = self.capture('missing ../a --line', retcode=1)
 
116
        lines5 = self.run_bzr('missing ../a --line', retcode=1)[0]
64
117
        lines5 = lines5.splitlines()
65
118
        self.assertEqual(2, len(lines5))
66
 
        lines6 = self.capture('missing ../a --reverse', retcode=1)
 
119
        lines6 = self.run_bzr('missing ../a --reverse', retcode=1)[0]
67
120
        lines6 = lines6.splitlines()
68
121
        self.assertEqual(lines6, lines)
69
 
        lines7 = self.capture('missing ../a --show-ids', retcode=1)
 
122
        lines7 = self.run_bzr('missing ../a --show-ids', retcode=1)[0]
70
123
        lines7 = lines7.splitlines()
71
124
        self.assertEqual(11, len(lines7))
72
 
        lines8 = self.capture('missing ../a --verbose', retcode=1)
 
125
        lines8 = self.run_bzr('missing ../a --verbose', retcode=1)[0]
73
126
        lines8 = lines8.splitlines()
74
127
        self.assertEqual("modified:", lines8[-2])
75
128
        self.assertEqual("  a", lines8[-1])
76
129
 
77
 
        
 
130
        os.chdir('../a')
 
131
        self.assertEqualDiff('Other branch is up to date.\n',
 
132
                             self.run_bzr('missing ../b --theirs-only')[0])
 
133
 
78
134
        # after a pull we're back on track
79
 
        self.capture('pull')
80
 
        self.assertEqual("Branches are up to date.\n", 
81
 
                         self.capture('missing ../a'))
82
 
 
 
135
        b_tree.pull(a_branch)
 
136
        self.assertEqualDiff("Branches are up to date.\n",
 
137
                             self.run_bzr('missing ../b')[0])
 
138
        os.chdir('../b')
 
139
        self.assertEqualDiff('Branches are up to date.\n',
 
140
                             self.run_bzr('missing ../a')[0])
 
141
        # If you supply mine or theirs you only know one side is up to date
 
142
        self.assertEqualDiff('This branch is up to date.\n',
 
143
                             self.run_bzr('missing ../a --mine-only')[0])
 
144
        self.assertEqualDiff('Other branch is up to date.\n',
 
145
                             self.run_bzr('missing ../a --theirs-only')[0])
 
146
 
 
147
    def test_missing_filtered(self):
 
148
        # create a source branch
 
149
        a_tree = self.make_branch_and_tree('a')
 
150
        self.build_tree_contents([('a/a', 'initial\n')])
 
151
        a_tree.add('a')
 
152
        a_tree.commit(message='r1')
 
153
        # clone and add differing revisions
 
154
        b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
 
155
 
 
156
        for i in range(2, 6):
 
157
            a_tree.commit(message='a%d' % i)
 
158
            b_tree.commit(message='b%d' % i)
 
159
 
 
160
        os.chdir('a')
 
161
        # local
 
162
        out,err = self.run_bzr('missing ../b --my-revision 3', retcode=1)
 
163
        self.assertMessages(out, ('a3', 'b2', 'b3', 'b4', 'b5'), ('a2', 'a4'))
 
164
 
 
165
        out,err = self.run_bzr('missing ../b --my-revision 3..4', retcode=1)
 
166
        self.assertMessages(out, ('a3', 'a4'), ('a2', 'a5'))
 
167
 
 
168
        #remote
 
169
        out,err = self.run_bzr('missing ../b -r 3', retcode=1)
 
170
        self.assertMessages(out, ('a2', 'a3', 'a4', 'a5', 'b3'), ('b2', 'b4'))
 
171
 
 
172
        out,err = self.run_bzr('missing ../b -r 3..4', retcode=1)
 
173
        self.assertMessages(out, ('b3', 'b4'), ('b2', 'b5'))
 
174
 
 
175
        #both
 
176
        out,err = self.run_bzr('missing ../b --my-revision 3..4 -r 3..4',
 
177
            retcode=1)
 
178
        self.assertMessages(out, ('a3', 'a4', 'b3', 'b4'),
 
179
            ('a2', 'a5', 'b2', 'b5'))
 
180
 
 
181
    def test_missing_check_last_location(self):
 
182
        # check that last location shown as filepath not file URL
 
183
 
 
184
        # create a source branch
 
185
        wt = self.make_branch_and_tree('a')
 
186
        b = wt.branch
 
187
        self.build_tree(['a/foo'])
 
188
        wt.add('foo')
 
189
        wt.commit('initial')
 
190
 
 
191
        os.chdir('a')
 
192
        location = osutils.getcwd() + '/'
 
193
 
 
194
        # clone
 
195
        b.bzrdir.sprout('../b')
 
196
 
 
197
        # check last location
 
198
        lines, err = self.run_bzr('missing', working_dir='../b')
 
199
        self.assertEquals('Using saved parent location: %s\n'
 
200
                          'Branches are up to date.\n' % location,
 
201
                          lines)
 
202
        self.assertEquals('', err)