~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: John Arbash Meinel
  • Date: 2006-10-11 00:23:23 UTC
  • mfrom: (2070 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2071.
  • Revision ID: john@arbash-meinel.com-20061011002323-82ba88c293d7caff
[merge] bzr.dev 2070

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# Copyright (C) 2006 by 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
32
34
        self.assertEqual('Tree is up to date at revision 0.\n', err)
33
35
        self.assertEqual('', out)
34
36
 
 
37
    def test_update_standalone_trivial_with_alias_up(self):
 
38
        self.runbzr("init")
 
39
        out, err = self.runbzr('up')
 
40
        self.assertEqual('Tree is up to date at revision 0.\n', err)
 
41
        self.assertEqual('', out)
 
42
 
35
43
    def test_update_up_to_date_light_checkout(self):
36
44
        self.make_branch_and_tree('branch')
37
45
        self.runbzr('checkout --lightweight branch checkout')
49
57
    def test_update_out_of_date_standalone_tree(self):
50
58
        # FIXME the default format has to change for this to pass
51
59
        # because it currently uses the branch last-revision marker.
52
 
        raise TestSkipped('default format too old')
53
60
        self.make_branch_and_tree('branch')
54
61
        # make a checkout
55
62
        self.runbzr('checkout --lightweight branch checkout')
58
65
        self.runbzr('commit -m add-file checkout')
59
66
        # now branch should be out of date
60
67
        out,err = self.runbzr('update branch')
61
 
        self.assertEqual('Updated to revision 1.\n', out)
62
 
        self.assertEqual('', err)
 
68
        self.assertEqual('', out)
 
69
        self.assertEqual('All changes applied successfully.\n'
 
70
                         'Updated to revision 1.\n', err)
63
71
        self.failUnlessExists('branch/file')
64
72
 
65
73
    def test_update_out_of_date_light_checkout(self):
105
113
    def test_smoke_update_checkout_bound_branch_local_commits(self):
106
114
        # smoke test for doing an update of a checkout of a bound
107
115
        # branch with local commits.
108
 
        self.make_branch_and_tree('master')
 
116
        master = self.make_branch_and_tree('master')
109
117
        # make a bound branch
110
118
        self.run_bzr('checkout', 'master', 'child')
 
119
        # get an object form of child
 
120
        child = WorkingTree.open('child')
111
121
        # check that out
112
122
        self.run_bzr('checkout', '--lightweight', 'child', 'checkout')
 
123
        # get an object form of the checkout to manipulate
 
124
        wt = WorkingTree.open('checkout')
113
125
        # change master
114
126
        a_file = file('master/file', 'wt')
115
127
        a_file.write('Foo')
116
128
        a_file.close()
117
 
        self.run_bzr('add', 'master')
118
 
        self.run_bzr('commit', '-m', 'add file', 'master')
 
129
        master.add(['file'])
 
130
        master_tip = master.commit('add file')
119
131
        # change child
120
132
        a_file = file('child/file_b', 'wt')
121
133
        a_file.write('Foo')
122
134
        a_file.close()
123
 
        self.run_bzr('add', 'child')
124
 
        self.run_bzr('commit', '--local', '-m', 'add file_b', 'child')
 
135
        child.add(['file_b'])
 
136
        child_tip = child.commit('add file_b', local=True)
125
137
        # check checkout
126
138
        a_file = file('checkout/file_c', 'wt')
127
139
        a_file.write('Foo')
128
140
        a_file.close()
129
 
        self.run_bzr('add', 'checkout')
 
141
        wt.add(['file_c'])
130
142
 
131
143
        # now, update checkout ->
132
144
        # get all three files and a pending merge.
133
 
        self.run_bzr('update', 'checkout')
134
 
        wt = WorkingTree.open('checkout')
135
 
        self.assertNotEqual([], wt.pending_merges())
 
145
        out, err = self.run_bzr('update', 'checkout')
 
146
        self.assertEqual('', out)
 
147
        self.assertContainsRe(err, 'Updated to revision 1.\n'
 
148
                                   'Your local commits will now show as'
 
149
                                   ' pending merges')
 
150
        self.assertEqual([master_tip, child_tip], wt.get_parent_ids())
136
151
        self.failUnlessExists('checkout/file')
137
152
        self.failUnlessExists('checkout/file_b')
138
153
        self.failUnlessExists('checkout/file_c')
139
154
        self.assertTrue(wt.has_filename('file_c'))
 
155
 
 
156
    def test_update_with_merges(self):
 
157
        # Test that 'bzr update' works correctly when you have
 
158
        # an update in the master tree, and a lightweight checkout
 
159
        # which has merged another branch
 
160
        master = self.make_branch_and_tree('master')
 
161
        self.build_tree(['master/file'])
 
162
        master.add(['file'])
 
163
        master.commit('one', rev_id='m1')
 
164
 
 
165
        self.build_tree(['checkout1/'])
 
166
        checkout_dir = bzrdir.BzrDirMetaFormat1().initialize('checkout1')
 
167
        branch.BranchReferenceFormat().initialize(checkout_dir, master.branch)
 
168
        checkout1 = checkout_dir.create_workingtree('m1')
 
169
 
 
170
        # Create a second branch, with an extra commit
 
171
        other = master.bzrdir.sprout('other').open_workingtree()
 
172
        self.build_tree(['other/file2'])
 
173
        other.add(['file2'])
 
174
        other.commit('other2', rev_id='o2')
 
175
 
 
176
        # Create a new commit in the master branch
 
177
        self.build_tree(['master/file3'])
 
178
        master.add(['file3'])
 
179
        master.commit('f3', rev_id='m2')
 
180
 
 
181
        # Merge the other branch into checkout
 
182
        os.chdir('checkout1')
 
183
        self.run_bzr('merge', '../other')
 
184
 
 
185
        self.assertEqual(['o2'], checkout1.get_parent_ids()[1:])
 
186
 
 
187
        # At this point, 'commit' should fail, because we are out of date
 
188
        self.run_bzr_error(["please run 'bzr update'"],
 
189
                           'commit', '-m', 'merged')
 
190
 
 
191
        # This should not report about local commits being pending
 
192
        # merges, because they were real merges
 
193
        out, err = self.run_bzr('update')
 
194
        self.assertEqual('', out)
 
195
        self.assertEqual('All changes applied successfully.\n'
 
196
                         'Updated to revision 2.\n', err)
 
197
 
 
198
        # The pending merges should still be there
 
199
        self.assertEqual(['o2'], checkout1.get_parent_ids()[1:])