~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Patch Queue Manager
  • Date: 2016-02-01 19:13:13 UTC
  • mfrom: (6614.2.2 trunk)
  • Revision ID: pqm@pqm.ubuntu.com-20160201191313-wdfvmfff1djde6oq
(vila) Release 2.7.0 (Vincent Ladeuil)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2005-2012, 2016 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
16
16
 
17
17
"""Black-box tests for bzr missing."""
18
18
 
19
 
import os
20
 
 
21
 
from bzrlib import osutils
22
 
 
23
 
from bzrlib.branch import Branch
24
 
from bzrlib.tests import TestCaseWithTransport
25
 
 
26
 
 
27
 
class TestMissing(TestCaseWithTransport):
 
19
from bzrlib import (
 
20
    osutils,
 
21
    tests,
 
22
    )
 
23
 
 
24
 
 
25
class TestMissing(tests.TestCaseWithTransport):
28
26
 
29
27
    def assertMessages(self, out, must_have=(), must_not_have=()):
30
28
        """Check if commit messages are in or not in the output"""
49
47
        self.assertEqual('', err)
50
48
 
51
49
    def test_missing(self):
52
 
        missing = "You are missing 1 revision(s):"
 
50
        missing_one = "You are missing 1 revision:"
 
51
        extra_one = "You have 1 extra revision:"
53
52
 
54
53
        # create a source branch
55
54
        a_tree = self.make_branch_and_tree('a')
62
61
        self.build_tree_contents([('b/a', 'initial\nmore\n')])
63
62
        b_tree.commit(message='more')
64
63
 
 
64
        def run_missing(args, retcode=1, working_dir=None):
 
65
            out, err = self.run_bzr(['missing'] + args,
 
66
                                    retcode=retcode, working_dir=working_dir)
 
67
            # we do not expect any error output.
 
68
            self.assertEqual('', err)
 
69
            return out.splitlines()
 
70
 
 
71
        def run_missing_a(args, retcode=1):
 
72
            return run_missing(['../a'] + args,
 
73
                               retcode=retcode, working_dir='b')
 
74
 
 
75
        def run_missing_b(args, retcode=1):
 
76
            return run_missing(['../b'] + args,
 
77
                               retcode=retcode, working_dir='a')
 
78
 
65
79
        # run missing in a against b
66
80
        # this should not require missing to take out a write lock on a
67
81
        # or b. So we take a write lock on both to test that at the same
72
86
        a_branch.lock_write()
73
87
        b_branch = b_tree.branch
74
88
        b_branch.lock_write()
75
 
        os.chdir('a')
76
 
        out,err = self.run_bzr('missing ../b', retcode=1)
77
 
        lines = out.splitlines()
 
89
 
 
90
        lines = run_missing_b([])
78
91
        # we're missing the extra revision here
79
 
        self.assertEqual(missing, lines[0])
 
92
        self.assertEqual(missing_one, lines[0])
80
93
        # and we expect 8 lines of output which we trust at the moment to be
81
94
        # good.
82
95
        self.assertEqual(8, len(lines))
83
 
        # we do not expect any error output.
84
 
        self.assertEqual('', err)
85
96
        # unlock the branches for the rest of the test
86
97
        a_branch.unlock()
87
98
        b_branch.unlock()
91
102
        a_tree.commit(message='merge')
92
103
 
93
104
        # compare again, but now we have the 'merge' commit extra
94
 
        lines = self.run_bzr('missing ../b', retcode=1)[0].splitlines()
95
 
        self.assertEqual("You have 1 extra revision(s):", lines[0])
96
 
        self.assertEqual(8, len(lines))
97
 
        lines2 = self.run_bzr('missing ../b --mine-only', retcode=1)[0]
98
 
        lines2 = lines2.splitlines()
 
105
        lines = run_missing_b([])
 
106
        self.assertEqual(extra_one, lines[0])
 
107
        self.assertLength(8, lines)
 
108
 
 
109
        lines2 = run_missing_b(['--mine-only'])
99
110
        self.assertEqual(lines, lines2)
100
 
        lines3 = self.run_bzr('missing ../b --theirs-only', retcode=0)[0]
101
 
        self.assertEqualDiff('Other branch is up to date.\n', lines3)
 
111
 
 
112
        lines3 = run_missing_b(['--theirs-only'], retcode=0)
 
113
        self.assertEqualDiff('Other branch has no new revisions.', lines3[0])
102
114
 
103
115
        # relative to a, missing the 'merge' commit
104
 
        os.chdir('../b')
