1
# Copyright (C) 2005 by Canonical Ltd
2
# -*- coding: utf-8 -*-
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.
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.
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
19
"""Black-box tests for bzr pull.
25
from bzrlib.branch import Branch
26
from bzrlib.tests.blackbox import ExternalBase
28
class TestPull(ExternalBase):
30
def example_branch(test):
32
file('hello', 'wt').write('foo')
33
test.runbzr('add hello')
34
test.runbzr('commit -m setup hello')
35
file('goodbye', 'wt').write('baz')
36
test.runbzr('add goodbye')
37
test.runbzr('commit -m setup goodbye')
40
"""Pull changes from one branch to another."""
45
self.runbzr('pull', retcode=3)
46
self.runbzr('missing', retcode=3)
47
self.runbzr('missing .')
48
self.runbzr('missing')
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)
58
self.runbzr('pull /', retcode=3)
59
if sys.platform not in ('win32', 'cygwin'):
63
self.runbzr('branch a b')
67
self.runbzr('add subdir')
68
self.runbzr('commit -m blah --unchanged')
71
b = Branch.open('../b')
72
self.assertEquals(a.revision_history(), b.revision_history()[:-1])
73
self.runbzr('pull ../b')
74
self.assertEquals(a.revision_history(), b.revision_history())
75
self.runbzr('commit -m blah2 --unchanged')
77
self.runbzr('commit -m blah3 --unchanged')
79
self.runbzr('pull ../a', retcode=3)
81
self.runbzr('branch b overwriteme')
82
os.chdir('overwriteme')
83
self.runbzr('pull --overwrite ../a')
84
overwritten = Branch.open('.')
85
self.assertEqual(overwritten.revision_history(),
88
self.runbzr('merge ../b')
89
self.runbzr('commit -m blah4 --unchanged')
90
os.chdir('../b/subdir')
91
self.runbzr('pull ../../a')
92
self.assertEquals(a.revision_history()[-1], b.revision_history()[-1])
93
self.runbzr('commit -m blah5 --unchanged')
94
self.runbzr('commit -m blah6 --unchanged')
96
self.runbzr('pull ../a')
98
self.runbzr('commit -m blah7 --unchanged')
99
self.runbzr('merge ../b')
100
self.runbzr('commit -m blah8 --unchanged')
101
self.runbzr('pull ../b')
102
self.runbzr('pull ../b')
104
def test_pull_revision(self):
105
"""Pull some changes from one branch to another."""
109
self.example_branch()
110
file('hello2', 'wt').write('foo')
111
self.runbzr('add hello2')
112
self.runbzr('commit -m setup hello2')
113
file('goodbye2', 'wt').write('baz')
114
self.runbzr('add goodbye2')
115
self.runbzr('commit -m setup goodbye2')
118
self.runbzr('branch -r 1 a b')
120
self.runbzr('pull -r 2')
121
a = Branch.open('../a')
123
self.assertEquals(a.revno(),4)
124
self.assertEquals(b.revno(),2)
125
self.runbzr('pull -r 3')
126
self.assertEquals(b.revno(),3)
127
self.runbzr('pull -r 4')
128
self.assertEquals(a.revision_history(), b.revision_history())
131
def test_overwrite_uptodate(self):
132
# Make sure pull --overwrite overwrites
133
# even if the target branch has merged
134
# everything already.
137
def get_rh(expected_len):
138
rh = self.capture('revision-history')
139
# Make sure we don't have trailing empty revisions
140
rh = rh.strip().split('\n')
141
self.assertEqual(len(rh), expected_len)
147
open('foo', 'wb').write('original\n')
149
bzr('commit', '-m', 'initial commit')
152
bzr('branch', 'a', 'b')
155
open('foo', 'wb').write('changed\n')
156
bzr('commit', '-m', 'later change')
158
open('foo', 'wb').write('another\n')
159
bzr('commit', '-m', 'a third change')
161
rev_history_a = get_rh(3)
165
bzr('commit', '-m', 'merge')
167
rev_history_b = get_rh(2)
169
bzr('pull', '--overwrite', '../a')
170
rev_history_b = get_rh(3)
172
self.assertEqual(rev_history_b, rev_history_a)
174
def test_overwrite_children(self):
175
# Make sure pull --overwrite sets the revision-history
176
# to be identical to the pull source, even if we have convergence
179
def get_rh(expected_len):
180
rh = self.capture('revision-history')
181
# Make sure we don't have trailing empty revisions
182
rh = rh.strip().split('\n')
183
self.assertEqual(len(rh), expected_len)
189
open('foo', 'wb').write('original\n')
191
bzr('commit', '-m', 'initial commit')
194
bzr('branch', 'a', 'b')
197
open('foo', 'wb').write('changed\n')
198
bzr('commit', '-m', 'later change')
200
open('foo', 'wb').write('another\n')
201
bzr('commit', '-m', 'a third change')
203
rev_history_a = get_rh(3)
207
bzr('commit', '-m', 'merge')
209
rev_history_b = get_rh(2)
212
open('foo', 'wb').write('a fourth change\n')
213
bzr('commit', '-m', 'a fourth change')
215
rev_history_a = get_rh(4)
217
# With convergence, we could just pull over the
218
# new change, but with --overwrite, we want to switch our history
220
bzr('pull', '--overwrite', '../a')
221
rev_history_b = get_rh(4)
223
self.assertEqual(rev_history_b, rev_history_a)