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_overwrite_uptodate(self):
105
# Make sure pull --overwrite overwrites
106
# even if the target branch has merged
107
# everything already.
110
def get_rh(expected_len):
111
rh = self.capture('revision-history')
112
# Make sure we don't have trailing empty revisions
113
rh = rh.strip().split('\n')
114
self.assertEqual(len(rh), expected_len)
120
open('foo', 'wb').write('original\n')
122
bzr('commit', '-m', 'initial commit')
125
bzr('branch', 'a', 'b')
128
open('foo', 'wb').write('changed\n')
129
bzr('commit', '-m', 'later change')
131
open('foo', 'wb').write('another\n')
132
bzr('commit', '-m', 'a third change')
134
rev_history_a = get_rh(3)
138
bzr('commit', '-m', 'merge')
140
rev_history_b = get_rh(2)
142
bzr('pull', '--overwrite', '../a')
143
rev_history_b = get_rh(3)
145
self.assertEqual(rev_history_b, rev_history_a)
147
def test_overwrite_children(self):
148
# Make sure pull --overwrite sets the revision-history
149
# to be identical to the pull source, even if we have convergence
152
def get_rh(expected_len):
153
rh = self.capture('revision-history')
154
# Make sure we don't have trailing empty revisions
155
rh = rh.strip().split('\n')
156
self.assertEqual(len(rh), expected_len)
162
open('foo', 'wb').write('original\n')
164
bzr('commit', '-m', 'initial commit')
167
bzr('branch', 'a', 'b')
170
open('foo', 'wb').write('changed\n')
171
bzr('commit', '-m', 'later change')
173
open('foo', 'wb').write('another\n')
174
bzr('commit', '-m', 'a third change')
176
rev_history_a = get_rh(3)
180
bzr('commit', '-m', 'merge')
182
rev_history_b = get_rh(2)
185
open('foo', 'wb').write('a fourth change\n')
186
bzr('commit', '-m', 'a fourth change')
188
rev_history_a = get_rh(4)
190
# With convergence, we could just pull over the
191
# new change, but with --overwrite, we want to switch our history
193
bzr('pull', '--overwrite', '../a')
194
rev_history_b = get_rh(4)
196
self.assertEqual(rev_history_b, rev_history_a)