~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_update.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-09-20 02:40:52 UTC
  • mfrom: (2835.1.1 ianc-integration)
  • Revision ID: pqm@pqm.ubuntu.com-20070920024052-y2l7r5o00zrpnr73
No longer propagate index differences automatically (Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006 by Canonical Ltd
 
1
# Copyright (C) 2006 Canonical Ltd
2
2
# -*- coding: utf-8 -*-
3
 
 
 
3
#
4
4
# This program is free software; you can redistribute it and/or modify
5
5
# it under the terms of the GNU General Public License as published by
6
6
# the Free Software Foundation; either version 2 of the License, or
7
7
# (at your option) any later version.
8
 
 
 
8
#
9
9
# This program is distributed in the hope that it will be useful,
10
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
12
# GNU General Public License for more details.
13
 
 
 
13
#
14
14
# You should have received a copy of the GNU General Public License
15
15
# along with this program; if not, write to the Free Software
16
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
18
 
19
19
"""Tests for the update command of bzr."""
20
20
 
 
21
import os
21
22
 
 
23
from bzrlib import branch, bzrdir
22
24
from bzrlib.tests import TestSkipped
23
25
from bzrlib.tests.blackbox import ExternalBase
24
26
from bzrlib.workingtree import WorkingTree
27
29
class TestUpdate(ExternalBase):
28
30
 
29
31
    def test_update_standalone_trivial(self):
30
 
        self.runbzr("init")
31
 
        out, err = self.runbzr('update')
32
 
        self.assertEqual('Tree is up to date.\n', err)
 
32
        self.make_branch_and_tree('.')
 
33
        out, err = self.run_bzr('update')
 
34
        self.assertEqual('Tree is up to date at revision 0.\n', err)
 
35
        self.assertEqual('', out)
 
36
 
 
37
    def test_update_standalone_trivial_with_alias_up(self):
 
38
        self.make_branch_and_tree('.')
 
39
        out, err = self.run_bzr('up')
 
40
        self.assertEqual('Tree is up to date at revision 0.\n', err)
33
41
        self.assertEqual('', out)
34
42
 
35
43
    def test_update_up_to_date_light_checkout(self):
36
44
        self.make_branch_and_tree('branch')
37
 
        self.runbzr('checkout --lightweight branch checkout')
38
 
        out, err = self.runbzr('update checkout')
39
 
        self.assertEqual('Tree is up to date.\n', err)
 
45
        self.run_bzr('checkout --lightweight branch checkout')
 
46
        out, err = self.run_bzr('update checkout')
 
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')
 
52
        self.run_bzr('checkout branch checkout')
 
53
        out, err = self.run_bzr('update checkout')
 
54
        self.assertEqual('Tree is up to date at revision 0.\n', err)
40
55
        self.assertEqual('', out)
41
56
 
42
57
    def test_update_out_of_date_standalone_tree(self):
43
58
        # FIXME the default format has to change for this to pass
44
59
        # because it currently uses the branch last-revision marker.
45
 
        raise TestSkipped('default format too old')
46
60
        self.make_branch_and_tree('branch')
47
61
        # make a checkout
48
 
        self.runbzr('checkout --lightweight branch checkout')
 
62
        self.run_bzr('checkout --lightweight branch checkout')
49
63
        self.build_tree(['checkout/file'])
50
 
        self.runbzr('add checkout/file')
51
 
        self.runbzr('commit -m add-file checkout')
 
64
        self.run_bzr('add checkout/file')
 
65
        self.run_bzr('commit -m add-file checkout')
52
66
        # now branch should be out of date
53
 
        out,err = self.runbzr('update branch')
54
 
        self.assertEqual('Updated to revision 1.\n', out)
55
 
        self.assertEqual('', err)
 
67
        out,err = self.run_bzr('update branch')
 
68
        self.assertEqual('', out)
 
69
        self.assertContainsRe(err, '\+N  file')
 
70
        self.assertEndsWith(err, 'All changes applied successfully.\n'
 
71
                         'Updated to revision 1.\n')
56
72
        self.failUnlessExists('branch/file')
57
73
 
58
74
    def test_update_out_of_date_light_checkout(self):
59
75
        self.make_branch_and_tree('branch')
60
76
        # make two checkouts
61
 
        self.runbzr('checkout --lightweight branch checkout')
62
 
        self.runbzr('checkout --lightweight branch checkout2')
 
77
        self.run_bzr('checkout --lightweight branch checkout')
 
78
        self.run_bzr('checkout --lightweight branch checkout2')
63
79
        self.build_tree(['checkout/file'])
64
 
        self.runbzr('add checkout/file')
65
 
        self.runbzr('commit -m add-file checkout')
 
80
        self.run_bzr('add checkout/file')
 
81
        self.run_bzr('commit -m add-file checkout')
66
82
        # now checkout2 should be out of date
67
 
        out,err = self.runbzr('update checkout2')
68
 
        self.assertEqual('All changes applied successfully.\n'
69
 
                         'Updated to revision 1.\n',
70
 
                         err)
 
83
        out,err = self.run_bzr('update checkout2')
 
84
        self.assertContainsRe(err, '\+N  file')
 
85
        self.assertEndsWith(err, 'All changes applied successfully.\n'
 
86
                         'Updated to revision 1.\n')
71
87
        self.assertEqual('', out)
72
88
 
73
89
    def test_update_conflicts_returns_2(self):
74
90
        self.make_branch_and_tree('branch')
75
91
        # make two checkouts
76
 
        self.runbzr('checkout --lightweight branch checkout')
 
92
        self.run_bzr('checkout --lightweight branch checkout')
77
93
        self.build_tree(['checkout/file'])
78
 
        self.runbzr('add checkout/file')
79
 
        self.runbzr('commit -m add-file checkout')
80
 
        self.runbzr('checkout --lightweight branch checkout2')
 
94
        self.run_bzr('add checkout/file')
 
95
        self.run_bzr('commit -m add-file checkout')
 
96
        self.run_bzr('checkout --lightweight branch checkout2')
81
97
        # now alter file in checkout
82
98
        a_file = file('checkout/file', 'wt')
83
99
        a_file.write('Foo')
84
100
        a_file.close()
85
 
        self.runbzr('commit -m checnge-file checkout')
 
101
        self.run_bzr('commit -m checnge-file checkout')
86
102
        # now checkout2 should be out of date
87
103
        # make a local change to file
88
104
        a_file = file('checkout2/file', 'wt')
89
105
        a_file.write('Bar')
90
106
        a_file.close()
91
 
        out,err = self.runbzr('update checkout2', retcode=1)
 
107
        out,err = self.run_bzr('update checkout2', retcode=1)
 
108
        self.assertContainsRe(err, 'M  file')
92
109
        self.assertEqual(['1 conflicts encountered.',
93
110
                          'Updated to revision 2.'],
94
 
                         err.split('\n')[1:3])
 
111
                         err.split('\n')[-3:-1])
