/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
1185.50.5 by John Arbash Meinel
pull --overwrite should always overwrite, not just if diverged. (Test case from Robey Pointer)
1
# Copyright (C) 2005 by Canonical Ltd
2
# -*- coding: utf-8 -*-
3
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.
8
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.
13
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
17
18
1185.50.8 by John Arbash Meinel
Cleanup of test_pull.py headers
19
"""Black-box tests for bzr pull.
1185.50.5 by John Arbash Meinel
pull --overwrite should always overwrite, not just if diverged. (Test case from Robey Pointer)
20
"""
21
22
import os
23
import sys
24
25
from bzrlib.branch import Branch
26
from bzrlib.tests.blackbox import ExternalBase
27
1185.50.7 by John Arbash Meinel
Fix broken test from refactoring blackbox/test_pull
28
class TestPull(ExternalBase):
29
30
    def example_branch(test):
31
        test.runbzr('init')
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')
1185.50.5 by John Arbash Meinel
pull --overwrite should always overwrite, not just if diverged. (Test case from Robey Pointer)
38
39
    def test_pull(self):
40
        """Pull changes from one branch to another."""
41
        os.mkdir('a')
42
        os.chdir('a')
43
44
        self.example_branch()
45
        self.runbzr('pull', retcode=3)
46
        self.runbzr('missing', retcode=3)
47
        self.runbzr('missing .')
48
        self.runbzr('missing')
1185.31.31 by John Arbash Meinel
avoiding 'bzr pull .' means all tests pass under cygwin
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)
57
            self.runbzr('pull')
1185.50.5 by John Arbash Meinel
pull --overwrite should always overwrite, not just if diverged. (Test case from Robey Pointer)
58
        self.runbzr('pull /', retcode=3)
1185.31.31 by John Arbash Meinel
avoiding 'bzr pull .' means all tests pass under cygwin
59
        if sys.platform not in ('win32', 'cygwin'):
60
            self.runbzr('pull')
1185.50.5 by John Arbash Meinel
pull --overwrite should always overwrite, not just if diverged. (Test case from Robey Pointer)
61
62
        os.chdir('..')
63
        self.runbzr('branch a b')
64
        os.chdir('b')
65
        self.runbzr('pull')
66
        os.mkdir('subdir')
67
        self.runbzr('add subdir')
68
        self.runbzr('commit -m blah --unchanged')
69
        os.chdir('../a')
70
        a = Branch.open('.')
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')
76
        os.chdir('../b')
77
        self.runbzr('commit -m blah3 --unchanged')
78
        # no overwrite
79
        self.runbzr('pull ../a', retcode=3)
80
        os.chdir('..')
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(),
86
                         a.revision_history())
87
        os.chdir('../a')
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')
95
        os.chdir('..')
96
        self.runbzr('pull ../a')
97
        os.chdir('../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')
103
1185.76.2 by Erik Bågfors
test for pull --revision
104
    def test_pull_revision(self):
105
        """Pull some changes from one branch to another."""
106
        os.mkdir('a')
107
        os.chdir('a')
108
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')
116
117
        os.chdir('..')
118
        self.runbzr('branch -r 1 a b')
119
        os.chdir('b')
120
        self.runbzr('pull -r 2')
121
        a = Branch.open('../a')
122
        b = Branch.open('.')
1185.76.4 by Erik Bågfors
expanded tabs
123
        self.assertEquals(a.revno(),4)
124
        self.assertEquals(b.revno(),2)
1185.76.2 by Erik Bågfors
test for pull --revision
125
        self.runbzr('pull -r 3')
1185.76.4 by Erik Bågfors
expanded tabs
126
        self.assertEquals(b.revno(),3)
1185.76.2 by Erik Bågfors
test for pull --revision
127
        self.runbzr('pull -r 4')
128
        self.assertEquals(a.revision_history(), b.revision_history())
129
130
1185.50.7 by John Arbash Meinel
Fix broken test from refactoring blackbox/test_pull
131
    def test_overwrite_uptodate(self):
1185.50.5 by John Arbash Meinel
pull --overwrite should always overwrite, not just if diverged. (Test case from Robey Pointer)
132
        # Make sure pull --overwrite overwrites
133
        # even if the target branch has merged
134
        # everything already.
135
        bzr = self.run_bzr
136
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)
142
            return rh
143
144
        os.mkdir('a')
145
        os.chdir('a')
146
        bzr('init')
147
        open('foo', 'wb').write('original\n')
148
        bzr('add', 'foo')
149
        bzr('commit', '-m', 'initial commit')
150
151
        os.chdir('..')
152
        bzr('branch', 'a', 'b')
153
154
        os.chdir('a')
155
        open('foo', 'wb').write('changed\n')
156
        bzr('commit', '-m', 'later change')
157
158
        open('foo', 'wb').write('another\n')
159
        bzr('commit', '-m', 'a third change')
160
161
        rev_history_a = get_rh(3)
162
163
        os.chdir('../b')
164
        bzr('merge', '../a')
165
        bzr('commit', '-m', 'merge')
166
167
        rev_history_b = get_rh(2)
168
169
        bzr('pull', '--overwrite', '../a')
170
        rev_history_b = get_rh(3)
171
172
        self.assertEqual(rev_history_b, rev_history_a)
173
1185.50.7 by John Arbash Meinel
Fix broken test from refactoring blackbox/test_pull
174
    def test_overwrite_children(self):
1185.50.5 by John Arbash Meinel
pull --overwrite should always overwrite, not just if diverged. (Test case from Robey Pointer)
175
        # Make sure pull --overwrite sets the revision-history
176
        # to be identical to the pull source, even if we have convergence
177
        bzr = self.run_bzr
178
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)
184
            return rh
185
186
        os.mkdir('a')
187
        os.chdir('a')
188
        bzr('init')
189
        open('foo', 'wb').write('original\n')
190
        bzr('add', 'foo')
191
        bzr('commit', '-m', 'initial commit')
192
193
        os.chdir('..')
194
        bzr('branch', 'a', 'b')
195
196
        os.chdir('a')
197
        open('foo', 'wb').write('changed\n')
198
        bzr('commit', '-m', 'later change')
199
200
        open('foo', 'wb').write('another\n')
201
        bzr('commit', '-m', 'a third change')
202
203
        rev_history_a = get_rh(3)
204
205
        os.chdir('../b')
206
        bzr('merge', '../a')
207
        bzr('commit', '-m', 'merge')
208
209
        rev_history_b = get_rh(2)
210
211
        os.chdir('../a')
212
        open('foo', 'wb').write('a fourth change\n')
213
        bzr('commit', '-m', 'a fourth change')
214
215
        rev_history_a = get_rh(4)
216
217
        # With convergence, we could just pull over the
218
        # new change, but with --overwrite, we want to switch our history
219
        os.chdir('../b')
220
        bzr('pull', '--overwrite', '../a')
221
        rev_history_b = get_rh(4)
222
223
        self.assertEqual(rev_history_b, rev_history_a)
224
225