1508.1.24
by Robert Collins
Add update command for use with checkouts. |
1 |
# Copyright (C) 2006 by Canonical Ltd
|
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): |
|
32 |
self.runbzr("init") |
|
33 |
out, err = self.runbzr('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): |
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 |
||
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') |
1587.1.14
by Robert Collins
Make bound branch creation happen via 'checkout' |
45 |
self.runbzr('checkout --lightweight branch checkout') |
1534.5.1
by Robert Collins
Give info some reasonable output and tests. |
46 |
out, err = self.runbzr('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') |
|
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) |
|
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
|
|
1587.1.14
by Robert Collins
Make bound branch creation happen via 'checkout' |
62 |
self.runbzr('checkout --lightweight branch checkout') |
1508.1.24
by Robert Collins
Add update command for use with checkouts. |
63 |
self.build_tree(['checkout/file']) |
64 |
self.runbzr('add checkout/file') |
|
65 |
self.runbzr('commit -m add-file checkout') |
|
66 |
# now branch should be out of date
|
|
67 |
out,err = self.runbzr('update branch') |
|
1711.2.107
by John Arbash Meinel
re-enable a skipped update test, and clean it up |
68 |
self.assertEqual('', out) |
69 |
self.assertEqual('All changes applied successfully.\n' |
|
70 |
'Updated to revision 1.\n', err) |
|
1508.1.24
by Robert Collins
Add update command for use with checkouts. |
71 |
self.failUnlessExists('branch/file') |
72 |
||
1587.1.14
by Robert Collins
Make bound branch creation happen via 'checkout' |
73 |
def test_update_out_of_date_light_checkout(self): |
1508.1.24
by Robert Collins
Add update command for use with checkouts. |
74 |
self.make_branch_and_tree('branch') |
75 |
# make two checkouts
|
|
1587.1.14
by Robert Collins
Make bound branch creation happen via 'checkout' |
76 |
self.runbzr('checkout --lightweight branch checkout') |
77 |
self.runbzr('checkout --lightweight branch checkout2') |
|
1508.1.24
by Robert Collins
Add update command for use with checkouts. |
78 |
self.build_tree(['checkout/file']) |
79 |
self.runbzr('add checkout/file') |
|
80 |
self.runbzr('commit -m add-file checkout') |
|
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) |
|
86 |
self.assertEqual('', out) |
|
87 |
||
88 |
def test_update_conflicts_returns_2(self): |
|
89 |
self.make_branch_and_tree('branch') |
|
90 |
# make two checkouts
|
|
1587.1.14
by Robert Collins
Make bound branch creation happen via 'checkout' |
91 |
self.runbzr('checkout --lightweight branch checkout') |
1508.1.24
by Robert Collins
Add update command for use with checkouts. |
92 |
self.build_tree(['checkout/file']) |
93 |
self.runbzr('add checkout/file') |
|
94 |
self.runbzr('commit -m add-file checkout') |
|
1587.1.14
by Robert Collins
Make bound branch creation happen via 'checkout' |
95 |
self.runbzr('checkout --lightweight branch checkout2') |
1508.1.24
by Robert Collins
Add update command for use with checkouts. |
96 |
# now alter file in checkout
|
97 |
a_file = file('checkout/file', 'wt') |
|
98 |
a_file.write('Foo') |
|
99 |
a_file.close() |
|
100 |
self.runbzr('commit -m checnge-file checkout') |
|
101 |
# now checkout2 should be out of date
|
|
102 |
# make a local change to file
|
|
103 |
a_file = file('checkout2/file', 'wt') |
|
104 |
a_file.write('Bar') |
|
105 |
a_file.close() |
|
106 |
out,err = self.runbzr('update checkout2', retcode=1) |
|
107 |
self.assertEqual(['1 conflicts encountered.', |
|
108 |
'Updated to revision 2.'], |
|
109 |
err.split('\n')[1:3]) |
|
1534.7.164
by Aaron Bentley
Updated test to new conflict message |
110 |
self.assertContainsRe(err, 'Text conflict in file\n') |
1508.1.24
by Robert Collins
Add update command for use with checkouts. |
111 |
self.assertEqual('', out) |
1587.1.11
by Robert Collins
Local commits appear to be working properly. |
112 |
|
113 |
def test_smoke_update_checkout_bound_branch_local_commits(self): |
|
114 |
# smoke test for doing an update of a checkout of a bound
|
|
115 |
# branch with local commits.
|
|
116 |
self.make_branch_and_tree('master') |
|
117 |
# make a bound branch
|
|
1587.1.14
by Robert Collins
Make bound branch creation happen via 'checkout' |
118 |
self.run_bzr('checkout', 'master', 'child') |
1587.1.11
by Robert Collins
Local commits appear to be working properly. |
119 |
# check that out
|
1587.1.14
by Robert Collins
Make bound branch creation happen via 'checkout' |
120 |
self.run_bzr('checkout', '--lightweight', 'child', 'checkout') |
1587.1.11
by Robert Collins
Local commits appear to be working properly. |
121 |
# change master
|
122 |
a_file = file('master/file', 'wt') |
|
123 |
a_file.write('Foo') |
|
124 |
a_file.close() |
|
125 |
self.run_bzr('add', 'master') |
|
126 |
self.run_bzr('commit', '-m', 'add file', 'master') |
|
127 |
# change child
|
|
128 |
a_file = file('child/file_b', 'wt') |
|
129 |
a_file.write('Foo') |
|
130 |
a_file.close() |
|
131 |
self.run_bzr('add', 'child') |
|
132 |
self.run_bzr('commit', '--local', '-m', 'add file_b', 'child') |
|
133 |
# check checkout
|
|
134 |
a_file = file('checkout/file_c', 'wt') |
|
135 |
a_file.write('Foo') |
|
136 |
a_file.close() |
|
137 |
self.run_bzr('add', 'checkout') |
|
138 |
||
139 |
# now, update checkout ->
|
|
140 |
# get all three files and a pending merge.
|
|
1711.2.108
by John Arbash Meinel
Assert that update informs the user about where their local commits went. |
141 |
out, err = self.run_bzr('update', 'checkout') |
142 |
self.assertEqual('', out) |
|
143 |
self.assertContainsRe(err, 'Updated to revision 1.\n' |
|
144 |
'Your local commits will now show as'
|
|
145 |
' pending merges') |
|
1587.1.11
by Robert Collins
Local commits appear to be working properly. |
146 |
wt = WorkingTree.open('checkout') |
147 |
self.assertNotEqual([], wt.pending_merges()) |
|
148 |
self.failUnlessExists('checkout/file') |
|
149 |
self.failUnlessExists('checkout/file_b') |
|
150 |
self.failUnlessExists('checkout/file_c') |
|
151 |
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. |
152 |
|
153 |
def test_update_with_merges(self): |
|
154 |
# Test that 'bzr update' works correctly when you have
|
|
155 |
# an update in the master tree, and a lightweight checkout
|
|
156 |
# which has merged another branch
|
|
157 |
master = self.make_branch_and_tree('master') |
|
158 |
self.build_tree(['master/file']) |
|
159 |
master.add(['file']) |
|
160 |
master.commit('one', rev_id='m1') |
|
161 |
||
162 |
self.build_tree(['checkout1/']) |
|
163 |
checkout_dir = bzrdir.BzrDirMetaFormat1().initialize('checkout1') |
|
164 |
branch.BranchReferenceFormat().initialize(checkout_dir, master.branch) |
|
165 |
checkout1 = checkout_dir.create_workingtree('m1') |
|
166 |
||
167 |
# Create a second branch, with an extra commit
|
|
168 |
other = master.bzrdir.sprout('other').open_workingtree() |
|
169 |
self.build_tree(['other/file2']) |
|
170 |
other.add(['file2']) |
|
171 |
other.commit('other2', rev_id='o2') |
|
172 |
||
173 |
# Create a new commit in the master branch
|
|
174 |
self.build_tree(['master/file3']) |
|
175 |
master.add(['file3']) |
|
176 |
master.commit('f3', rev_id='m2') |
|
177 |
||
178 |
# Merge the other branch into checkout
|
|
179 |
os.chdir('checkout1') |
|
180 |
self.run_bzr('merge', '../other') |
|
181 |
||
182 |
self.assertEqual(['o2'], checkout1.pending_merges()) |
|
183 |
||
184 |
# At this point, 'commit' should fail, because we are out of date
|
|
185 |
self.run_bzr_error(["please run 'bzr update'"], |
|
186 |
'commit', '-m', 'merged') |
|
187 |
||
188 |
# This should not report about local commits being pending
|
|
189 |
# merges, because they were real merges
|
|
190 |
out, err = self.run_bzr('update') |
|
191 |
self.assertEqual('', out) |
|
192 |
self.assertEqual('All changes applied successfully.\n' |
|
193 |
'Updated to revision 2.\n', err) |
|
194 |
||
195 |
# The pending merges should still be there
|
|
196 |
self.assertEqual(['o2'], checkout1.pending_merges()) |