/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_pull.py

  • Committer: Martin Pool
  • Date: 2007-09-14 06:31:28 UTC
  • mfrom: (2822 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2823.
  • Revision ID: mbp@sourcefrog.net-20070914063128-0p7mh6zfb4pzdg9p
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
import sys
22
22
 
23
23
from bzrlib.branch import Branch
 
24
from bzrlib.osutils import pathjoin
24
25
from bzrlib.tests.blackbox import ExternalBase
25
26
from bzrlib.uncommit import uncommit
 
27
from bzrlib.workingtree import WorkingTree
26
28
from bzrlib import urlutils
27
29
 
28
30
 
29
31
class TestPull(ExternalBase):
30
32
 
31
 
    def example_branch(test):
32
 
        test.run_bzr('init')
33
 
        file('hello', 'wt').write('foo')
34
 
        test.run_bzr('add hello')
35
 
        test.run_bzr('commit -m setup hello')
36
 
        file('goodbye', 'wt').write('baz')
37
 
        test.run_bzr('add goodbye')
38
 
        test.run_bzr('commit -m setup goodbye')
 
33
    def example_branch(self, path='.'):
 
34
        tree = self.make_branch_and_tree(path)
 
35
        self.build_tree_contents([
 
36
            (pathjoin(path, 'hello'),   'foo'),
 
37
            (pathjoin(path, 'goodbye'), 'baz')])
 
38
        tree.add('hello')
 
39
        tree.commit(message='setup')
 
40
        tree.add('goodbye')
 
41
        tree.commit(message='setup')
 
42
        return tree
39
43
 
40
44
    def test_pull(self):
41
45
        """Pull changes from one branch to another."""
42
 
        os.mkdir('a')
 
46
        a_tree = self.example_branch('a')
43
47
        os.chdir('a')
44
 
 
45
 
        self.example_branch()
46
48
        self.run_bzr('pull', retcode=3)
47
49
        self.run_bzr('missing', retcode=3)
48
50
        self.run_bzr('missing .')
55
57
            self.run_bzr('pull')
56
58
 
57
59
        os.chdir('..')
58
 
        self.run_bzr('branch a b')
 
60
        b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
59
61
        os.chdir('b')
60
62
        self.run_bzr('pull')
61
63
        os.mkdir('subdir')
62
 
        self.run_bzr('add subdir')
63
 
        self.run_bzr('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])
 
64
        b_tree.add('subdir')
 
65
        b_tree.commit(message='blah', allow_pointless=True)
 
66
 
 
67
        os.chdir('..')
 
68
        a = Branch.open('a')
 
69
        b = Branch.open('b')
 
70
        self.assertEqual(a.revision_history(), b.revision_history()[:-1])
 
71
 
 
72
        os.chdir('a')
68
73
        self.run_bzr('pull ../b')
69
 
        self.assertEquals(a.revision_history(), b.revision_history())
70
 
        self.run_bzr('commit -m blah2 --unchanged')
71
 
        os.chdir('../b')
72
 
        self.run_bzr('commit -m blah3 --unchanged')
 
74
        self.assertEqual(a.revision_history(), b.revision_history())
 
75
        a_tree.commit(message='blah2', allow_pointless=True)
 
76
        b_tree.commit(message='blah3', allow_pointless=True)
73
77
        # no overwrite
 
78
        os.chdir('../b')
74
79
        self.run_bzr('pull ../a', retcode=3)
75
80
        os.chdir('..')
76
 
        self.run_bzr('branch b overwriteme')
 
81
        b_tree.bzrdir.sprout('overwriteme')
77
82
        os.chdir('overwriteme')
78
83
        self.run_bzr('pull --overwrite ../a')
79
84
        overwritten = Branch.open('.')
80
85
        self.assertEqual(overwritten.revision_history(),
81
86
                         a.revision_history())
82
 
        os.chdir('../a')
83
 
        self.run_bzr('merge ../b')
84
 
        self.run_bzr('commit -m blah4 --unchanged')
 
87
        a_tree.merge_from_branch(b_tree.branch)
 
88
        a_tree.commit(message="blah4", allow_pointless=True)
85
89
        os.chdir('../b/subdir')
86
90
        self.run_bzr('pull ../../a')
87
 
        self.assertEquals(a.revision_history()[-1], b.revision_history()[-1])
88
 
        self.run_bzr('commit -m blah5 --unchanged')
89
 
        self.run_bzr('commit -m blah6 --unchanged')
 
91
        self.assertEqual(a.revision_history()[-1], b.revision_history()[-1])
 
92
        sub_tree = WorkingTree.open_containing('.')[0]
 
93
        sub_tree.commit(message="blah5", allow_pointless=True)
 
94
        sub_tree.commit(message="blah6", allow_pointless=True)
90
95
        os.chdir('..')
91
96
        self.run_bzr('pull ../a')
92
97
        os.chdir('../a')
93
 
        self.run_bzr('commit -m blah7 --unchanged')
94
 
        self.run_bzr('merge ../b')
95
 
        self.run_bzr('commit -m blah8 --unchanged')
 
98
        a_tree.commit(message="blah7", allow_pointless=True)
 
99
        a_tree.merge_from_branch(b_tree.branch)
 
100
        a_tree.commit(message="blah8", allow_pointless=True)
96
101
        self.run_bzr('pull ../b')
97
102
        self.run_bzr('pull ../b')
98
103
 
99
104
    def test_pull_dash_d(self):
100
 
        os.mkdir('a')
101
 
        os.chdir('a')
102
 
        self.example_branch()
103
 
        self.run_bzr('init ../b')
104
 
        self.run_bzr('init ../c')
 
105
        self.example_branch('a')
 
106
        self.make_branch_and_tree('b')
 
107
        self.make_branch_and_tree('c')
105
108
        # pull into that branch
106
 
        self.run_bzr('pull -d ../b .')
 
109
        self.run_bzr('pull -d b a')
107
110
        # pull into a branch specified by a url
108
 
        c_url = urlutils.local_path_to_url('../c')
 
111
        c_url = urlutils.local_path_to_url('c')
109
112
        self.assertStartsWith(c_url, 'file://')
110
 
        self.run_bzr('pull -d %s .' % c_url)
 
113
        self.run_bzr(['pull', '-d', c_url, 'a'])
111
114
 
112
115
    def test_pull_revision(self):
113
116
        """Pull some changes from one branch to another."""
114
 
        os.mkdir('a')
115
 
        os.chdir('a')
116
 
 
117
 
        self.example_branch()
118
 
        file('hello2', 'wt').write('foo')
119
 
        self.run_bzr('add hello2')
120
 
        self.run_bzr('commit -m setup hello2')
121
 
        file('goodbye2', 'wt').write('baz')
122
 
        self.run_bzr('add goodbye2')
123
 
        self.run_bzr('commit -m setup goodbye2')
124
 
 
125
 
        os.chdir('..')
126
 
        self.run_bzr('branch -r 1 a b')
 
117
        a_tree = self.example_branch('a')
 
118
        self.build_tree_contents([
 
119
            ('a/hello2',   'foo'),
 
120
            ('a/goodbye2', 'baz')])
 
121
        a_tree.add('hello2')
 
122
        a_tree.commit(message="setup")
 
123
        a_tree.add('goodbye2')
 
124
        a_tree.commit(message="setup")
 
125
 
 
126
        b_tree = a_tree.bzrdir.sprout('b',
 
127
                   revision_id=a_tree.branch.get_rev_id(1)).open_workingtree()
127
128
        os.chdir('b')
128
129
        self.run_bzr('pull -r 2')
129
130
        a = Branch.open('../a')
130
131
        b = Branch.open('.')
131
 
        self.assertEquals(a.revno(),4)
132
 
        self.assertEquals(b.revno(),2)
 
132
        self.assertEqual(a.revno(),4)
 
133
        self.assertEqual(b.revno(),2)
133
134
        self.run_bzr('pull -r 3')
134
 
        self.assertEquals(b.revno(),3)
 
135
        self.assertEqual(b.revno(),3)
135
136
        self.run_bzr('pull -r 4')
136
 
        self.assertEquals(a.revision_history(), b.revision_history())
 
137
        self.assertEqual(a.revision_history(), b.revision_history())
137
138
 
138
139
 
139
140
    def test_overwrite_uptodate(self):
140
141
        # Make sure pull --overwrite overwrites
141
142
        # even if the target branch has merged
142
143
        # everything already.
143
 
        bzr = self.run_bzr
144
 
 
145
 
        def get_rh(expected_len):
146
 
            rh = self.run_bzr('revision-history')[0]
147
 
            # Make sure we don't have trailing empty revisions
148
 
            rh = rh.strip().split('\n')
149
 
            self.assertEqual(len(rh), expected_len)
150
 
            return rh
151
 
 
152
 
        os.mkdir('a')
153
 
        os.chdir('a')
154
 
        bzr('init')
155
 
        open('foo', 'wb').write('original\n')
156
 
        bzr('add foo')
157
 
        bzr(['commit', '-m', 'initial commit'])
158
 
 
159
 
        os.chdir('..')
160
 
        bzr('branch a b')
161
 
 
162
 
        os.chdir('a')
163
 
        open('foo', 'wb').write('changed\n')
164
 
        bzr(['commit', '-m', 'later change'])
165
 
 
166
 
        open('foo', 'wb').write('another\n')
167
 
        bzr(['commit', '-m', 'a third change'])
168
 
 
169
 
        rev_history_a = get_rh(3)
170
 
 
171
 
        os.chdir('../b')
172
 
        bzr('merge ../a')
173
 
        bzr('commit -m merge')
174
 
 
175
 
        rev_history_b = get_rh(2)
176
 
 
177
 
        bzr('pull --overwrite ../a')
178
 
        rev_history_b = get_rh(3)
 
144
        a_tree = self.make_branch_and_tree('a')
 
145
        self.build_tree_contents([('a/foo', 'original\n')])
 
146
        a_tree.add('foo')
 
147
        a_tree.commit(message='initial commit')
 
148
 
 
149
        b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
 
150
 
 
151
        self.build_tree_contents([('a/foo', 'changed\n')])
 
152
        a_tree.commit(message='later change')
 
153
 
 
154
        self.build_tree_contents([('a/foo', 'a third change')])
 
155
        a_tree.commit(message='a third change')
 
156
 
 
157
        rev_history_a = a_tree.branch.revision_history()
 
158
        self.assertEqual(len(rev_history_a), 3)
 
159
 
 
160
        b_tree.merge_from_branch(a_tree.branch)
 
161
        b_tree.commit(message='merge')
 
162
 
 
163
        self.assertEqual(len(b_tree.branch.revision_history()), 2)
 
164
 
 
165
        os.chdir('b')
 
166
        self.run_bzr('pull --overwrite ../a')
 
167
        rev_history_b = b_tree.branch.revision_history()
 
168
        self.assertEqual(len(rev_history_b), 3)
179
169
 
180
170
        self.assertEqual(rev_history_b, rev_history_a)
181
171
 
182
172
    def test_overwrite_children(self):
183
173
        # Make sure pull --overwrite sets the revision-history
184
174
        # to be identical to the pull source, even if we have convergence
185
 
        bzr = self.run_bzr
186
 
 
187
 
        def get_rh(expected_len):
188
 
            rh = self.run_bzr('revision-history')[0]
189
 
            # Make sure we don't have trailing empty revisions
190
 
            rh = rh.strip().split('\n')
191
 
            self.assertEqual(len(rh), expected_len)
192
 
            return rh
193
 
 
194
 
        os.mkdir('a')
195
 
        os.chdir('a')
196
 
        bzr('init')
197
 
        open('foo', 'wb').write('original\n')
198
 
        bzr('add foo')
199
 
        bzr(['commit', '-m', 'initial commit'])
200
 
 
201
 
        os.chdir('..')
202
 
        bzr('branch a b')
203
 
 
204
 
        os.chdir('a')
205
 
        open('foo', 'wb').write('changed\n')
206
 
        bzr(['commit', '-m', 'later change'])
207
 
 
208
 
        open('foo', 'wb').write('another\n')
209
 
        bzr(['commit', '-m', 'a third change'])
210
 
 
211
 
        rev_history_a = get_rh(3)
212
 
 
213
 
        os.chdir('../b')
214
 
        bzr('merge ../a')
215
 
        bzr('commit -m merge')
216
 
 
217
 
        rev_history_b = get_rh(2)
218
 
 
219
 
        os.chdir('../a')
220
 
        open('foo', 'wb').write('a fourth change\n')
221
 
        bzr(['commit', '-m', 'a fourth change'])
222
 
 
223
 
        rev_history_a = get_rh(4)
 
175
        a_tree = self.make_branch_and_tree('a')
 
176
        self.build_tree_contents([('a/foo', 'original\n')])
 
177
        a_tree.add('foo')
 
178
        a_tree.commit(message='initial commit')
 
179
 
 
180
        b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
 
181
 
 
182
        self.build_tree_contents([('a/foo', 'changed\n')])
 
183
        a_tree.commit(message='later change')
 
184
 
 
185
        self.build_tree_contents([('a/foo', 'a third change')])
 
186
        a_tree.commit(message='a third change')
 
187
 
 
188
        self.assertEqual(len(a_tree.branch.revision_history()), 3)
 
189
 
 
190
        b_tree.merge_from_branch(a_tree.branch)
 
191
        b_tree.commit(message='merge')
 
192
 
 
193
        self.assertEqual(len(b_tree.branch.revision_history()), 2)
 
194
 
 
195
        self.build_tree_contents([('a/foo', 'a fourth change\n')])
 
196
        a_tree.commit(message='a fourth change')
 
197
 
 
198
        rev_history_a = a_tree.branch.revision_history()
 
199
        self.assertEqual(len(rev_history_a), 4)
224
200
 
225
201
        # With convergence, we could just pull over the
226
202
        # new change, but with --overwrite, we want to switch our history
227
 
        os.chdir('../b')
228
 
        bzr('pull --overwrite ../a')
229
 
        rev_history_b = get_rh(4)
 
203
        os.chdir('b')
 
204
        self.run_bzr('pull --overwrite ../a')
 
205
        rev_history_b = b_tree.branch.revision_history()
 
206
        self.assertEqual(len(rev_history_b), 4)
230
207
 
231
208
        self.assertEqual(rev_history_b, rev_history_a)
232
209
 
252
229
        # test pull for failure without parent set
253
230
        os.chdir('branch_b')
254
231
        out = self.run_bzr('pull', retcode=3)
255
 
        self.assertEquals(out,
 
232
        self.assertEqual(out,
256
233
                ('','bzr: ERROR: No pull location known or specified.\n'))
257
234
        # test implicit --remember when no parent set, this pull conflicts
258
235
        self.build_tree(['d'])
259
236
        tree_b.add('d')
260
237
        tree_b.commit('commit d')
261
238
        out = self.run_bzr('pull ../branch_a', retcode=3)
262
 
        self.assertEquals(out,
 
239
        self.assertEqual(out,
263
240
                ('','bzr: ERROR: These branches have diverged.'
264
241
                    ' Use the merge command to reconcile them.\n'))
265
 
        self.assertEquals(branch_b.get_parent(), parent)
 
242
        self.assertEqual(branch_b.get_parent(), parent)
266
243
        # test implicit --remember after resolving previous failure
267
244
        uncommit(branch=branch_b, tree=tree_b)
268
245
        transport.delete('branch_b/d')
269
246
        self.run_bzr('pull')
270
 
        self.assertEquals(branch_b.get_parent(), parent)
 
247
        self.assertEqual(branch_b.get_parent(), parent)
271
248
        # test explicit --remember
272
249
        self.run_bzr('pull ../branch_c --remember')
273
 
        self.assertEquals(branch_b.get_parent(),
 
250
        self.assertEqual(branch_b.get_parent(),
274
251
                          branch_c.bzrdir.root_transport.base)
275
252
 
276
253
    def test_pull_bundle(self):
293
270
 
294
271
        # Create the bundle for 'b' to pull
295
272
        os.chdir('branch_a')
296
 
        bundle_file = open('../bundle', 'wb')
297
 
        bundle_file.write(self.run_bzr('bundle ../branch_b')[0])
298
 
        bundle_file.close()
 
273
        self.run_bzr('bundle ../branch_b -o ../bundle')
299
274
 
300
275
        os.chdir('../branch_b')
301
276
        out, err = self.run_bzr('pull ../bundle')
318
293
        out, err = self.run_bzr('pull ../bundle')
319
294
        self.assertEqual(err, '')
320
295
        self.assertEqual(out, 'No revisions to pull.\n')
 
296
 
 
297
    def test_pull_verbose_no_files(self):
 
298
        """Pull --verbose should not list modified files"""
 
299
        tree_a = self.make_branch_and_tree('tree_a')
 
300
        self.build_tree(['tree_a/foo'])
 
301
        tree_a.add('foo')
 
302
        tree_a.commit('bar')
 
303
        tree_b = self.make_branch_and_tree('tree_b')
 
304
        out = self.run_bzr('pull --verbose -d tree_b tree_a')[0]
 
305
        self.assertContainsRe(out, 'bar')
 
306
        self.assertNotContainsRe(out, 'added:')
 
307
        self.assertNotContainsRe(out, 'foo')