1
# Copyright (C) 2006 by Canonical Ltd
2
# -*- coding: utf-8 -*-
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.
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.
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
19
"""Tests for the update command of bzr."""
22
from bzrlib.tests import TestSkipped
23
from bzrlib.tests.blackbox import ExternalBase
24
from bzrlib.workingtree import WorkingTree
27
class TestUpdate(ExternalBase):
29
def test_update_standalone_trivial(self):
31
out, err = self.runbzr('update')
32
self.assertEqual('Tree is up to date at revision 0.\n', err)
33
self.assertEqual('', out)
35
def test_update_up_to_date_light_checkout(self):
36
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 at revision 0.\n', err)
40
self.assertEqual('', out)
42
def test_update_up_to_date_checkout(self):
43
self.make_branch_and_tree('branch')
44
self.run_bzr('checkout', 'branch', 'checkout')
45
out, err = self.run_bzr('update', 'checkout')
46
self.assertEqual('Tree is up to date at revision 0.\n', err)
47
self.assertEqual('', out)
49
def test_update_out_of_date_standalone_tree(self):
50
# FIXME the default format has to change for this to pass
51
# because it currently uses the branch last-revision marker.
52
raise TestSkipped('default format too old')
53
self.make_branch_and_tree('branch')
55
self.runbzr('checkout --lightweight branch checkout')
56
self.build_tree(['checkout/file'])
57
self.runbzr('add checkout/file')
58
self.runbzr('commit -m add-file checkout')
59
# now branch should be out of date
60
out,err = self.runbzr('update branch')
61
self.assertEqual('Updated to revision 1.\n', out)
62
self.assertEqual('', err)
63
self.failUnlessExists('branch/file')
65
def test_update_out_of_date_light_checkout(self):
66
self.make_branch_and_tree('branch')
68
self.runbzr('checkout --lightweight branch checkout')
69
self.runbzr('checkout --lightweight branch checkout2')
70
self.build_tree(['checkout/file'])
71
self.runbzr('add checkout/file')
72
self.runbzr('commit -m add-file checkout')
73
# now checkout2 should be out of date
74
out,err = self.runbzr('update checkout2')
75
self.assertEqual('All changes applied successfully.\n'
76
'Updated to revision 1.\n',
78
self.assertEqual('', out)
80
def test_update_conflicts_returns_2(self):
81
self.make_branch_and_tree('branch')
83
self.runbzr('checkout --lightweight branch checkout')
84
self.build_tree(['checkout/file'])
85
self.runbzr('add checkout/file')
86
self.runbzr('commit -m add-file checkout')
87
self.runbzr('checkout --lightweight branch checkout2')
88
# now alter file in checkout
89
a_file = file('checkout/file', 'wt')
92
self.runbzr('commit -m checnge-file checkout')
93
# now checkout2 should be out of date
94
# make a local change to file
95
a_file = file('checkout2/file', 'wt')
98
out,err = self.runbzr('update checkout2', retcode=1)
99
self.assertEqual(['1 conflicts encountered.',
100
'Updated to revision 2.'],
101
err.split('\n')[1:3])
102
self.assertContainsRe(err, 'Text conflict in file\n')
103
self.assertEqual('', out)
105
def test_smoke_update_checkout_bound_branch_local_commits(self):
106
# smoke test for doing an update of a checkout of a bound
107
# branch with local commits.
108
self.make_branch_and_tree('master')
109
# make a bound branch
110
self.run_bzr('checkout', 'master', 'child')
112
self.run_bzr('checkout', '--lightweight', 'child', 'checkout')
114
a_file = file('master/file', 'wt')
117
self.run_bzr('add', 'master')
118
self.run_bzr('commit', '-m', 'add file', 'master')
120
a_file = file('child/file_b', 'wt')
123
self.run_bzr('add', 'child')
124
self.run_bzr('commit', '--local', '-m', 'add file_b', 'child')
126
a_file = file('checkout/file_c', 'wt')
129
self.run_bzr('add', 'checkout')
131
# now, update checkout ->
132
# 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())
136
self.failUnlessExists('checkout/file')
137
self.failUnlessExists('checkout/file_b')
138
self.failUnlessExists('checkout/file_c')
139
self.assertTrue(wt.has_filename('file_c'))