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.
21
These check that it behaves properly when it's invoked through the regular
22
command-line interface. This doesn't actually run a new interpreter but
23
rather starts again from the run_bzr function.
27
# XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
28
# Note: Please don't add new tests here, it's too big and bulky. Instead add
29
# them into small suites in bzrlib.tests.blackbox.test_FOO for the particular
30
# UI command/aspect that is being tested.
33
from cStringIO import StringIO
39
from bzrlib.branch import Branch
40
from bzrlib.clone import copy_branch
41
from bzrlib.errors import BzrCommandError
42
from bzrlib.osutils import has_symlinks
43
from bzrlib.tests.HTTPTestUtil import TestCaseWithWebserver
44
from bzrlib.tests.blackbox import ExternalBase
46
class TestPull(ExternalBase):
48
def example_branch(test):
50
file('hello', 'wt').write('foo')
51
test.runbzr('add hello')
52
test.runbzr('commit -m setup hello')
53
file('goodbye', 'wt').write('baz')
54
test.runbzr('add goodbye')
55
test.runbzr('commit -m setup goodbye')
58
"""Pull changes from one branch to another."""
63
self.runbzr('pull', retcode=3)
64
self.runbzr('missing', retcode=3)
65
self.runbzr('missing .')
66
self.runbzr('missing')
67
if sys.platform not in ('win32', 'cygwin'):
68
# This is equivalent to doing "bzr pull ."
69
# Which means that bzr creates 2 branches grabbing
70
# the same location, and tries to pull.
71
# However, 2 branches mean 2 locks on the same file
72
# which ultimately implies a deadlock.
73
# (non windows platforms allow multiple locks on the
74
# same file by the same calling process)
76
self.runbzr('pull /', retcode=3)
77
if sys.platform not in ('win32', 'cygwin'):
81
self.runbzr('branch a b')
85
self.runbzr('add subdir')
86
self.runbzr('commit -m blah --unchanged')
89
b = Branch.open('../b')
90
self.assertEquals(a.revision_history(), b.revision_history()[:-1])
91
self.runbzr('pull ../b')
92
self.assertEquals(a.revision_history(), b.revision_history())
93
self.runbzr('commit -m blah2 --unchanged')
95
self.runbzr('commit -m blah3 --unchanged')
97
self.runbzr('pull ../a', retcode=3)
99
self.runbzr('branch b overwriteme')
100
os.chdir('overwriteme')
101
self.runbzr('pull --overwrite ../a')
102
overwritten = Branch.open('.')
103
self.assertEqual(overwritten.revision_history(),
104
a.revision_history())
106
self.runbzr('merge ../b')
107
self.runbzr('commit -m blah4 --unchanged')
108
os.chdir('../b/subdir')
109
self.runbzr('pull ../../a')
110
self.assertEquals(a.revision_history()[-1], b.revision_history()[-1])
111
self.runbzr('commit -m blah5 --unchanged')
112
self.runbzr('commit -m blah6 --unchanged')
114
self.runbzr('pull ../a')
116
self.runbzr('commit -m blah7 --unchanged')
117
self.runbzr('merge ../b')
118
self.runbzr('commit -m blah8 --unchanged')
119
self.runbzr('pull ../b')
120
self.runbzr('pull ../b')
122
def test_overwrite_uptodate(self):
123
# Make sure pull --overwrite overwrites
124
# even if the target branch has merged
125
# everything already.
128
def get_rh(expected_len):
129
rh = self.capture('revision-history')
130
# Make sure we don't have trailing empty revisions
131
rh = rh.strip().split('\n')
132
self.assertEqual(len(rh), expected_len)
138
open('foo', 'wb').write('original\n')
140
bzr('commit', '-m', 'initial commit')
143
bzr('branch', 'a', 'b')
146
open('foo', 'wb').write('changed\n')
147
bzr('commit', '-m', 'later change')
149
open('foo', 'wb').write('another\n')
150
bzr('commit', '-m', 'a third change')
152
rev_history_a = get_rh(3)
156
bzr('commit', '-m', 'merge')
158
rev_history_b = get_rh(2)
160
bzr('pull', '--overwrite', '../a')
161
rev_history_b = get_rh(3)
163
self.assertEqual(rev_history_b, rev_history_a)
165
def test_overwrite_children(self):
166
# Make sure pull --overwrite sets the revision-history
167
# to be identical to the pull source, even if we have convergence
170
def get_rh(expected_len):
171
rh = self.capture('revision-history')
172
# Make sure we don't have trailing empty revisions
173
rh = rh.strip().split('\n')
174
self.assertEqual(len(rh), expected_len)
180
open('foo', 'wb').write('original\n')
182
bzr('commit', '-m', 'initial commit')
185
bzr('branch', 'a', 'b')
188
open('foo', 'wb').write('changed\n')
189
bzr('commit', '-m', 'later change')
191
open('foo', 'wb').write('another\n')
192
bzr('commit', '-m', 'a third change')
194
rev_history_a = get_rh(3)
198
bzr('commit', '-m', 'merge')
200
rev_history_b = get_rh(2)
203
open('foo', 'wb').write('a fourth change\n')
204
bzr('commit', '-m', 'a fourth change')
206
rev_history_a = get_rh(4)
208
# With convergence, we could just pull over the
209
# new change, but with --overwrite, we want to switch our history
211
bzr('pull', '--overwrite', '../a')
212
rev_history_b = get_rh(4)
214
self.assertEqual(rev_history_b, rev_history_a)