~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

Fixed deletion handling

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005 Canonical Ltd
 
1
# Copyright (C) 2005 by Canonical Ltd
2
2
# -*- coding: utf-8 -*-
3
 
#
 
3
 
4
4
# This program is free software; you can redistribute it and/or modify
5
5
# it under the terms of the GNU General Public License as published by
6
6
# the Free Software Foundation; either version 2 of the License, or
7
7
# (at your option) any later version.
8
 
#
 
8
 
9
9
# This program is distributed in the hope that it will be useful,
10
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
12
# GNU General Public License for more details.
13
 
#
 
13
 
14
14
# You should have received a copy of the GNU General Public License
15
15
# along with this program; if not, write to the Free Software
16
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
17
 
18
18
 
19
 
"""Black-box tests for bzr pull."""
 
19
"""Black-box tests for bzr pull.
 
20
"""
20
21
 
21
22
import os
22
23
import sys
23
24
 
24
25
from bzrlib.branch import Branch
25
26
from bzrlib.tests.blackbox import ExternalBase
26
 
from bzrlib.uncommit import uncommit
27
 
 
28
27
 
29
28
class TestPull(ExternalBase):
30
29
 
47
46
        self.runbzr('missing', retcode=3)
48
47
        self.runbzr('missing .')
49
48
        self.runbzr('missing')
50
 
        # this will work on windows because we check for the same branch
51
 
        # in pull - if it fails, it is a regression
52
 
        self.runbzr('pull')
 
49
        if sys.platform not in ('win32', 'cygwin'):
 
50
            # This is equivalent to doing "bzr pull ."
 
51
            # Which means that bzr creates 2 branches grabbing
 
52
            # the same location, and tries to pull.
 
53
            # However, 2 branches mean 2 locks on the same file
 
54
            # which ultimately implies a deadlock.
 
55
            # (non windows platforms allow multiple locks on the
 
56
            # same file by the same calling process)
 
57
            self.runbzr('pull')
53
58
        self.runbzr('pull /', retcode=3)
54
59
        if sys.platform not in ('win32', 'cygwin'):
55
60
            self.runbzr('pull')
96
101
        self.runbzr('pull ../b')
97
102
        self.runbzr('pull ../b')
98
103
 
99
 
    def test_pull_revision(self):
100
 
        """Pull some changes from one branch to another."""
101
 
        os.mkdir('a')
102
 
        os.chdir('a')
103
 
 
104
 
        self.example_branch()
105
 
        file('hello2', 'wt').write('foo')
106
 
        self.runbzr('add hello2')
107
 
        self.runbzr('commit -m setup hello2')
108
 
        file('goodbye2', 'wt').write('baz')
109
 
        self.runbzr('add goodbye2')
110
 
        self.runbzr('commit -m setup goodbye2')
111
 
 
112
 
        os.chdir('..')
113
 
        self.runbzr('branch -r 1 a b')
114
 
        os.chdir('b')
115
 
        self.runbzr('pull -r 2')
116
 
        a = Branch.open('../a')
117
 
        b = Branch.open('.')
118
 
        self.assertEquals(a.revno(),4)
119
 
        self.assertEquals(b.revno(),2)
120
 
        self.runbzr('pull -r 3')
121
 
        self.assertEquals(b.revno(),3)
122
 
        self.runbzr('pull -r 4')
123
 
        self.assertEquals(a.revision_history(), b.revision_history())
124
 
 
125
 
 
126
104
    def test_overwrite_uptodate(self):
127
105
        # Make sure pull --overwrite overwrites
128
106
        # even if the target branch has merged
217
195
 
218
196
        self.assertEqual(rev_history_b, rev_history_a)
219
197
 
220
 
    def test_pull_remember(self):
221
 
        """Pull changes from one branch to another and test parent location."""
222
 
        transport = self.get_transport()
223
 
        tree_a = self.make_branch_and_tree('branch_a')
224
 
        branch_a = tree_a.branch
225
 
        self.build_tree(['branch_a/a'])
226
 
        tree_a.add('a')
227
 
        tree_a.commit('commit a')
