~bzr-pqm/bzr/bzr.dev

1185.50.5 by John Arbash Meinel
pull --overwrite should always overwrite, not just if diverged. (Test case from Robey Pointer)
1
# Copyright (C) 2005 by Canonical Ltd
2
# -*- coding: utf-8 -*-
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
3
#
1185.50.5 by John Arbash Meinel
pull --overwrite should always overwrite, not just if diverged. (Test case from Robey Pointer)
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
8
#
1185.50.5 by John Arbash Meinel
pull --overwrite should always overwrite, not just if diverged. (Test case from Robey Pointer)
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
13
#
1185.50.5 by John Arbash Meinel
pull --overwrite should always overwrite, not just if diverged. (Test case from Robey Pointer)
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
18
1666.1.5 by Robert Collins
Merge bound branch test performance improvements.
19
"""Black-box tests for bzr pull."""
1185.50.5 by John Arbash Meinel
pull --overwrite should always overwrite, not just if diverged. (Test case from Robey Pointer)
20
21
import os
22
import sys
23
24
from bzrlib.branch import Branch
25
from bzrlib.tests.blackbox import ExternalBase
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
26
from bzrlib.uncommit import uncommit
1614.2.8 by Olaf Conradi
Added testcases for using pull with --remember. Moved remember code to
27
1185.50.5 by John Arbash Meinel
pull --overwrite should always overwrite, not just if diverged. (Test case from Robey Pointer)
28
1185.50.7 by John Arbash Meinel
Fix broken test from refactoring blackbox/test_pull
29
class TestPull(ExternalBase):
30
31
    def example_branch(test):
32
        test.runbzr('init')
33
        file('hello', 'wt').write('foo')
34
        test.runbzr('add hello')
35
        test.runbzr('commit -m setup hello')
36
        file('goodbye', 'wt').write('baz')
37
        test.runbzr('add goodbye')
38
        test.runbzr('commit -m setup goodbye')
1185.50.5 by John Arbash Meinel
pull --overwrite should always overwrite, not just if diverged. (Test case from Robey Pointer)
39
40
    def test_pull(self):
41
        """Pull changes from one branch to another."""
42
        os.mkdir('a')
43
        os.chdir('a')
44
45
        self.example_branch()
46
        self.runbzr('pull', retcode=3)
47
        self.runbzr('missing', retcode=3)
48
        self.runbzr('missing .')
49
        self.runbzr('missing')
1666.1.5 by Robert Collins
Merge bound branch test performance improvements.
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')
1185.50.5 by John Arbash Meinel
pull --overwrite should always overwrite, not just if diverged. (Test case from Robey Pointer)
53
        self.runbzr('pull /', retcode=3)
1185.31.31 by John Arbash Meinel
avoiding 'bzr pull .' means all tests pass under cygwin
54
        if sys.platform not in ('win32', 'cygwin'):
55
            self.runbzr('pull')
1185.50.5 by John Arbash Meinel
pull --overwrite should always overwrite, not just if diverged. (Test case from Robey Pointer)
56
57
        os.chdir('..')
58
        self.runbzr('branch a b')
59
        os.chdir('b')
60
        self.runbzr('pull')
61
        os.mkdir('subdir')
62
        self.runbzr('add subdir')
63
        self.runbzr('commit -m blah --unchanged')
64
        os.chdir('../a')
65
        a = Branch.open('.')
66
        b = Branch.open('../b')
67
        self.assertEquals(a.revision_history(), b.revision_history()[:-1])
68
        self.runbzr('pull ../b')
69
        self.assertEquals(a.revision_history(), b.revision_history())
70
        self.runbzr('commit -m blah2 --unchanged')
71
        os.chdir('../b')
72
        self.runbzr('commit -m blah3 --unchanged')
73
        # no overwrite
74
        self.runbzr('pull ../a', retcode=3)
75
        os.chdir('..')
76
        self.runbzr('branch b overwriteme')
77
        os.chdir('overwriteme')
78
        self.runbzr('pull --overwrite ../a')
79
        overwritten = Branch.open('.')
