/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
1508.1.24 by Robert Collins
Add update command for use with checkouts.
1
# Copyright (C) 2006 by Canonical Ltd
2
# -*- coding: utf-8 -*-
3
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.
8
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.
13
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
21
22
from bzrlib.tests import TestSkipped
23
from bzrlib.tests.blackbox import ExternalBase
1587.1.11 by Robert Collins
Local commits appear to be working properly.
24
from bzrlib.workingtree import WorkingTree
1508.1.24 by Robert Collins
Add update command for use with checkouts.
25
26
27
class TestUpdate(ExternalBase):
28
29
    def test_update_standalone_trivial(self):
30
        self.runbzr("init")
31
        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.
32
        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.
33
        self.assertEqual('', out)
34
1815.3.4 by Stefan (metze) Metzmacher
add simple test for 'bzr up'
35
    def test_update_standalone_trivial_with_alias_up(self):
36
        self.runbzr("init")
37
        out, err = self.runbzr('up')
38
        self.assertEqual('Tree is up to date at revision 0.\n', err)
39
        self.assertEqual('', out)
40
1587.1.14 by Robert Collins
Make bound branch creation happen via 'checkout'
41
    def test_update_up_to_date_light_checkout(self):
1508.1.24 by Robert Collins
Add update command for use with checkouts.
42
        self.make_branch_and_tree('branch')
1587.1.14 by Robert Collins
Make bound branch creation happen via 'checkout'
43
        self.runbzr('checkout --lightweight branch checkout')
1534.5.1 by Robert Collins
Give info some reasonable output and tests.
44
        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.
45
        self.assertEqual('Tree is up to date at revision 0.\n', err)
46
        self.assertEqual('', out)
47
48
    def test_update_up_to_date_checkout(self):
49
        self.make_branch_and_tree('branch')
50
        self.run_bzr('checkout', 'branch', 'checkout')
51
        out, err = self.run_bzr('update', 'checkout')
52
        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.
53
        self.assertEqual('', out)
54
55
    def test_update_out_of_date_standalone_tree(self):
56
        # FIXME the default format has to change for this to pass
57
        # because it currently uses the branch last-revision marker.
58
        raise TestSkipped('default format too old')
59
        self.make_branch_and_tree('branch')
60
        # make a checkout
1587.1.14 by Robert Collins
Make bound branch creation happen via 'checkout'
61
        self.runbzr('checkout --lightweight branch checkout')
1508.1.24 by Robert Collins
Add update command for use with checkouts.
62
        self.build_tree(['checkout/file'])
63
        self.runbzr('add checkout/file')
64
        self.runbzr('commit -m add-file checkout')
65
        # now branch should be out of date
66
        out,err = self.runbzr('update branch')
67
        self.assertEqual('Updated to revision 1.\n', out)
68
        self.assertEqual('', err)
69
        self.failUnlessExists('branch/file')
70
1587.1.14 by Robert Collins
Make bound branch creation happen via 'checkout'
71
    def test_update_out_of_date_light_checkout(self):
1508.1.24 by Robert Collins
Add update command for use with checkouts.
72
        self.make_branch_and_tree('branch')
73
        # make two checkouts
1587.1.14 by Robert Collins
Make bound branch creation happen via 'checkout'
74
        self.runbzr('checkout --lightweight branch checkout')
75
        self.runbzr('checkout --lightweight branch checkout2')
1508.1.24 by Robert Collins
Add update command for use with checkouts.
76
        self.build_tree(['checkout/file'])
77
        self.runbzr('add checkout/file')
78
        self.runbzr('commit -m add-file checkout')
79
        # now checkout2 should be out of date
80
        out,err = self.runbzr('update checkout2')
81
        self.assertEqual('All changes applied successfully.\n'
82
                         'Updated to revision 1.\n',
83
                         err)
84
        self.assertEqual('', out)
85
86
    def test_update_conflicts_returns_2(self):
87
        self.make_branch_and_tree('branch')
88
        # make two checkouts
1587.1.14 by Robert Collins
Make bound branch creation happen via 'checkout'
89
        self.runbzr('checkout --lightweight branch checkout')
1508.1.24 by Robert Collins
Add update command for use with checkouts.
90
        self.build_tree(['checkout/file'])
91
        self.runbzr('add checkout/file')
92
        self.runbzr('commit -m add-file checkout')
1587.1.14 by Robert Collins
Make bound branch creation happen via 'checkout'
93
        self.runbzr('checkout --lightweight branch checkout2')
1508.1.24 by Robert Collins
Add update command for use with checkouts.
94
        # now alter file in checkout
95
        a_file = file('checkout/file', 'wt')
96
        a_file.write('Foo')
97
        a_file.close()
98
        self.runbzr('commit -m checnge-file checkout')
99
        # now checkout2 should be out of date
100
        # make a local change to file
101
        a_file = file('checkout2/file', 'wt')
102
        a_file.write('Bar')
103
        a_file.close()
104
        out,err = self.runbzr('update checkout2', retcode=1)
105
        self.assertEqual(['1 conflicts encountered.',
106
                          'Updated to revision 2.'],
107
                         err.split('\n')[1:3])
1534.7.164 by Aaron Bentley
Updated test to new conflict message
108
        self.assertContainsRe(err, 'Text conflict in file\n')
1508.1.24 by Robert Collins
Add update command for use with checkouts.
109
        self.assertEqual('', out)
1587.1.11 by Robert Collins
Local commits appear to be working properly.
110
111
    def test_smoke_update_checkout_bound_branch_local_commits(self):
112
        # smoke test for doing an update of a checkout of a bound
113
        # branch with local commits.
114
        self.make_branch_and_tree('master')
115
        # make a bound branch
1587.1.14 by Robert Collins
Make bound branch creation happen via 'checkout'
116
        self.run_bzr('checkout', 'master', 'child')
1587.1.11 by Robert Collins
Local commits appear to be working properly.
117
        # check that out
1587.1.14 by Robert Collins
Make bound branch creation happen via 'checkout'
118
        self.run_bzr('checkout', '--lightweight', 'child', 'checkout')
1587.1.11 by Robert Collins
Local commits appear to be working properly.
119
        # change master
120
        a_file = file('master/file', 'wt')
121
        a_file.write('Foo')
122
        a_file.close()
123
        self.run_bzr('add', 'master')
124
        self.run_bzr('commit', '-m', 'add file', 'master')
125
        # change child
126
        a_file = file('child/file_b', 'wt')
127
        a_file.write('Foo')
128
        a_file.close()
129
        self.run_bzr('add', 'child')
130
        self.run_bzr('commit', '--local', '-m', 'add file_b', 'child')
131
        # check checkout
132
        a_file = file('checkout/file_c', 'wt')
133
        a_file.write('Foo')
134
        a_file.close()
135
        self.run_bzr('add', 'checkout')
136
137
        # now, update checkout ->
138
        # get all three files and a pending merge.
139
        self.run_bzr('update', 'checkout')
140
        wt = WorkingTree.open('checkout')
141
        self.assertNotEqual([], wt.pending_merges())
142
        self.failUnlessExists('checkout/file')
143
        self.failUnlessExists('checkout/file_b')
144
        self.failUnlessExists('checkout/file_c')
145
        self.assertTrue(wt.has_filename('file_c'))