/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
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 -*-
3
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.
8
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.
13
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
1185.50.8 by John Arbash Meinel
Cleanup of test_pull.py headers
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
22
import os
23
import sys
24
25
from bzrlib.branch import Branch
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
26
from bzrlib.osutils import abspath
1185.50.5 by John Arbash Meinel
pull --overwrite should always overwrite, not just if diverged. (Test case from Robey Pointer)
27
from bzrlib.tests.blackbox import ExternalBase
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
28
from bzrlib.uncommit import uncommit
1614.2.8 by Olaf Conradi
Added testcases for using pull with --remember. Moved remember code to
29
1185.50.5 by John Arbash Meinel
pull --overwrite should always overwrite, not just if diverged. (Test case from Robey Pointer)
30
1185.50.7 by John Arbash Meinel
Fix broken test from refactoring blackbox/test_pull
31
class TestPull(ExternalBase):
32
33
    def example_branch(test):
34
        test.runbzr('init')
35
        file('hello', 'wt').write('foo')
36
        test.runbzr('add hello')
37
        test.runbzr('commit -m setup hello')
38
        file('goodbye', 'wt').write('baz')
39
        test.runbzr('add goodbye')
40
        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)
41
42
    def test_pull(self):
43
        """Pull changes from one branch to another."""
44
        os.mkdir('a')
45
        os.chdir('a')
46
47
        self.example_branch()
48
        self.runbzr('pull', retcode=3)
49
        self.runbzr('missing', retcode=3)
50
        self.runbzr('missing .')
51
        self.runbzr('missing')
1185.31.31 by John Arbash Meinel
avoiding 'bzr pull .' means all tests pass under cygwin
52
        if sys.platform not in ('win32', 'cygwin'):
53
            # This is equivalent to doing "bzr pull ."
54
            # Which means that bzr creates 2 branches grabbing
55
            # the same location, and tries to pull.
56
            # However, 2 branches mean 2 locks on the same file
57
            # which ultimately implies a deadlock.
58
            # (non windows platforms allow multiple locks on the
59
            # same file by the same calling process)
60
            self.runbzr('pull')
1185.50.5 by John Arbash Meinel
pull --overwrite should always overwrite, not just if diverged. (Test case from Robey Pointer)
61
        self.runbzr('pull /', retcode=3)
1185.31.31 by John Arbash Meinel
avoiding 'bzr pull .' means all tests pass under cygwin
62
        if sys.platform not in ('win32', 'cygwin'):
63
            self.runbzr('pull')
1185.50.5 by John Arbash Meinel
pull --overwrite should always overwrite, not just if diverged. (Test case from Robey Pointer)
64
65
        os.chdir('..')
66
        self.runbzr('branch a b')
67
        os.chdir('b')
68
        self.runbzr('pull')
69
        os.mkdir('subdir')
70
        self.runbzr('add subdir')
71
        self.runbzr('commit -m blah --unchanged')
72
        os.chdir('../a')
73
        a = Branch.open('.')
74
        b = Branch.open('../b')
75
        self.assertEquals(a.revision_history(), b.revision_history()[:-1])
76
        self.runbzr('pull ../b')
77
        self.assertEquals(a.revision_history(), b.revision_history())
78
        self.runbzr('commit -m blah2 --unchanged')
79
        os.chdir('../b')
80
        self.runbzr('commit -m blah3 --unchanged')
81
        # no overwrite
82
        self.runbzr('pull ../a', retcode=3)
83
        os.chdir('..')
84
        self.runbzr('branch b overwriteme')
85
        os.chdir('overwriteme')
86
        self.runbzr('pull --overwrite ../a')
87
        overwritten = Branch.open('.')
88
        self.assertEqual(overwritten.revision_history(),
89
                         a.revision_history())
90
        os.chdir('../a')
91
        self.runbzr('merge ../b')
92
        self.runbzr('commit -m blah4 --unchanged')
93
        os.chdir('../b/subdir')
94
        self.runbzr('pull ../../a')