80
        self.assertEqual(overwritten.revision_history(),
81
                         a.revision_history())
82
        os.chdir('../a')
83
        self.runbzr('merge ../b')
84
        self.runbzr('commit -m blah4 --unchanged')
85
        os.chdir('../b/subdir')
86
        self.runbzr('pull ../../a')
87
        self.assertEquals(a.revision_history()[-1], b.revision_history()[-1])
88
        self.runbzr('commit -m blah5 --unchanged')
89
        self.runbzr('commit -m blah6 --unchanged')
90
        os.chdir('..')
91
        self.runbzr('pull ../a')
92
        os.chdir('../a')
93
        self.runbzr('commit -m blah7 --unchanged')
94
        self.runbzr('merge ../b')
95
        self.runbzr('commit -m blah8 --unchanged')
96
        self.runbzr('pull ../b')
97
        self.runbzr('pull ../b')
98
1185.76.2 by Erik Bågfors
test for pull --revision
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('.')
1185.76.4 by Erik Bågfors
expanded tabs
118
        self.assertEquals(a.revno(),4)
119
        self.assertEquals(b.revno(),2)
1185.76.2 by Erik Bågfors
test for pull --revision
120
        self.runbzr('pull -r 3')
1185.76.4 by Erik Bågfors
expanded tabs
121
        self.assertEquals(b.revno(),3)
1185.76.2 by Erik Bågfors
test for pull --revision
122
        self.runbzr('pull -r 4')
123
        self.assertEquals(a.revision_history(), b.revision_history())
124
125
1185.50.7 by John Arbash Meinel
Fix broken test from refactoring blackbox/test_pull
126
    def test_overwrite_uptodate(self):
1185.50.5 by John Arbash Meinel
pull --overwrite should always overwrite, not just if diverged. (Test case from Robey Pointer)
127
        # Make sure pull --overwrite overwrites
128
        # even if the target branch has merged
129
        # everything already.
130
        bzr = self.run_bzr
131
132
        def get_rh(expected_len):
133
            rh = self.capture('revision-history')
134
            # Make sure we don't have trailing empty revisions
135
            rh = rh.strip().split('\n')
136
            self.assertEqual(len(rh), expected_len)
137
            return rh
138
139
        os.mkdir('a')
140
        os.chdir('a')
141
        bzr('init')
142
        open('foo', 'wb').write('original\n')
143
        bzr('add', 'foo')
144
        bzr('commit', '-m', 'initial commit')
145
146
        os.chdir('..')
147
        bzr('branch', 'a', 'b')
148
149
        os.chdir('a')
150
        open('foo', 'wb').write('changed\n')
151
        bzr('commit', '-m', 'later change')
152
153
        open('foo', 'wb').write('another\n')
154
        bzr('commit', '-m', 'a third change')
155
156
        rev_history_a = get_rh(3)
157
158
        os.chdir('../b')
159
        bzr('merge', '../a')
160
        bzr('commit', '-m', 'merge')
161
162
        rev_history_b = get_rh(2)
163
164
        bzr('pull', '--overwrite', '../a')
165
        rev_history_b = get_rh(3)
166
167
        self.assertEqual(rev_history_b, rev_history_a)
168
1185.50.7 by John Arbash Meinel
Fix broken test from refactoring blackbox/test_pull
169
    def test_overwrite_children(self):
1185.50.5 by John Arbash Meinel
pull --overwrite should always overwrite, not just if diverged. (Test case from Robey Pointer)
170
        # Make sure pull --overwrite sets the revision-history
171
        # to be identical to the pull source, even if we have convergence
172
        bzr = self.run_bzr
173
174
        def get_rh(expected_len):
175
            rh = self.capture('revision-history')
176
            # Make sure we don't have trailing empty revisions
177
            rh = rh.strip().split('\n')
178
            self.assertEqual(len(rh), expected_len)
179
            return rh
180
181
        os.mkdir('a')
182
        os.chdir('a')
183
        bzr('init')
184
        open('foo', 'wb').write('original\n')
185
        bzr('add', 'foo')
186
        bzr('commit', '-m', 'initial commit')
187
188
        os.chdir('..')
