1
# Copyright (C) 2005 Canonical Ltd
2
# -*- coding: utf-8 -*-
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 2 of the License, or
8
# (at your option) any later version.
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
"""Black-box tests for bzr missing."""
1
"""Black-box tests for bzr missing.
23
from bzrlib import osutils
25
6
from bzrlib.branch import Branch
26
from bzrlib.tests import TestCaseWithTransport
29
class TestMissing(TestCaseWithTransport):
7
from bzrlib.tests import TestCaseInTempDir
9
class TestMissing(TestCaseInTempDir):
31
10
def test_missing(self):
32
def bzr(*args, **kwargs):
33
return self.run_bzr(*args, **kwargs)[0]
34
11
missing = "You are missing 1 revision(s):"
36
13
# create a source branch
40
17
open('a', 'wb').write('initial\n')
42
bzr('commit -m inital')
19
self.capture('commit -m inital')
44
21
# clone and add a differing revision
22
self.capture('branch . ../b')
47
24
open('a', 'ab').write('more\n')
25
self.capture('commit -m more')
50
# run missing in a against b
52
# this should not require missing to take out a write lock on a
53
# or b. So we take a write lock on both to test that at the same
54
# time. This may let the test pass while the default branch is an
55
# os-locking branch, but it will trigger failures with lockdir based
57
branch_a = Branch.open('.')
59
branch_b = Branch.open('../b')
61
out,err = self.run_bzr('missing ../b', retcode=1)
62
lines = out.splitlines()
29
lines = self.capture('missing ../b', retcode=1).splitlines()
63
30
# we're missing the extra revision here
64
31
self.assertEqual(missing, lines[0])
65
# and we expect 8 lines of output which we trust at the moment to be
67
32
self.assertEqual(8, len(lines))
68
# we do not expect any error output.
69
self.assertEqual('', err)
70
# unlock the branches for the rest of the test
74
34
# get extra revision from b
76
bzr('commit -m merge')
35
self.capture('merge ../b')
36
self.capture('commit -m merge')
78
38
# compare again, but now we have the 'merge' commit extra
79
lines = bzr('missing ../b', retcode=1).splitlines()
39
lines = self.capture('missing ../b', retcode=1).splitlines()
80
40
self.assertEqual("You have 1 extra revision(s):", lines[0])
81
41
self.assertEqual(8, len(lines))
82
lines2 = bzr('missing ../b --mine-only', retcode=1)
42
lines2 = self.capture('missing ../b --mine-only', retcode=1)
83
43
lines2 = lines2.splitlines()
84
44
self.assertEqual(lines, lines2)
85
lines3 = bzr('missing ../b --theirs-only', retcode=1)
45
lines3 = self.capture('missing ../b --theirs-only', retcode=1)
86
46
lines3 = lines3.splitlines()
87
47
self.assertEqual(0, len(lines3))
89
49
# relative to a, missing the 'merge' commit
91
lines = bzr('missing ../a', retcode=1).splitlines()
51
lines = self.capture('missing ../a', retcode=1).splitlines()
92
52
self.assertEqual(missing, lines[0])
93
53
self.assertEqual(8, len(lines))
94
lines2 = bzr('missing ../a --theirs-only', retcode=1)
54
lines2 = self.capture('missing ../a --theirs-only', retcode=1)
95
55
lines2 = lines2.splitlines()
96
56
self.assertEqual(lines, lines2)
97
lines3 = bzr('missing ../a --mine-only', retcode=1)
57
lines3 = self.capture('missing ../a --mine-only', retcode=1)
98
58
lines3 = lines3.splitlines()
99
59
self.assertEqual(0, len(lines3))
100
lines4 = bzr('missing ../a --short', retcode=1)
60
lines4 = self.capture('missing ../a --short', retcode=1)
101
61
lines4 = lines4.splitlines()
102
62
self.assertEqual(4, len(lines4))
103
lines5 = bzr('missing ../a --line', retcode=1)
63
lines5 = self.capture('missing ../a --line', retcode=1)
104
64
lines5 = lines5.splitlines()
105
65
self.assertEqual(2, len(lines5))
106
lines6 = bzr('missing ../a --reverse', retcode=1)
66
lines6 = self.capture('missing ../a --reverse', retcode=1)
107
67
lines6 = lines6.splitlines()
108
68
self.assertEqual(lines6, lines)
109
lines7 = bzr('missing ../a --show-ids', retcode=1)
69
lines7 = self.capture('missing ../a --show-ids', retcode=1)
110
70
lines7 = lines7.splitlines()
111
71
self.assertEqual(11, len(lines7))
112
lines8 = bzr('missing ../a --verbose', retcode=1)
72
lines8 = self.capture('missing ../a --verbose', retcode=1)
113
73
lines8 = lines8.splitlines()
114
74
self.assertEqual("modified:", lines8[-2])
115
75
self.assertEqual(" a", lines8[-1])
117
78
# after a pull we're back on track
119
self.assertEqual("Branches are up to date.\n", bzr('missing ../a'))
121
def test_missing_check_last_location(self):
122
# check that last location shown as filepath not file URL
124
# create a source branch
127
wt = self.make_branch_and_tree('.')
129
self.build_tree(['foo'])
133
location = osutils.getcwd() + '/'
136
b.bzrdir.sprout('../b')
138
# check last location
139
lines, err = self.run_bzr('missing', working_dir='../b')
140
self.assertEquals('Using last location: %s\n'
141
'Branches are up to date.\n' % location,
143
self.assertEquals('', err)
80
self.assertEqual("Branches are up to date.\n",
81
self.capture('missing ../a'))