/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
2052.3.2 by John Arbash Meinel
Change Copyright .. by Canonical to Copyright ... Canonical
1
# Copyright (C) 2006 Canonical Ltd
1508.1.24 by Robert Collins
Add update command for use with checkouts.
2
# -*- coding: utf-8 -*-
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
3
#
1508.1.24 by Robert Collins
Add update command for use with checkouts.
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.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
8
#
1508.1.24 by Robert Collins
Add update command for use with checkouts.
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.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
13
#
1508.1.24 by Robert Collins
Add update command for use with checkouts.
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
19
"""Tests for the update command of bzr."""
20
1711.2.109 by John Arbash Meinel
Add a test for handling a pending merge plus an update.
21
import os
1508.1.24 by Robert Collins
Add update command for use with checkouts.
22
1711.2.109 by John Arbash Meinel
Add a test for handling a pending merge plus an update.
23
from bzrlib import branch, bzrdir
1508.1.24 by Robert Collins
Add update command for use with checkouts.
24
from bzrlib.tests import TestSkipped
25
from bzrlib.tests.blackbox import ExternalBase
1587.1.11 by Robert Collins
Local commits appear to be working properly.
26
from bzrlib.workingtree import WorkingTree
1508.1.24 by Robert Collins
Add update command for use with checkouts.
27
28
29
class TestUpdate(ExternalBase):
30
31
    def test_update_standalone_trivial(self):
2664.7.2 by Daniel Watkins
tests.blackbox.test_update now uses internals where appropriate.
32
        self.make_branch_and_tree('.')
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
33
        out, err = self.run_bzr('update')
1830.1.1 by John Arbash Meinel
Print up to date even if bound, also always print out current revno.
34
        self.assertEqual('Tree is up to date at revision 0.\n', err)
1508.1.24 by Robert Collins
Add update command for use with checkouts.
35
        self.assertEqual('', out)
36
1815.3.4 by Stefan (metze) Metzmacher
add simple test for 'bzr up'
37
    def test_update_standalone_trivial_with_alias_up(self):
2664.7.2 by Daniel Watkins
tests.blackbox.test_update now uses internals where appropriate.
38
        self.make_branch_and_tree('.')
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
39
        out, err = self.run_bzr('up')
1815.3.4 by Stefan (metze) Metzmacher
add simple test for 'bzr up'
40
        self.assertEqual('Tree is up to date at revision 0.\n', err)
41
        self.assertEqual('', out)
42
1587.1.14 by Robert Collins
Make bound branch creation happen via 'checkout'
43
    def test_update_up_to_date_light_checkout(self):
1508.1.24 by Robert Collins
Add update command for use with checkouts.
44
        self.make_branch_and_tree('branch')
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
45
        self.run_bzr('checkout --lightweight branch checkout')
46
        out, err = self.run_bzr('update checkout')
1830.1.1 by John Arbash Meinel
Print up to date even if bound, also always print out current revno.
47
        self.assertEqual('Tree is up to date at revision 0.\n', err)
48
        self.assertEqual('', out)
49
50
    def test_update_up_to_date_checkout(self):
51
        self.make_branch_and_tree('branch')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
52
        self.run_bzr('checkout branch checkout')
53
        out, err = self.run_bzr('update checkout')
1830.1.1 by John Arbash Meinel
Print up to date even if bound, also always print out current revno.
54
        self.assertEqual('Tree is up to date at revision 0.\n', err)
1508.1.24 by Robert Collins
Add update command for use with checkouts.
55
        self.assertEqual('', out)
56
57
    def test_update_out_of_date_standalone_tree(self):
58
        # FIXME the default format has to change for this to pass
59
        # because it currently uses the branch last-revision marker.
60
        self.make_branch_and_tree('branch')
61
        # make a checkout
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
62
        self.run_bzr('checkout --lightweight branch checkout')
1508.1.24 by Robert Collins
Add update command for use with checkouts.
63
        self.build_tree(['checkout/file'])
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
64
        self.run_bzr('add checkout/file')
65
        self.run_bzr('commit -m add-file checkout')
1508.1.24 by Robert Collins
Add update command for use with checkouts.
66
        # now branch should be out of date
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
67
        out,err = self.run_bzr('update branch')
1711.2.107 by John Arbash Meinel
re-enable a skipped update test, and clean it up
68
        self.assertEqual('', out)
2504.2.3 by Daniel Watkins
Further modified existing tests to cover the new output.
69
        self.assertContainsRe(err, '\+N  file')
2504.2.2 by Daniel Watkins
Modified existing tests to reflect changes to output.
70
        self.assertEndsWith(err, 'All changes applied successfully.\n'
71
                         'Updated to revision 1.\n')
1508.1.24 by Robert Collins
Add update command for use with checkouts.
72
        self.failUnlessExists('branch/file')
