~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Martin Pool
  • Date: 2005-05-10 06:07:16 UTC
  • Revision ID: mbp@sourcefrog.net-20050510060716-0f939ce3ddea5d15
- New command update-stat-cache for testing
- work-cache always stored with unix newlines and in ascii

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2008 Canonical Ltd
2
 
#
3
 
# This program is free software; you can redistribute it and/or modify
4
 
# it under the terms of the GNU General Public License as published by
5
 
# the Free Software Foundation; either version 2 of the License, or
6
 
# (at your option) any later version.
7
 
#
8
 
# This program is distributed in the hope that it will be useful,
9
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 
# GNU General Public License for more details.
12
 
#
13
 
# You should have received a copy of the GNU General Public License
14
 
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
 
 
17
 
"""Black-box tests for bzr missing."""
18
 
 
19
 
import os
20
 
 
21
 
from bzrlib import osutils
22
 
 
23
 
from bzrlib.branch import Branch
24
 
from bzrlib.tests import TestCaseWithTransport
25
 
 
26
 
 
27
 
class TestMissing(TestCaseWithTransport):
28
 
 
29
 
    def test_missing_quiet(self):
30
 
        # <https://bugs.launchpad.net/bzr/+bug/284748>
31
 
        # create a source branch
32
 
        #
33
 
        # XXX: This still needs a test that missing is quiet when there are
34
 
        # missing revisions.
35
 
        a_tree = self.make_branch_and_tree('.')
36
 
        self.build_tree_contents([('a', 'initial\n')])
37
 
        a_tree.add('a')
38
 
        a_tree.commit(message='initial')
39
 
 
40
 
        out, err = self.run_bzr('missing -q .')
41
 
        self.assertEqual('', out)
42
 
        self.assertEqual('', err)
43
 
 
44
 
    def test_missing(self):
45
 
        missing = "You are missing 1 revision(s):"
46
 
 
47
 
        # create a source branch
48
 
        a_tree = self.make_branch_and_tree('a')
49
 
        self.build_tree_contents([('a/a', 'initial\n')])
50
 
        a_tree.add('a')
51
 
        a_tree.commit(message='initial')
52
 
 
53
 
        # clone and add a differing revision
54
 
        b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
55
 
        self.build_tree_contents([('b/a', 'initial\nmore\n')])
56
 
        b_tree.commit(message='more')
57
 
 
58
 
        # run missing in a against b
59
 
        # this should not require missing to take out a write lock on a 
60
 
        # or b. So we take a write lock on both to test that at the same
61
 
        # time. This may let the test pass while the default branch is an
62
 
        # os-locking branch, but it will trigger failures with lockdir based
63
 
        # branches.
64
 
        a_branch = a_tree.branch
65
 
        a_branch.lock_write()
66
 
        b_branch = b_tree.branch
67
 
        b_branch.lock_write()
68
 
        os.chdir('a')
69
 
        out,err = self.run_bzr('missing ../b', retcode=1)
70
 
        lines = out.splitlines()
71
 
        # we're missing the extra revision here
72
 
        self.assertEqual(missing, lines[0])
73
 
        # and we expect 8 lines of output which we trust at the moment to be
74
 
        # good.
75
 
        self.assertEqual(8, len(lines))
76
 
        # we do not expect any error output.
77
 
        self.assertEqual('', err)
78
 
        # unlock the branches for the rest of the test
79
 
        a_branch.unlock()
80
 
        b_branch.unlock()
81
 
 
82
 
        # get extra revision from b
83
 
        a_tree.merge_from_branch(b_branch)
84
 
        a_tree.commit(message='merge')
85
 
 
86
 
        # compare again, but now we have the 'merge' commit extra
87
 
        lines = self.run_bzr('missing ../b', retcode=1)[0].splitlines()
88
 
        self.assertEqual("You have 1 extra revision(s):", lines[0])
89
 
        self.assertEqual(8, len(lines))