95
        self.assertEquals(a.revision_history()[-1], b.revision_history()[-1])
96
        self.runbzr('commit -m blah5 --unchanged')
97
        self.runbzr('commit -m blah6 --unchanged')
98
        os.chdir('..')
99
        self.runbzr('pull ../a')
100
        os.chdir('../a')
101
        self.runbzr('commit -m blah7 --unchanged')
102
        self.runbzr('merge ../b')
103
        self.runbzr('commit -m blah8 --unchanged')
104
        self.runbzr('pull ../b')
105
        self.runbzr('pull ../b')
106
1185.76.2 by Erik Bågfors
test for pull --revision
107
    def test_pull_revision(self):
108
        """Pull some changes from one branch to another."""
109
        os.mkdir('a')
110
        os.chdir('a')
111
112
        self.example_branch()
113
        file('hello2', 'wt').write('foo')
114
        self.runbzr('add hello2')
115
        self.runbzr('commit -m setup hello2')
116
        file('goodbye2', 'wt').write('baz')
117
        self.runbzr('add goodbye2')
118
        self.runbzr('commit -m setup goodbye2')
119
120
        os.chdir('..')
121
        self.runbzr('branch -r 1 a b')
122
        os.chdir('b')
123
        self.runbzr('pull -r 2')
124
        a = Branch.open('../a')
125
        b = Branch.open('.')
1185.76.4 by Erik Bågfors
expanded tabs
126
        self.assertEquals(a.revno(),4)
127
        self.assertEquals(b.revno(),2)
1185.76.2 by Erik Bågfors
test for pull --revision
128
        self.runbzr('pull -r 3')
1185.76.4 by Erik Bågfors
expanded tabs
129
        self.assertEquals(b.revno(),3)
1185.76.2 by Erik Bågfors
test for pull --revision
130
        self.runbzr('pull -r 4')
131
        self.assertEquals(a.revision_history(), b.revision_history())
132
133
1185.50.7 by John Arbash Meinel
Fix broken test from refactoring blackbox/test_pull
134
    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)
135
        # Make sure pull --overwrite overwrites
136
        # even if the target branch has merged
137
        # everything already.
138
        bzr = self.run_bzr
139
140
        def get_rh(expected_len):
141
            rh = self.capture('revision-history')
142
            # Make sure we don't have trailing empty revisions
143
            rh = rh.strip().split('\n')
144
            self.assertEqual(len(rh), expected_len)
145
            return rh
146
147
        os.mkdir('a')
148
        os.chdir('a')
149
        bzr('init')
150
        open('foo', 'wb').write('original\n')
151
        bzr('add', 'foo')
152
        bzr('commit', '-m', 'initial commit')
153
154
        os.chdir('..')
155
        bzr('branch', 'a', 'b')
156
157
        os.chdir('a')
158
        open('foo', 'wb').write('changed\n')
159
        bzr('commit', '-m', 'later change')
160
161
        open('foo', 'wb').write('another\n')
162
        bzr('commit', '-m', 'a third change')
163
164
        rev_history_a = get_rh(3)
165
166
        os.chdir('../b')
167
        bzr('merge', '../a')
168
        bzr('commit', '-m', 'merge')
169
170
        rev_history_b = get_rh(2)
171
172
        bzr('pull', '--overwrite', '../a')
173
        rev_history_b = get_rh(3)
174
175
        self.assertEqual(rev_history_b, rev_history_a)
176
1185.50.7 by John Arbash Meinel
Fix broken test from refactoring blackbox/test_pull
177
    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)
178
        # Make sure pull --overwrite sets the revision-history
179
        # to be identical to the pull source, even if we have convergence
180
        bzr = self.run_bzr
181
182
        def get_rh(expected_len):
183
            rh = self.capture('revision-history')
184
            # Make sure we don't have trailing empty revisions
185
            rh = rh.strip().split('\n')
186
            self.assertEqual(len(rh), expected_len)
187
            return rh
188
189
        os.mkdir('a')
190
        os.chdir('a')
191
        bzr('init')
