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.
24
from bzrlib.branch import Branch
25
from bzrlib.tests.blackbox import ExternalBase
27
class TestPull(ExternalBase):
29
def example_branch(test):
31
file('hello', 'wt').write('foo')
32
test.runbzr('add hello')
33
test.runbzr('commit -m setup hello')
34
file('goodbye', 'wt').write('baz')
35
test.runbzr('add goodbye')
36
test.runbzr('commit -m setup goodbye')
39
"""Pull changes from one branch to another."""
44
self.runbzr('pull', retcode=3)
45
self.runbzr('missing', retcode=3)
46
self.runbzr('missing .')
47
self.runbzr('missing')
49
self.runbzr('pull /', retcode=3)
53
self.runbzr('branch a b')
57
self.runbzr('add subdir')
58
self.runbzr('commit -m blah --unchanged')
61
b = Branch.open('../b')
62
self.assertEquals(a.revision_history(), b.revision_history()[:-1])
63
self.runbzr('pull ../b')
64
self.assertEquals(a.revision_history(), b.revision_history())
65
self.runbzr('commit -m blah2 --unchanged')
67
self.runbzr('commit -m blah3 --unchanged')
69
self.runbzr('pull ../a', retcode=3)
71
self.runbzr('branch b overwriteme')
72
os.chdir('overwriteme')
73
self.runbzr('pull --overwrite ../a')
74
overwritten = Branch.open('.')
75
self.assertEqual(overwritten.revision_history(),
78
self.runbzr('merge ../b')
79
self.runbzr('commit -m blah4 --unchanged')
80
os.chdir('../b/subdir')
81
self.runbzr('pull ../../a')
82
self.assertEquals(a.revision_history()[-1], b.revision_history()[-1])
83
self.runbzr('commit -m blah5 --unchanged')
84
self.runbzr('commit -m blah6 --unchanged')
86
self.runbzr('pull ../a')
88
self.runbzr('commit -m blah7 --unchanged')
89
self.runbzr('merge ../b')
90
self.runbzr('commit -m blah8 --unchanged')
91
self.runbzr('pull ../b')
92
self.runbzr('pull ../b')
94
def test_overwrite_uptodate(self):
95
# Make sure pull --overwrite overwrites
96
# even if the target branch has merged
100
def get_rh(expected_len):
101
rh = self.capture('revision-history')
102
# Make sure we don't have trailing empty revisions
103
rh = rh.strip().split('\n')
104
self.assertEqual(len(rh), expected_len)
110
open('foo', 'wb').write('original\n')
112
bzr('commit', '-m', 'initial commit')
115
bzr('branch', 'a', 'b')
118
open('foo', 'wb').write('changed\n')
119
bzr('commit', '-m', 'later change')
121
open('foo', 'wb').write('another\n')
122
bzr('commit', '-m', 'a third change')
124
rev_history_a = get_rh(3)
128
bzr('commit', '-m', 'merge')
130
rev_history_b = get_rh(2)
132
bzr('pull', '--overwrite', '../a')
133
rev_history_b = get_rh(3)
135
self.assertEqual(rev_history_b, rev_history_a)
137
def test_overwrite_children(self):
138
# Make sure pull --overwrite sets the revision-history
139
# to be identical to the pull source, even if we have convergence
142
def get_rh(expected_len):
143
rh = self.capture('revision-history')
144
# Make sure we don't have trailing empty revisions
145
rh = rh.strip().split('\n')
146
self.assertEqual(len(rh), expected_len)
152
open('foo', 'wb').write('original\n')
154
bzr('commit', '-m', 'initial commit')
157
bzr('branch', 'a', 'b')
160
open('foo', 'wb').write('changed\n')
161
bzr('commit', '-m', 'later change')
163
open('foo', 'wb').write('another\n')
164
bzr('commit', '-m', 'a third change')
166
rev_history_a = get_rh(3)
170
bzr('commit', '-m', 'merge')
172
rev_history_b = get_rh(2)
175
open('foo', 'wb').write('a fourth change\n')
176
bzr('commit', '-m', 'a fourth change')
178
rev_history_a = get_rh(4)
180
# With convergence, we could just pull over the
181
# new change, but with --overwrite, we want to switch our history
183
bzr('pull', '--overwrite', '../a')
184
rev_history_b = get_rh(4)
186
self.assertEqual(rev_history_b, rev_history_a)