90
 
        lines2 = self.run_bzr('missing ../b --mine-only', retcode=1)[0]
91
 
        lines2 = lines2.splitlines()
92
 
        self.assertEqual(lines, lines2)
93
 
        lines3 = self.run_bzr('missing ../b --theirs-only', retcode=0)[0]
94
 
        self.assertEqualDiff('Other branch is up to date.\n', lines3)
95
 
 
96
 
        # relative to a, missing the 'merge' commit 
97
 
        os.chdir('../b')
98
 
        lines = self.run_bzr('missing ../a', retcode=1)[0].splitlines()
99
 
        self.assertEqual(missing, lines[0])
100
 
        self.assertEqual(8, len(lines))
101
 
        lines2 = self.run_bzr('missing ../a --theirs-only', retcode=1)[0]
102
 
        lines2 = lines2.splitlines()
103
 
        self.assertEqual(lines, lines2)
104
 
        lines3 = self.run_bzr('missing ../a --mine-only', retcode=0)[0]
105
 
        self.assertEqualDiff('This branch is up to date.\n', lines3)
106
 
        lines4 = self.run_bzr('missing ../a --short', retcode=1)[0]
107
 
        lines4 = lines4.splitlines()
108
 
        self.assertEqual(4, len(lines4))
109
 
        lines5 = self.run_bzr('missing ../a --line', retcode=1)[0]
110
 
        lines5 = lines5.splitlines()
111
 
        self.assertEqual(2, len(lines5))
112
 
        lines6 = self.run_bzr('missing ../a --reverse', retcode=1)[0]
113
 
        lines6 = lines6.splitlines()
114
 
        self.assertEqual(lines6, lines)
115
 
        lines7 = self.run_bzr('missing ../a --show-ids', retcode=1)[0]
116
 
        lines7 = lines7.splitlines()
117
 
        self.assertEqual(11, len(lines7))
118
 
        lines8 = self.run_bzr('missing ../a --verbose', retcode=1)[0]
119
 
        lines8 = lines8.splitlines()
120
 
        self.assertEqual("modified:", lines8[-2])
121
 
        self.assertEqual("  a", lines8[-1])
122
 
 
123
 
        os.chdir('../a')
124
 
        self.assertEqualDiff('Other branch is up to date.\n',
125
 
                             self.run_bzr('missing ../b --theirs-only')[0])
126
 
 
127
 
        # after a pull we're back on track
128
 
        b_tree.pull(a_branch)
129
 
        self.assertEqualDiff("Branches are up to date.\n",
130
 
                             self.run_bzr('missing ../b')[0])
131
 
        os.chdir('../b')
132
 
        self.assertEqualDiff('Branches are up to date.\n',
133
 
                             self.run_bzr('missing ../a')[0])
134
 
        # If you supply mine or theirs you only know one side is up to date
135
 
        self.assertEqualDiff('This branch is up to date.\n',
136
 
                             self.run_bzr('missing ../a --mine-only')[0])
137
 
        self.assertEqualDiff('Other branch is up to date.\n',
138
 
                             self.run_bzr('missing ../a --theirs-only')[0])
139
 
 
140
 
    def test_missing_check_last_location(self):
141
 
        # check that last location shown as filepath not file URL
142
 
 
143
 
        # create a source branch
144
 
        wt = self.make_branch_and_tree('a')
145
 
        b = wt.branch
146
 
        self.build_tree(['a/foo'])
147
 
        wt.add('foo')
148
 
        wt.commit('initial')
149
 
 
150
 
        os.chdir('a')
151
 
        location = osutils.getcwd() + '/'
152
 
 
153
 
        # clone
154
 
        b.bzrdir.sprout('../b')
155
 
 
156
 
        # check last location
157
 
        lines, err = self.run_bzr('missing', working_dir='../b')
158
 
        self.assertEquals('Using saved parent location: %s\n'
159
 
                          'Branches are up to date.\n' % location,
160
 
                          lines)
161
 
        self.assertEquals('', err)