228
 
        tree_b = branch_a.bzrdir.sprout('branch_b').open_workingtree()
229
 
        branch_b = tree_b.branch
230
 
        tree_c = branch_a.bzrdir.sprout('branch_c').open_workingtree()
231
 
        branch_c = tree_c.branch
232
 
        self.build_tree(['branch_a/b'])
233
 
        tree_a.add('b')
234
 
        tree_a.commit('commit b')
235
 
        # reset parent
236
 
        parent = branch_b.get_parent()
237
 
        branch_b.set_parent(None)
238
 
        self.assertEqual(None, branch_b.get_parent())
239
 
        # test pull for failure without parent set
240
 
        os.chdir('branch_b')
241
 
        out = self.runbzr('pull', retcode=3)
242
 
        self.assertEquals(out,
243
 
                ('','bzr: ERROR: No pull location known or specified.\n'))
244
 
        # test implicit --remember when no parent set, this pull conflicts
245
 
        self.build_tree(['d'])
246
 
        tree_b.add('d')
247
 
        tree_b.commit('commit d')
248
 
        out = self.runbzr('pull ../branch_a', retcode=3)
249
 
        self.assertEquals(out,
250
 
                ('','bzr: ERROR: These branches have diverged.  Use the merge command to reconcile them.\n'))
251
 
        self.assertEquals(branch_b.get_parent(), parent)
252
 
        # test implicit --remember after resolving previous failure
253
 
        uncommit(branch=branch_b, tree=tree_b)
254
 
        transport.delete('branch_b/d')
255
 
        self.runbzr('pull')
256
 
        self.assertEquals(branch_b.get_parent(), parent)
257
 
        # test explicit --remember
258
 
        self.runbzr('pull ../branch_c --remember')
259
 
        self.assertEquals(branch_b.get_parent(),
260
 
                          branch_c.bzrdir.root_transport.base)
261
 
 
262
 
    def test_pull_bundle(self):
263
 
        from bzrlib.testament import Testament
264
 
        # Build up 2 trees and prepare for a pull
265
 
        tree_a = self.make_branch_and_tree('branch_a')
266
 
        f = open('branch_a/a', 'wb')
267
 
        f.write('hello')
268
 
        f.close()
269
 
        tree_a.add('a')
270
 
        tree_a.commit('message')
271
 
 
272
 
        tree_b = tree_a.bzrdir.sprout('branch_b').open_workingtree()
273
 
 
274
 
        # Make a change to 'a' that 'b' can pull
275
 
        f = open('branch_a/a', 'wb')
276
 
        f.write('hey there')
277
 
        f.close()
278
 
        tree_a.commit('message')
279
 
 
280
 
        # Create the bundle for 'b' to pull
281
 
        os.chdir('branch_a')
282
 
        bundle_file = open('../bundle', 'wb')
283
 
        bundle_file.write(self.run_bzr('bundle', '../branch_b')[0])
284
 
        bundle_file.close()
285
 
 
286
 
        os.chdir('../branch_b')
287
 
        output = self.run_bzr('pull', '../bundle')
288
 
        self.assertEqual('', output[0])
289
 
        self.assertEqual('All changes applied successfully.\n'
290
 
                         '1 revision(s) pulled.\n', output[1])
291
 
 
292
 
        self.assertEqualDiff(tree_a.branch.revision_history(),
293
 
                             tree_b.branch.revision_history())
294
 
 
295
 
        testament_a = Testament.from_revision(tree_a.branch.repository,
296
 
                                              tree_a.get_parent_ids()[0])
297
 
        testament_b = Testament.from_revision(tree_b.branch.repository,
298
 
                                              tree_b.get_parent_ids()[0])
299
 
        self.assertEqualDiff(testament_a.as_text(),
300
 
                             testament_b.as_text())
301
 
 
302
 
        # it is legal to attempt to pull an already-merged bundle
303
 
        output = self.run_bzr('pull', '../bundle')
304
 
        self.assertEqual('', output[0])
305
 
        self.assertEqual('0 revision(s) pulled.\n', output[1])
 
198