~bzr-pqm/bzr/bzr.dev

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.50.7 by John Arbash Meinel
Fix broken test from refactoring blackbox/test_pull
104
    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)
105
        # Make sure pull --overwrite overwrites
106
        # even if the target branch has merged
107
        # everything already.
108
        bzr = self.run_bzr
109
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)
115
            return rh
116
117
        os.mkdir('a')
118
        os.chdir('a')
119
        bzr('init')
120
        open('foo', 'wb').write('original\n')
121
        bzr('add', 'foo')
122
        bzr('commit', '-m', 'initial commit')
123
124
        os.chdir('..')
125
        bzr('branch', 'a', 'b')
126
127
        os.chdir('a')
128
        open('foo', 'wb').write('changed\n')
129
        bzr('commit', '-m', 'later change')
130
131
        open('foo', 'wb').write('another\n')
132
        bzr('commit', '-m', 'a third change')
133
134
        rev_history_a = get_rh(3)
135
136
        os.chdir('../b')
137
        bzr('merge', '../a')
138
        bzr('commit', '-m', 'merge')
139
140
        rev_history_b = get_rh(2)
141
142
        bzr('pull', '--overwrite', '../a')
143
        rev_history_b = get_rh(3)
144
145
        self.assertEqual(rev_history_b, rev_history_a)
146
1185.50.7 by John Arbash Meinel
Fix broken test from refactoring blackbox/test_pull
147
    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)
148
        # Make sure pull --overwrite sets the revision-history
149
        # to be identical to the pull source, even if we have convergence
150
        bzr = self.run_bzr
151
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)
157
            return rh
158
159
        os.mkdir('a')
160
        os.chdir('a')
161
        bzr('init')
162
        open('foo', 'wb').write('original\n')
163
        bzr('add', 'foo')
164
        bzr('commit', '-m', 'initial commit')
165
166
        os.chdir('..')
167
        bzr('branch', 'a', 'b')
168
169
        os.chdir('a')
170
        open('foo', 'wb').write('changed\n')
171
        bzr('commit', '-m', 'later change')
172
173
        open('foo', 'wb').write('another\n')
174
        bzr('commit', '-m', 'a third change')
175
176
        rev_history_a = get_rh(3)
177
178
        os.chdir('../b')
179
        bzr('merge', '../a')
180
        bzr('commit', '-m', 'merge')
181
182
        rev_history_b = get_rh(2)
183
184
        os.chdir('../a')
185
        open('foo', 'wb').write('a fourth change\n')
186
        bzr('commit', '-m', 'a fourth change')
187
188
        rev_history_a = get_rh(4)
189
190
        # With convergence, we could just pull over the
191
        # new change, but with --overwrite, we want to switch our history
192
        os.chdir('../b')
193
        bzr('pull', '--overwrite', '../a')
194
        rev_history_b = get_rh(4)
195
196
        self.assertEqual(rev_history_b, rev_history_a)
197
198