~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: 2009-10-02 20:32:50 UTC
  • mto: (4679.6.1 2.1-export-c-api)
  • mto: This revision was merged to the branch mainline in revision 4735.
  • Revision ID: john@arbash-meinel.com-20091002203250-q6iv6o2mwjqp4g53
Add __iter__ support.

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
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
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
17
 
18
18
 
19
19
"""Tests for the update command of bzr."""
21
21
import os
22
22
 
23
23
from bzrlib import branch, bzrdir
24
 
from bzrlib.tests import TestSkipped
25
24
from bzrlib.tests.blackbox import ExternalBase
26
25
from bzrlib.workingtree import WorkingTree
27
26
 
29
28
class TestUpdate(ExternalBase):
30
29
 
31
30
    def test_update_standalone_trivial(self):
32
 
        self.runbzr("init")
33
 
        out, err = self.runbzr('update')
 
31
        self.make_branch_and_tree('.')
 
32
        out, err = self.run_bzr('update')
34
33
        self.assertEqual('Tree is up to date at revision 0.\n', err)
35
34
        self.assertEqual('', out)
36
35
 
37
36
    def test_update_standalone_trivial_with_alias_up(self):
38
 
        self.runbzr("init")
39
 
        out, err = self.runbzr('up')
 
37
        self.make_branch_and_tree('.')
 
38
        out, err = self.run_bzr('up')
40
39
        self.assertEqual('Tree is up to date at revision 0.\n', err)
41
40
        self.assertEqual('', out)
42
41
 
43
42
    def test_update_up_to_date_light_checkout(self):
44
43
        self.make_branch_and_tree('branch')
45
 
        self.runbzr('checkout --lightweight branch checkout')
46
 
        out, err = self.runbzr('update checkout')
 
44
        self.run_bzr('checkout --lightweight branch checkout')
 
45
        out, err = self.run_bzr('update checkout')
47
46
        self.assertEqual('Tree is up to date at revision 0.\n', err)
48
47
        self.assertEqual('', out)
49
48
 
50
49
    def test_update_up_to_date_checkout(self):
51
50
        self.make_branch_and_tree('branch')
52
 
        self.run_bzr('checkout', 'branch', 'checkout')
53
 
        out, err = self.run_bzr('update', 'checkout')
 
51
        self.run_bzr('checkout branch checkout')
 
52
        out, err = self.run_bzr('update checkout')
54
53
        self.assertEqual('Tree is up to date at revision 0.\n', err)
55
54
        self.assertEqual('', out)
56
55
 
59
58
        # because it currently uses the branch last-revision marker.
60
59
        self.make_branch_and_tree('branch')
61
60
        # make a checkout
62
 
        self.runbzr('checkout --lightweight branch checkout')
 
61
        self.run_bzr('checkout --lightweight branch checkout')
63
62
        self.build_tree(['checkout/file'])
64
 
        self.runbzr('add checkout/file')
65
 
        self.runbzr('commit -m add-file checkout')
 
63
        self.run_bzr('add checkout/file')
 
64
        self.run_bzr('commit -m add-file checkout')
66
65
        # now branch should be out of date
67
 
        out,err = self.runbzr('update branch')
 
66
        out,err = self.run_bzr('update branch')
68
67
        self.assertEqual('', out)
69
 
        self.assertEqual('All changes applied successfully.\n'
70
 
                         'Updated to revision 1.\n', err)
 
68
        self.assertContainsRe(err, '\+N  file')
 
69
        self.assertEndsWith(err, 'All changes applied successfully.\n'
 
70
                         'Updated to revision 1.\n')
71
71
        self.failUnlessExists('branch/file')
72
72
 
73
73
    def test_update_out_of_date_light_checkout(self):
74
74
        self.make_branch_and_tree('branch')
75
75
        # make two checkouts
76
 
        self.runbzr('checkout --lightweight branch checkout')
77
 
        self.runbzr('checkout --lightweight branch checkout2')
 
76
        self.run_bzr('checkout --lightweight branch checkout')
 
77
        self.run_bzr('checkout --lightweight branch checkout2')
78
78
        self.build_tree(['checkout/file'])
79
 
        self.runbzr('add checkout/file')
80
 
        self.runbzr('commit -m add-file checkout')
 
79
        self.run_bzr('add checkout/file')
 
80
        self.run_bzr('commit -m add-file checkout')
81
81
        # now checkout2 should be out of date
82
 
        out,err = self.runbzr('update checkout2')
83
 
        self.assertEqual('All changes applied successfully.\n'
84
 
                         'Updated to revision 1.\n',
85
 
                         err)
 
82
        out,err = self.run_bzr('update checkout2')
 
83
        self.assertContainsRe(err, '\+N  file')
 
84
        self.assertEndsWith(err, 'All changes applied successfully.\n'
 
85
                         'Updated to revision 1.\n')
86
86
        self.assertEqual('', out)
87
87
 
88
88
    def test_update_conflicts_returns_2(self):
89
89
        self.make_branch_and_tree('branch')
90
90
        # make two checkouts
91
 
        self.runbzr('checkout --lightweight branch checkout')
 
91
        self.run_bzr('checkout --lightweight branch checkout')
92
92
        self.build_tree(['checkout/file'])
93
 
        self.runbzr('add checkout/file')
94
 
        self.runbzr('commit -m add-file checkout')
95
 
        self.runbzr('checkout --lightweight branch checkout2')
 
93
        self.run_bzr('add checkout/file')
 
94
        self.run_bzr('commit -m add-file checkout')
 
95
        self.run_bzr('checkout --lightweight branch checkout2')
96
96
        # now alter file in checkout
