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 TestCommands(ExternalBase):
49
"""Pull changes from one branch to another."""
54
self.runbzr('pull', retcode=3)
55
self.runbzr('missing', retcode=3)
56
self.runbzr('missing .')
57
self.runbzr('missing')
59
self.runbzr('pull /', retcode=3)
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_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_pull_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)