189
        bzr('branch', 'a', 'b')
190
191
        os.chdir('a')
192
        open('foo', 'wb').write('changed\n')
193
        bzr('commit', '-m', 'later change')
194
195
        open('foo', 'wb').write('another\n')
196
        bzr('commit', '-m', 'a third change')
197
198
        rev_history_a = get_rh(3)
199
200
        os.chdir('../b')
201
        bzr('merge', '../a')
202
        bzr('commit', '-m', 'merge')
203
204
        rev_history_b = get_rh(2)
205
206
        os.chdir('../a')
207
        open('foo', 'wb').write('a fourth change\n')
208
        bzr('commit', '-m', 'a fourth change')
209
210
        rev_history_a = get_rh(4)
211
212
        # With convergence, we could just pull over the
213
        # new change, but with --overwrite, we want to switch our history
214
        os.chdir('../b')
215
        bzr('pull', '--overwrite', '../a')
216
        rev_history_b = get_rh(4)
217
218
        self.assertEqual(rev_history_b, rev_history_a)
219
1614.2.8 by Olaf Conradi
Added testcases for using pull with --remember. Moved remember code to
220
    def test_pull_remember(self):
221
        """Pull changes from one branch to another and test parent location."""
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
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')
1666.1.4 by Robert Collins
* 'Metadir' is now the default disk format. This improves behaviour in
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
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
232
        self.build_tree(['branch_a/b'])
233
        tree_a.add('b')
234
        tree_a.commit('commit b')
1614.2.8 by Olaf Conradi
Added testcases for using pull with --remember. Moved remember code to
235
        # reset parent
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
236
        parent = branch_b.get_parent()
237
        branch_b.set_parent(None)
238
        self.assertEqual(None, branch_b.get_parent())
1614.2.8 by Olaf Conradi
Added testcases for using pull with --remember. Moved remember code to
239
        # test pull for failure without parent set
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
240
        os.chdir('branch_b')
1614.2.8 by Olaf Conradi
Added testcases for using pull with --remember. Moved remember code to
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
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
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)
1614.2.8 by Olaf Conradi
Added testcases for using pull with --remember. Moved remember code to
249
        self.assertEquals(out,
1740.5.6 by Martin Pool
Clean up many exception classes.
250
                ('','bzr: ERROR: These branches have diverged.  Use the merge command to reconcile them.\n'))
1685.1.19 by John Arbash Meinel
pull/merge/branch/missing should all save the absolute path to the other branch, not the relative one
251
        self.assertEquals(branch_b.get_parent(), parent)
1614.2.8 by Olaf Conradi
Added testcases for using pull with --remember. Moved remember code to
252
        # test implicit --remember after resolving previous failure
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
253
        uncommit(branch=branch_b, tree=tree_b)
254
        transport.delete('branch_b/d')
1614.2.8 by Olaf Conradi
Added testcases for using pull with --remember. Moved remember code to
255
        self.runbzr('pull')
1685.1.19 by John Arbash Meinel
pull/merge/branch/missing should all save the absolute path to the other branch, not the relative one
256
        self.assertEquals(branch_b.get_parent(), parent)
1614.2.8 by Olaf Conradi
Added testcases for using pull with --remember. Moved remember code to
257
        # test explicit --remember
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
258
        self.runbzr('pull ../branch_c --remember')
1685.1.19 by John Arbash Meinel
pull/merge/branch/missing should all save the absolute path to the other branch, not the relative one
259
        self.assertEquals(branch_b.get_parent(),
260
                          branch_c.bzrdir.root_transport.base)
1711.3.3 by John Arbash Meinel
Allow pull to use a bundle as a target,
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
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
295
        testament_a = Testament.from_revision(tree_a.branch.repository,
296
                                              tree_a.get_parent_ids()[0])
1711.3.3 by John Arbash Meinel
Allow pull to use a bundle as a target,
297
        testament_b = Testament.from_revision(tree_b.branch.repository,
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
298
                                              tree_b.get_parent_ids()[0])
1711.3.3 by John Arbash Meinel
Allow pull to use a bundle as a target,
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])