73
1587.1.14 by Robert Collins
Make bound branch creation happen via 'checkout'
74
    def test_update_out_of_date_light_checkout(self):
1508.1.24 by Robert Collins
Add update command for use with checkouts.
75
        self.make_branch_and_tree('branch')
76
        # make two checkouts
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
77
        self.run_bzr('checkout --lightweight branch checkout')
78
        self.run_bzr('checkout --lightweight branch checkout2')
1508.1.24 by Robert Collins
Add update command for use with checkouts.
79
        self.build_tree(['checkout/file'])
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
80
        self.run_bzr('add checkout/file')
81
        self.run_bzr('commit -m add-file checkout')
1508.1.24 by Robert Collins
Add update command for use with checkouts.
82
        # now checkout2 should be out of date
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
83
        out,err = self.run_bzr('update checkout2')
2504.2.3 by Daniel Watkins
Further modified existing tests to cover the new output.
84
        self.assertContainsRe(err, '\+N  file')
2504.2.2 by Daniel Watkins
Modified existing tests to reflect changes to output.
85
        self.assertEndsWith(err, 'All changes applied successfully.\n'
86
                         'Updated to revision 1.\n')
1508.1.24 by Robert Collins
Add update command for use with checkouts.
87
        self.assertEqual('', out)
88
89
    def test_update_conflicts_returns_2(self):
90
        self.make_branch_and_tree('branch')
91
        # make two checkouts
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
92
        self.run_bzr('checkout --lightweight branch checkout')
1508.1.24 by Robert Collins
Add update command for use with checkouts.
93
        self.build_tree(['checkout/file'])
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
94
        self.run_bzr('add checkout/file')
95
        self.run_bzr('commit -m add-file checkout')
96
        self.run_bzr('checkout --lightweight branch checkout2')
1508.1.24 by Robert Collins
Add update command for use with checkouts.
97
        # now alter file in checkout
98
        a_file = file('checkout/file', 'wt')
99
        a_file.write('Foo')
100
        a_file.close()
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
101
        self.run_bzr('commit -m checnge-file checkout')
1508.1.24 by Robert Collins
Add update command for use with checkouts.
102
        # now checkout2 should be out of date
103
        # make a local change to file
104
        a_file = file('checkout2/file', 'wt')
105
        a_file.write('Bar')
106
        a_file.close()
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
107
        out,err = self.run_bzr('update checkout2', retcode=1)
2504.2.3 by Daniel Watkins
Further modified existing tests to cover the new output.
108
        self.assertContainsRe(err, 'M  file')
1508.1.24 by Robert Collins
Add update command for use with checkouts.
109
        self.assertEqual(['1 conflicts encountered.',
110
                          'Updated to revision 2.'],
2504.2.2 by Daniel Watkins
Modified existing tests to reflect changes to output.
111
                         err.split('\n')[-3:-1])
1534.7.164 by Aaron Bentley
Updated test to new conflict message
112
        self.assertContainsRe(err, 'Text conflict in file\n')
1508.1.24 by Robert Collins
Add update command for use with checkouts.
113
        self.assertEqual('', out)
1587.1.11 by Robert Collins
Local commits appear to be working properly.
114
115
    def test_smoke_update_checkout_bound_branch_local_commits(self):
116
        # smoke test for doing an update of a checkout of a bound
117
        # branch with local commits.
1908.6.11 by Robert Collins
Remove usage of tree.pending_merges().
118
        master = self.make_branch_and_tree('master')
1587.1.11 by Robert Collins
Local commits appear to be working properly.
119
        # make a bound branch
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
120
        self.run_bzr('checkout master child')
1908.6.11 by Robert Collins
Remove usage of tree.pending_merges().
121
        # get an object form of child
122
        child = WorkingTree.open('child')
1587.1.11 by Robert Collins
Local commits appear to be working properly.
123
        # check that out
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
124
        self.run_bzr('checkout --lightweight child checkout')
1908.6.11 by Robert Collins
Remove usage of tree.pending_merges().
125
        # get an object form of the checkout to manipulate
126
        wt = WorkingTree.open('checkout')
1587.1.11 by Robert Collins
Local commits appear to be working properly.
127
        # change master
128
        a_file = file('master/file', 'wt')
129
        a_file.write('Foo')
130
        a_file.close()
1908.6.11 by Robert Collins
Remove usage of tree.pending_merges().
131
        master.add(['file'])
132
        master_tip = master.commit('add file')
1587.1.11 by Robert Collins
Local commits appear to be working properly.
133
        # change child
134
        a_file = file('child/file_b', 'wt')
135
        a_file.write('Foo')
136
        a_file.close()
1908.6.11 by Robert Collins
Remove usage of tree.pending_merges().
137
        child.add(['file_b'])
138
        child_tip = child.commit('add file_b', local=True)
1587.1.11 by Robert Collins
Local commits appear to be working properly.
139
        # check checkout
140
        a_file = file('checkout/file_c', 'wt')
