15
13
# You should have received a copy of the GNU General Public License
16
14
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
17
"""Black-box tests for bzr missing."""
21
from bzrlib import osutils
23
23
from bzrlib.branch import Branch
24
from bzrlib.tests import TestCaseInTempDir
27
class TestMissing(TestCaseInTempDir):
24
from bzrlib.tests import TestCaseWithTransport
27
class TestMissing(TestCaseWithTransport):
29
def assertMessages(self, out, must_have=(), must_not_have=()):
30
"""Check if commit messages are in or not in the output"""
32
self.assertContainsRe(out, r'\nmessage:\n %s\n' % m)
33
for m in must_not_have:
34
self.assertNotContainsRe(out, r'\nmessage:\n %s\n' % m)
36
def test_missing_quiet(self):
37
# <https://bugs.launchpad.net/bzr/+bug/284748>
38
# create a source branch
40
# XXX: This still needs a test that missing is quiet when there are
42
a_tree = self.make_branch_and_tree('.')
43
self.build_tree_contents([('a', 'initial\n')])
45
a_tree.commit(message='initial')
47
out, err = self.run_bzr('missing -q .')
48
self.assertEqual('', out)
49
self.assertEqual('', err)
29
51
def test_missing(self):
30
def bzr(*args, **kwargs):
31
return self.run_bzr(*args, **kwargs)[0]
32
missing = "You are missing 1 revision(s):"
52
missing = "You are missing 1 revision:"
34
54
# create a source branch
38
open('a', 'wb').write('initial\n')
40
bzr('commit', '-m', 'inital')
55
a_tree = self.make_branch_and_tree('a')
56
self.build_tree_contents([('a/a', 'initial\n')])
58
a_tree.commit(message='initial')
42
60
# clone and add a differing revision
43
bzr('branch', '.', '../b')
45
open('a', 'ab').write('more\n')
46
bzr('commit', '-m', 'more')
61
b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
62
self.build_tree_contents([('b/a', 'initial\nmore\n')])
63
b_tree.commit(message='more')
48
65
# run missing in a against b
50
# this should not require missing to take out a write lock on a
66
# this should not require missing to take out a write lock on a
51
67
# or b. So we take a write lock on both to test that at the same
52
68
# time. This may let the test pass while the default branch is an
53
69
# os-locking branch, but it will trigger failures with lockdir based
55
branch_a = Branch.open('.')
57
branch_b = Branch.open('../b')
59
out,err = self.run_bzr('missing', '../b', retcode=1)
71
a_branch = a_tree.branch
73
b_branch = b_tree.branch
76
out,err = self.run_bzr('missing ../b', retcode=1)
60
77
lines = out.splitlines()
61
78
# we're missing the extra revision here
62
79
self.assertEqual(missing, lines[0])
66
83
# we do not expect any error output.
67
84
self.assertEqual('', err)
68
85
# unlock the branches for the rest of the test
72
89
# get extra revision from b
74
bzr('commit', '-m', 'merge')
90
a_tree.merge_from_branch(b_branch)
91
a_tree.commit(message='merge')
76
93
# compare again, but now we have the 'merge' commit extra
77
lines = bzr('missing', '../b', retcode=1).splitlines()
78
self.assertEqual("You have 1 extra revision(s):", lines[0])
94
lines = self.run_bzr('missing ../b', retcode=1)[0].splitlines()
95
self.assertEqual("You have 1 extra revision:", lines[0])
79
96
self.assertEqual(8, len(lines))
80
lines2 = bzr('missing', '../b', '--mine-only', retcode=1)
97
lines2 = self.run_bzr('missing ../b --mine-only', retcode=1)[0]
81
98
lines2 = lines2.splitlines()
82
99
self.assertEqual(lines, lines2)
83
lines3 = bzr('missing', '../b', '--theirs-only', retcode=1)
84
lines3 = lines3.splitlines()
85
self.assertEqual(0, len(lines3))
100
lines3 = self.run_bzr('missing ../b --theirs-only', retcode=0)[0]
101
self.assertEqualDiff('Other branch has no new revisions.\n', lines3)
87
# relative to a, missing the 'merge' commit
103
# relative to a, missing the 'merge' commit
89
lines = bzr('missing', '../a', retcode=1).splitlines()
105
lines = self.run_bzr('missing ../a', retcode=1)[0].splitlines()
90
106
self.assertEqual(missing, lines[0])
91
107
self.assertEqual(8, len(lines))
92
lines2 = bzr('missing', '../a', '--theirs-only', retcode=1)
108
lines2 = self.run_bzr('missing ../a --theirs-only', retcode=1)[0]
93
109
lines2 = lines2.splitlines()
94
110
self.assertEqual(lines, lines2)
95
lines3 = bzr('missing', '../a', '--mine-only', retcode=1)
96
lines3 = lines3.splitlines()
97
self.assertEqual(0, len(lines3))
98
lines4 = bzr('missing', '../a', '--short', retcode=1)
111
lines3 = self.run_bzr('missing ../a --mine-only', retcode=0)[0]
112
self.assertEqualDiff('This branch has no new revisions.\n', lines3)
113
lines4 = self.run_bzr('missing ../a --short', retcode=1)[0]
99
114
lines4 = lines4.splitlines()
100
115
self.assertEqual(4, len(lines4))
101
lines5 = bzr('missing', '../a', '--line', retcode=1)
116
lines4a = self.run_bzr('missing ../a -S', retcode=1)[0]
117
lines4a = lines4a.splitlines()
118
self.assertEqual(lines4, lines4a)
119
lines5 = self.run_bzr('missing ../a --line', retcode=1)[0]
102
120
lines5 = lines5.splitlines()
103
121
self.assertEqual(2, len(lines5))
104
lines6 = bzr('missing', '../a', '--reverse', retcode=1)
122
lines6 = self.run_bzr('missing ../a --reverse', retcode=1)[0]
105
123
lines6 = lines6.splitlines()
106
124
self.assertEqual(lines6, lines)
107
lines7 = bzr('missing', '../a', '--show-ids', retcode=1)
125
lines7 = self.run_bzr('missing ../a --show-ids', retcode=1)[0]
108
126
lines7 = lines7.splitlines()
109
127
self.assertEqual(11, len(lines7))
110
lines8 = bzr('missing', '../a', '--verbose', retcode=1)
128
lines8 = self.run_bzr('missing ../a --verbose', retcode=1)[0]
111
129
lines8 = lines8.splitlines()
112
130
self.assertEqual("modified:", lines8[-2])
113
131
self.assertEqual(" a", lines8[-1])
134
self.assertEqualDiff('Other branch has no new revisions.\n',
135
self.run_bzr('missing ../b --theirs-only')[0])
116
137
# after a pull we're back on track
118
self.assertEqual("Branches are up to date.\n",
119
bzr('missing', '../a'))
138
b_tree.pull(a_branch)
139
self.assertEqualDiff("Branches are up to date.\n",
140
self.run_bzr('missing ../b')[0])
142
self.assertEqualDiff('Branches are up to date.\n',
143
self.run_bzr('missing ../a')[0])
144
# If you supply mine or theirs you only know one side is up to date
145
self.assertEqualDiff('This branch has no new revisions.\n',
146
self.run_bzr('missing ../a --mine-only')[0])
147
self.assertEqualDiff('Other branch has no new revisions.\n',
148
self.run_bzr('missing ../a --theirs-only')[0])
150
def test_missing_filtered(self):
151
# create a source branch
152
a_tree = self.make_branch_and_tree('a')
153
self.build_tree_contents([('a/a', 'initial\n')])
155
a_tree.commit(message='r1')
156
# clone and add differing revisions
157
b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
159
for i in range(2, 6):
160
a_tree.commit(message='a%d' % i)
161
b_tree.commit(message='b%d' % i)
165
out,err = self.run_bzr('missing ../b --my-revision 3', retcode=1)
166
self.assertMessages(out, ('a3', 'b2', 'b3', 'b4', 'b5'), ('a2', 'a4'))
168
out,err = self.run_bzr('missing ../b --my-revision 3..4', retcode=1)
169
self.assertMessages(out, ('a3', 'a4'), ('a2', 'a5'))
172
out,err = self.run_bzr('missing ../b -r 3', retcode=1)
173
self.assertMessages(out, ('a2', 'a3', 'a4', 'a5', 'b3'), ('b2', 'b4'))
175
out,err = self.run_bzr('missing ../b -r 3..4', retcode=1)
176
self.assertMessages(out, ('b3', 'b4'), ('b2', 'b5'))
179
out,err = self.run_bzr('missing ../b --my-revision 3..4 -r 3..4',
181
self.assertMessages(out, ('a3', 'a4', 'b3', 'b4'),
182
('a2', 'a5', 'b2', 'b5'))
184
def test_missing_check_last_location(self):
185
# check that last location shown as filepath not file URL
187
# create a source branch
188
wt = self.make_branch_and_tree('a')
190
self.build_tree(['a/foo'])
195
location = osutils.getcwd() + '/'
198
b.bzrdir.sprout('../b')
200
# check last location
201
lines, err = self.run_bzr('missing', working_dir='../b')
202
self.assertEquals('Using saved parent location: %s\n'
203
'Branches are up to date.\n' % location,
205
self.assertEquals('', err)
207
def test_missing_directory(self):
208
"""Test --directory option"""
210
# create a source branch
211
a_tree = self.make_branch_and_tree('a')
212
self.build_tree_contents([('a/a', 'initial\n')])
214
a_tree.commit(message='initial')
216
# clone and add a differing revision
217
b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
218
self.build_tree_contents([('b/a', 'initial\nmore\n')])
219
b_tree.commit(message='more')
221
out2, err2 = self.run_bzr('missing --directory a b', retcode=1)
223
out1, err1 = self.run_bzr('missing ../b', retcode=1)
224
self.assertEqualDiff(out1, out2)
225
self.assertEqualDiff(err1, err2)