105
 
        lines = self.run_bzr('missing ../a', retcode=1)[0].splitlines()
106
 
        self.assertEqual(missing, lines[0])
107
 
        self.assertEqual(8, len(lines))
108
 
        lines2 = self.run_bzr('missing ../a --theirs-only', retcode=1)[0]
109
 
        lines2 = lines2.splitlines()
 
116
        lines = run_missing_a([])
 
117
        self.assertEqual(missing_one, lines[0])
 
118
        self.assertLength(8, lines)
 
119
 
 
120
        lines2 = run_missing_a(['--theirs-only'])
110
121
        self.assertEqual(lines, lines2)
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]
114
 
        lines4 = lines4.splitlines()
115
 
        self.assertEqual(4, len(lines4))
116
 
        lines4a = self.run_bzr('missing ../a -S', retcode=1)[0]
117
 
        lines4a = lines4a.splitlines()
 
122
 
 
123
        lines3 = run_missing_a(['--mine-only'], retcode=0)
 
124
        self.assertEqualDiff('This branch has no new revisions.', lines3[0])
 
125
 
 
126
        lines4 = run_missing_a(['--short'])
 
127
        self.assertLength(4, lines4)
 
128
 
 
129
        lines4a = run_missing_a(['-S'])
118
130
        self.assertEqual(lines4, lines4a)
119
 
        lines5 = self.run_bzr('missing ../a --line', retcode=1)[0]
120
 
        lines5 = lines5.splitlines()
121
 
        self.assertEqual(2, len(lines5))
122
 
        lines6 = self.run_bzr('missing ../a --reverse', retcode=1)[0]
123
 
        lines6 = lines6.splitlines()
 
131
 
 
132
        lines5 = run_missing_a(['--line'])
 
133
        self.assertLength(2, lines5)
 
134
 
 
135
        lines6 = run_missing_a(['--reverse'])
124
136
        self.assertEqual(lines6, lines)
125
 
        lines7 = self.run_bzr('missing ../a --show-ids', retcode=1)[0]
126
 
        lines7 = lines7.splitlines()
127
 
        self.assertEqual(11, len(lines7))
128
 
        lines8 = self.run_bzr('missing ../a --verbose', retcode=1)[0]
129
 
        lines8 = lines8.splitlines()
 
137
 
 
138
        lines7 = run_missing_a(['--show-ids'])
 
139
        self.assertLength(11, lines7)
 
140
 
 
141
        lines8 =  run_missing_a(['--verbose'])
130
142
        self.assertEqual("modified:", lines8[-2])
131
143
        self.assertEqual("  a", lines8[-1])
132
144
 
133
 
        os.chdir('../a')
134
 
        self.assertEqualDiff('Other branch is up to date.\n',
135
 
                             self.run_bzr('missing ../b --theirs-only')[0])
 
145
        self.assertEqualDiff('Other branch has no new revisions.',
 
146
                             run_missing_b(['--theirs-only'], retcode=0)[0])
136
147
 
137
148
        # after a pull we're back on track
138
149
        b_tree.pull(a_branch)
139
 
        self.assertEqualDiff("Branches are up to date.\n",
140
 
                             self.run_bzr('missing ../b')[0])
141
 
        os.chdir('../b')
142
 
        self.assertEqualDiff('Branches are up to date.\n',
143
 
                             self.run_bzr('missing ../a')[0])
 
150
        self.assertEqualDiff("Branches are up to date.",
 
151
                             run_missing_b([], retcode=0)[0])
 
152
        self.assertEqualDiff('Branches are up to date.',
 
153
                             run_missing_a([], retcode=0)[0])
144
154
        # If you supply mine or theirs you only know one side is up to date
145
 
        self.assertEqualDiff('This branch is up to date.\n',
146
 
                             self.run_bzr('missing ../a --mine-only')[0])
147
 
        self.assertEqualDiff('Other branch is up to date.\n',
148
 
                             self.run_bzr('missing ../a --theirs-only')[0])
 
155
        self.assertEqualDiff('This branch has no new revisions.',
 
156
                             run_missing_a(['--mine-only'], retcode=0)[0])
 
157
        self.assertEqualDiff('Other branch has no new revisions.',
 
158
                              run_missing_a(['--theirs-only'], retcode=0)[0])
149
159
 
150
160
    def test_missing_filtered(self):
151
161
        # create a source branch
160
170
            a_tree.commit(message='a%d' % i)
161
171
            b_tree.commit(message='b%d' % i)
162
172
 
163
 
        os.chdir('a')
164
173
        # local
165
 
        out,err = self.run_bzr('missing ../b --my-revision 3', retcode=1)
 