95
112
        self.assertContainsRe(err, 'Text conflict in file\n')
96
113
        self.assertEqual('', out)
97
114
 
98
115
    def test_smoke_update_checkout_bound_branch_local_commits(self):
99
116
        # smoke test for doing an update of a checkout of a bound
100
117
        # branch with local commits.
101
 
        self.make_branch_and_tree('master')
 
118
        master = self.make_branch_and_tree('master')
102
119
        # make a bound branch
103
 
        self.run_bzr('checkout', 'master', 'child')
 
120
        self.run_bzr('checkout master child')
 
121
        # get an object form of child
 
122
        child = WorkingTree.open('child')
104
123
        # check that out
105
 
        self.run_bzr('checkout', '--lightweight', 'child', 'checkout')
 
124
        self.run_bzr('checkout --lightweight child checkout')
 
125
        # get an object form of the checkout to manipulate
 
126
        wt = WorkingTree.open('checkout')
106
127
        # change master
107
128
        a_file = file('master/file', 'wt')
108
129
        a_file.write('Foo')
109
130
        a_file.close()
110
 
        self.run_bzr('add', 'master')
111
 
        self.run_bzr('commit', '-m', 'add file', 'master')
 
131
        master.add(['file'])
 
132
        master_tip = master.commit('add file')
112
133
        # change child
113
134
        a_file = file('child/file_b', 'wt')
114
135
        a_file.write('Foo')
115
136
        a_file.close()
116
 
        self.run_bzr('add', 'child')
117
 
        self.run_bzr('commit', '--local', '-m', 'add file_b', 'child')
 
137
        child.add(['file_b'])
 
138
        child_tip = child.commit('add file_b', local=True)
118
139
        # check checkout
119
140
        a_file = file('checkout/file_c', 'wt')
120
141
        a_file.write('Foo')
121
142
        a_file.close()
122
 
        self.run_bzr('add', 'checkout')
 
143
        wt.add(['file_c'])
123
144
 
124
145
        # now, update checkout ->
125
146
        # get all three files and a pending merge.
126
 
        self.run_bzr('update', 'checkout')
127
 
        wt = WorkingTree.open('checkout')
128
 
        self.assertNotEqual([], wt.pending_merges())
 
147
        out, err = self.run_bzr('update checkout')
 
148
        self.assertEqual('', out)
 
149
        self.assertContainsRe(err, '\+N  file')
 
150
        self.assertContainsRe(err, '\+N  file_b')
 
151
        self.assertContainsRe(err, 'Updated to revision 1.\n'
 
152
                                   'Your local commits will now show as'
 
153
                                   ' pending merges')
 
154
        self.assertEqual([master_tip, child_tip], wt.get_parent_ids())
129
155
        self.failUnlessExists('checkout/file')
130
156
        self.failUnlessExists('checkout/file_b')
131
157
        self.failUnlessExists('checkout/file_c')
132
158
        self.assertTrue(wt.has_filename('file_c'))
 
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')
 
187
        self.run_bzr('merge ../other')
 
188
 
 
189
        self.assertEqual(['o2'], checkout1.get_parent_ids()[1:])
 
190
 
 
191
        # At this point, 'commit' should fail, because we are out of date
 
192
        self.run_bzr_error(["please run 'bzr update'"],
 
193
                           'commit -m merged')
 
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)
 
199
        self.assertEndsWith(err, 'All changes applied successfully.\n'
 
200
                         'Updated to revision 2.\n')
 
201
        self.assertContainsRe(err, r'\+N  file3')
 
202
        # The pending merges should still be there
 
203
        self.assertEqual(['o2'], checkout1.get_parent_ids()[1:])
 
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'))
 
209
        checkout = readonly_branch.create_checkout('checkout',
 
210
                                                   lightweight=True)
 
211
        tree.commit('empty commit')
 
212
        self.run_bzr('update checkout')