141
        a_file.write('Foo')
142
        a_file.close()
1908.6.11 by Robert Collins
Remove usage of tree.pending_merges().
143
        wt.add(['file_c'])
1587.1.11 by Robert Collins
Local commits appear to be working properly.
144
145
        # now, update checkout ->
146
        # get all three files and a pending merge.
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
147
        out, err = self.run_bzr('update checkout')
1711.2.108 by John Arbash Meinel
Assert that update informs the user about where their local commits went.
148
        self.assertEqual('', out)
2504.2.3 by Daniel Watkins
Further modified existing tests to cover the new output.
149
        self.assertContainsRe(err, '\+N  file')
150
        self.assertContainsRe(err, '\+N  file_b')
1711.2.108 by John Arbash Meinel
Assert that update informs the user about where their local commits went.
151
        self.assertContainsRe(err, 'Updated to revision 1.\n'
152
                                   'Your local commits will now show as'
153
                                   ' pending merges')
1908.6.11 by Robert Collins
Remove usage of tree.pending_merges().
154
        self.assertEqual([master_tip, child_tip], wt.get_parent_ids())
1587.1.11 by Robert Collins
Local commits appear to be working properly.
155
        self.failUnlessExists('checkout/file')
156
        self.failUnlessExists('checkout/file_b')
157
        self.failUnlessExists('checkout/file_c')
158
        self.assertTrue(wt.has_filename('file_c'))
1711.2.109 by John Arbash Meinel
Add a test for handling a pending merge plus an update.
159
160
    def test_update_with_merges(self):
161
        # Test that 'bzr update' works correctly when you have
162
        # an update in the master tree, and a lightweight checkout
163
        # which has merged another branch
164
        master = self.make_branch_and_tree('master')
165
        self.build_tree(['master/file'])
166
        master.add(['file'])
167
        master.commit('one', rev_id='m1')
168
169
        self.build_tree(['checkout1/'])
170
        checkout_dir = bzrdir.BzrDirMetaFormat1().initialize('checkout1')
171
        branch.BranchReferenceFormat().initialize(checkout_dir, master.branch)
172
        checkout1 = checkout_dir.create_workingtree('m1')
173
174
        # Create a second branch, with an extra commit
175
        other = master.bzrdir.sprout('other').open_workingtree()
176
        self.build_tree(['other/file2'])
177
        other.add(['file2'])
178
        other.commit('other2', rev_id='o2')
179
180
        # Create a new commit in the master branch
181
        self.build_tree(['master/file3'])
182
        master.add(['file3'])
183
        master.commit('f3', rev_id='m2')
184
185
        # Merge the other branch into checkout
186
        os.chdir('checkout1')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
187
        self.run_bzr('merge ../other')
1711.2.109 by John Arbash Meinel
Add a test for handling a pending merge plus an update.
188
1908.6.11 by Robert Collins
Remove usage of tree.pending_merges().
189
        self.assertEqual(['o2'], checkout1.get_parent_ids()[1:])
1711.2.109 by John Arbash Meinel
Add a test for handling a pending merge plus an update.
190
191
        # At this point, 'commit' should fail, because we are out of date
192
        self.run_bzr_error(["please run 'bzr update'"],
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
193
                           'commit -m merged')
1711.2.109 by John Arbash Meinel
Add a test for handling a pending merge plus an update.
194
195
        # This should not report about local commits being pending
196
        # merges, because they were real merges
197
        out, err = self.run_bzr('update')
198
        self.assertEqual('', out)
2504.2.2 by Daniel Watkins
Modified existing tests to reflect changes to output.
199
        self.assertEndsWith(err, 'All changes applied successfully.\n'
200
                         'Updated to revision 2.\n')
2504.2.3 by Daniel Watkins
Further modified existing tests to cover the new output.
201
        self.assertContainsRe(err, r'\+N  file3')
1711.2.109 by John Arbash Meinel
Add a test for handling a pending merge plus an update.
202
        # The pending merges should still be there
1908.6.11 by Robert Collins
Remove usage of tree.pending_merges().
203
        self.assertEqual(['o2'], checkout1.get_parent_ids()[1:])
2084.2.1 by Aaron Bentley
Support updating lightweight checkouts of readonly branches
204
205
    def test_readonly_lightweight_update(self):
206
        """Update a light checkout of a readonly branch"""
207
        tree = self.make_branch_and_tree('branch')
208
        readonly_branch = branch.Branch.open(self.get_readonly_url('branch'))
2255.7.55 by Robert Collins
Whitespace fix.
209
        checkout = readonly_branch.create_checkout('checkout',
2084.2.1 by Aaron Bentley
Support updating lightweight checkouts of readonly branches
210
                                                   lightweight=True)
211
        tree.commit('empty commit')
2552.2.2 by Vincent Ladeuil
Enforce run_bzr(string) where possible.
212
        self.run_bzr('update checkout')