192
        open('foo', 'wb').write('original\n')
193
        bzr('add', 'foo')
194
        bzr('commit', '-m', 'initial commit')
195
196
        os.chdir('..')
197
        bzr('branch', 'a', 'b')
198
199
        os.chdir('a')
200
        open('foo', 'wb').write('changed\n')
201
        bzr('commit', '-m', 'later change')
202
203
        open('foo', 'wb').write('another\n')
204
        bzr('commit', '-m', 'a third change')
205
206
        rev_history_a = get_rh(3)
207
208
        os.chdir('../b')
209
        bzr('merge', '../a')
210
        bzr('commit', '-m', 'merge')
211
212
        rev_history_b = get_rh(2)
213
214
        os.chdir('../a')
215
        open('foo', 'wb').write('a fourth change\n')
216
        bzr('commit', '-m', 'a fourth change')
217
218
        rev_history_a = get_rh(4)
219
220
        # With convergence, we could just pull over the
221
        # new change, but with --overwrite, we want to switch our history
222
        os.chdir('../b')
223
        bzr('pull', '--overwrite', '../a')
224
        rev_history_b = get_rh(4)
225
226
        self.assertEqual(rev_history_b, rev_history_a)
227
1614.2.8 by Olaf Conradi
Added testcases for using pull with --remember. Moved remember code to
228
    def test_pull_remember(self):
229
        """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.
230
        transport = self.get_transport()
231
        tree_a = self.make_branch_and_tree('branch_a')
232
        branch_a = tree_a.branch
233
        self.build_tree(['branch_a/a'])
234
        tree_a.add('a')
235
        tree_a.commit('commit a')
236
        branch_b = branch_a.bzrdir.sprout('branch_b').open_branch()
237
        tree_b = branch_b.bzrdir.open_workingtree()
238
        branch_c = branch_a.bzrdir.sprout('branch_c').open_branch()
239
        tree_c = branch_c.bzrdir.open_workingtree()
240
        self.build_tree(['branch_a/b'])
241
        tree_a.add('b')
242
        tree_a.commit('commit b')
1614.2.8 by Olaf Conradi
Added testcases for using pull with --remember. Moved remember code to
243
        # reset parent
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
244
        parent = branch_b.get_parent()
245
        branch_b.set_parent(None)
246
        self.assertEqual(None, branch_b.get_parent())
1614.2.8 by Olaf Conradi
Added testcases for using pull with --remember. Moved remember code to
247
        # test pull for failure without parent set
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
248
        os.chdir('branch_b')
1614.2.8 by Olaf Conradi
Added testcases for using pull with --remember. Moved remember code to
249
        out = self.runbzr('pull', retcode=3)
250
        self.assertEquals(out,
251
                ('','bzr: ERROR: No pull location known or specified.\n'))
252
        # test implicit --remember when no parent set, this pull conflicts
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
253
        self.build_tree(['d'])
254
        tree_b.add('d')
255
        tree_b.commit('commit d')
256
        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
257
        self.assertEquals(out,
258
                ('','bzr: ERROR: These branches have diverged.  Try merge.\n'))
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
259
        self.assertEquals(abspath(branch_b.get_parent()), abspath(parent))
1614.2.8 by Olaf Conradi
Added testcases for using pull with --remember. Moved remember code to
260
        # test implicit --remember after resolving previous failure
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
261
        uncommit(branch=branch_b, tree=tree_b)
262
        transport.delete('branch_b/d')
1614.2.8 by Olaf Conradi
Added testcases for using pull with --remember. Moved remember code to
263
        self.runbzr('pull')
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
264
        self.assertEquals(abspath(branch_b.get_parent()), abspath(parent))
1614.2.8 by Olaf Conradi
Added testcases for using pull with --remember. Moved remember code to
265
        # test explicit --remember
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
266
        self.runbzr('pull ../branch_c --remember')
267
        self.assertEquals(abspath(branch_b.get_parent()),
268
                          abspath(branch_c.bzrdir.root_transport.base))