174
        out,err = self.run_bzr('missing ../b --my-revision 3',
 
175
                               retcode=1, working_dir='a')
166
176
        self.assertMessages(out, ('a3', 'b2', 'b3', 'b4', 'b5'), ('a2', 'a4'))
167
177
 
168
 
        out,err = self.run_bzr('missing ../b --my-revision 3..4', retcode=1)
 
178
        out,err = self.run_bzr('missing ../b --my-revision 3..4',
 
179
                               retcode=1, working_dir='a')
169
180
        self.assertMessages(out, ('a3', 'a4'), ('a2', 'a5'))
170
181
 
171
182
        #remote
172
 
        out,err = self.run_bzr('missing ../b -r 3', retcode=1)
 
183
        out,err = self.run_bzr('missing ../b -r 3',
 
184
                               retcode=1, working_dir='a')
173
185
        self.assertMessages(out, ('a2', 'a3', 'a4', 'a5', 'b3'), ('b2', 'b4'))
174
186
 
175
 
        out,err = self.run_bzr('missing ../b -r 3..4', retcode=1)
 
187
        out,err = self.run_bzr('missing ../b -r 3..4',
 
188
                               retcode=1, working_dir='a')
176
189
        self.assertMessages(out, ('b3', 'b4'), ('b2', 'b5'))
177
190
 
178
191
        #both
179
192
        out,err = self.run_bzr('missing ../b --my-revision 3..4 -r 3..4',
180
 
            retcode=1)
 
193
                               retcode=1, working_dir='a')
181
194
        self.assertMessages(out, ('a3', 'a4', 'b3', 'b4'),
182
195
            ('a2', 'a5', 'b2', 'b5'))
183
196
 
191
204
        wt.add('foo')
192
205
        wt.commit('initial')
193
206
 
194
 
        os.chdir('a')
195
 
        location = osutils.getcwd() + '/'
 
207
        location = osutils.getcwd() + '/a/'
196
208
 
197
209
        # clone
198
 
        b.bzrdir.sprout('../b')
 
210
        b.bzrdir.sprout('b')
199
211
 
200
212
        # check last location
201
 
        lines, err = self.run_bzr('missing', working_dir='../b')
202
 
        self.assertEquals('Using saved parent location: %s\n'
203
 
                          'Branches are up to date.\n' % location,
204
 
                          lines)
205
 
        self.assertEquals('', err)
 
213
        lines, err = self.run_bzr('missing', working_dir='b')
 
214
        self.assertEqual('Using saved parent location: %s\n'
 
215
                         'Branches are up to date.\n' % location,
 
216
                         lines)
 
217
        self.assertEqual('', err)
206
218
 
207
219
    def test_missing_directory(self):
208
220
        """Test --directory option"""
217
229
        b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
218
230
        self.build_tree_contents([('b/a', 'initial\nmore\n')])
219
231
        b_tree.commit(message='more')
220
 
        
 
232
 
221
233
        out2, err2 = self.run_bzr('missing --directory a b', retcode=1)
222
 
        os.chdir('a')
223
 
        out1, err1 = self.run_bzr('missing ../b', retcode=1)
 
234
        out1, err1 = self.run_bzr('missing ../b', retcode=1, working_dir='a')
224
235
        self.assertEqualDiff(out1, out2)
225
236
        self.assertEqualDiff(err1, err2)
 
237
 
 
238
    def test_missing_tags(self):
 
239
        """Test showing tags"""
 
240
 
 
241
        # create a source branch
 
242
        a_tree = self.make_branch_and_tree('a')
 
243
        self.build_tree_contents([('a/a', 'initial\n')])
 
244
        a_tree.add('a')
 
245
        a_tree.commit(message='initial')
 
246
 
 
247
        # clone and add a differing revision
 
248
        b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
 
249
        self.build_tree_contents([('b/a', 'initial\nmore\n')])
 
250
        b_tree.commit(message='more')
 
251
        b_tree.branch.tags.set_tag('a-tag', b_tree.last_revision())
 
252
 
 
253
        for log_format in ['long', 'short', 'line']:
 
254
            out, err = self.run_bzr(
 
255
                'missing --log-format={0} ../a'.format(log_format),
 
256
                working_dir='b', retcode=1)
 
257
            self.assertContainsString(out, 'a-tag')
 
258
 
 
259
            out, err = self.run_bzr(
 
260
                'missing --log-format={0} ../b'.format(log_format),
 
261
                working_dir='a', retcode=1)
 
262
            self.assertContainsString(out, 'a-tag')