97
97
        a_file = file('checkout/file', 'wt')
98
98
        a_file.write('Foo')
99
99
        a_file.close()
100
 
        self.runbzr('commit -m checnge-file checkout')
 
100
        self.run_bzr('commit -m checnge-file checkout')
101
101
        # now checkout2 should be out of date
102
102
        # make a local change to file
103
103
        a_file = file('checkout2/file', 'wt')
104
104
        a_file.write('Bar')
105
105
        a_file.close()
106
 
        out,err = self.runbzr('update checkout2', retcode=1)
 
106
        out,err = self.run_bzr('update checkout2', retcode=1)
 
107
        self.assertContainsRe(err, 'M  file')
107
108
        self.assertEqual(['1 conflicts encountered.',
108
109
                          'Updated to revision 2.'],
109
 
                         err.split('\n')[1:3])
 
110
                         err.split('\n')[-3:-1])
110
111
        self.assertContainsRe(err, 'Text conflict in file\n')
111
112
        self.assertEqual('', out)
112
113
 
113
114
    def test_smoke_update_checkout_bound_branch_local_commits(self):
114
115
        # smoke test for doing an update of a checkout of a bound
115
116
        # branch with local commits.
116
 
        self.make_branch_and_tree('master')
 
117
        master = self.make_branch_and_tree('master')
117
118
        # make a bound branch
118
 
        self.run_bzr('checkout', 'master', 'child')
 
119
        self.run_bzr('checkout master child')
 
120
        # get an object form of child
 
121
        child = WorkingTree.open('child')
119
122
        # check that out
120
 
        self.run_bzr('checkout', '--lightweight', 'child', 'checkout')
 
123
        self.run_bzr('checkout --lightweight child checkout')
 
124
        # get an object form of the checkout to manipulate
 
125
        wt = WorkingTree.open('checkout')
121
126
        # change master
122
127
        a_file = file('master/file', 'wt')
123
128
        a_file.write('Foo')
124
129
        a_file.close()
125
 
        self.run_bzr('add', 'master')
126
 
        self.run_bzr('commit', '-m', 'add file', 'master')
 
130
        master.add(['file'])
 
131
        master_tip = master.commit('add file')
127
132
        # change child
128
133
        a_file = file('child/file_b', 'wt')
129
134
        a_file.write('Foo')
130
135
        a_file.close()
131
 
        self.run_bzr('add', 'child')
132
 
        self.run_bzr('commit', '--local', '-m', 'add file_b', 'child')
 
136
        child.add(['file_b'])
 
137
        child_tip = child.commit('add file_b', local=True)
133
138
        # check checkout
134
139
        a_file = file('checkout/file_c', 'wt')
135
140
        a_file.write('Foo')
136
141
        a_file.close()
137
 
        self.run_bzr('add', 'checkout')
 
142
        wt.add(['file_c'])
138
143
 
139
144
        # now, update checkout ->
140
145
        # get all three files and a pending merge.
141
 
        out, err = self.run_bzr('update', 'checkout')
 
146
        out, err = self.run_bzr('update checkout')
142
147
        self.assertEqual('', out)
 
148
        self.assertContainsRe(err, '\+N  file')
 
149
        self.assertContainsRe(err, '\+N  file_b')
143
150
        self.assertContainsRe(err, 'Updated to revision 1.\n'
144
151
                                   'Your local commits will now show as'
145
152
                                   ' pending merges')
146
 
        wt = WorkingTree.open('checkout')
147
 
        self.assertNotEqual([], wt.pending_merges())
 
153
        self.assertEqual([master_tip, child_tip], wt.get_parent_ids())
148
154
        self.failUnlessExists('checkout/file')
149
155
        self.failUnlessExists('checkout/file_b')
150
156
        self.failUnlessExists('checkout/file_c')
177
183
 
178
184
        # Merge the other branch into checkout
179
185
        os.chdir('checkout1')
180
 
        self.run_bzr('merge', '../other')
 
186
        self.run_bzr('merge ../other')
181
187
 
182
 
        self.assertEqual(['o2'], checkout1.pending_merges())
 
188
        self.assertEqual(['o2'], checkout1.get_parent_ids()[1:])
183
189
 
184
190
        # At this point, 'commit' should fail, because we are out of date
185
191
        self.run_bzr_error(["please run 'bzr update'"],
186
 
                           'commit', '-m', 'merged')
 
192
                           'commit -m merged')
187
193
 
188
194
        # This should not report about local commits being pending
189
195
        # merges, because they were real merges
190
196
        out, err = self.run_bzr('update')
191
197
        self.assertEqual('', out)
192
 
        self.assertEqual('All changes applied successfully.\n'
193
 
                         'Updated to revision 2.\n', err)
194
 
 
 
198
        self.assertEndsWith(err, 'All changes applied successfully.\n'
 
199
                         'Updated to revision 2.\n')
 
200
        self.assertContainsRe(err, r'\+N  file3')
195
201
        # The pending merges should still be there
196
 
        self.assertEqual(['o2'], checkout1.pending_merges())
 
202
        self.assertEqual(['o2'], checkout1.get_parent_ids()[1:])
 
203
 
 
204
    def test_readonly_lightweight_update(self):
 
205
        """Update a light checkout of a readonly branch"""
 
206
        tree = self.make_branch_and_tree('branch')
 
207
        readonly_branch = branch.Branch.open(self.get_readonly_url('branch'))
 
208
        checkout = readonly_branch.create_checkout('checkout',
 
209
                                                   lightweight=True)
 
210
        tree.commit('empty commit')
 
211
        self.run_bzr('update checkout')