13
15
# You should have received a copy of the GNU General Public License
14
16
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
19
"""Black-box tests for bzr missing."""
25
class TestMissing(tests.TestCaseWithTransport):
27
def assertMessages(self, out, must_have=(), must_not_have=()):
28
"""Check if commit messages are in or not in the output"""
30
self.assertContainsRe(out, r'\nmessage:\n %s\n' % m)
31
for m in must_not_have:
32
self.assertNotContainsRe(out, r'\nmessage:\n %s\n' % m)
34
def test_missing_quiet(self):
35
# <https://bugs.launchpad.net/bzr/+bug/284748>
36
# create a source branch
38
# XXX: This still needs a test that missing is quiet when there are
40
a_tree = self.make_branch_and_tree('.')
41
self.build_tree_contents([('a', 'initial\n')])
43
a_tree.commit(message='initial')
45
out, err = self.run_bzr('missing -q .')
46
self.assertEqual('', out)
47
self.assertEqual('', err)
23
from bzrlib import osutils
25
from bzrlib.branch import Branch
26
from bzrlib.tests import TestCaseWithTransport
29
class TestMissing(TestCaseWithTransport):
49
31
def test_missing(self):
50
missing_one = "You are missing 1 revision:"
51
extra_one = "You have 1 extra revision:"
32
missing = "You are missing 1 revision(s):"
53
34
# create a source branch
54
35
a_tree = self.make_branch_and_tree('a')
102
71
a_tree.commit(message='merge')
104
73
# compare again, but now we have the 'merge' commit extra
105
lines = run_missing_b([])
106
self.assertEqual(extra_one, lines[0])
107
self.assertLength(8, lines)
109
lines2 = run_missing_b(['--mine-only'])
110
self.assertEqual(lines, lines2)
112
lines3 = run_missing_b(['--theirs-only'], retcode=0)
113
self.assertEqualDiff('Other branch has no new revisions.', lines3[0])
115
# relative to a, missing the 'merge' commit
116
lines = run_missing_a([])
117
self.assertEqual(missing_one, lines[0])
118
self.assertLength(8, lines)
120
lines2 = run_missing_a(['--theirs-only'])
121
self.assertEqual(lines, lines2)
123
lines3 = run_missing_a(['--mine-only'], retcode=0)
124
self.assertEqualDiff('This branch has no new revisions.', lines3[0])
126
lines4 = run_missing_a(['--short'])
127
self.assertLength(4, lines4)
129
lines4a = run_missing_a(['-S'])
130
self.assertEqual(lines4, lines4a)
132
lines5 = run_missing_a(['--line'])
133
self.assertLength(2, lines5)
135
lines6 = run_missing_a(['--reverse'])
74
lines = self.run_bzr('missing ../b', retcode=1)[0].splitlines()
75
self.assertEqual("You have 1 extra revision(s):", lines[0])
76
self.assertEqual(8, len(lines))
77
lines2 = self.run_bzr('missing ../b --mine-only', retcode=1)[0]
78
lines2 = lines2.splitlines()
79
self.assertEqual(lines, lines2)
80
lines3 = self.run_bzr('missing ../b --theirs-only', retcode=0)[0]
81
self.assertEqualDiff('Other branch is up to date.\n', lines3)
83
# relative to a, missing the 'merge' commit
85
lines = self.run_bzr('missing ../a', retcode=1)[0].splitlines()
86
self.assertEqual(missing, lines[0])
87
self.assertEqual(8, len(lines))
88
lines2 = self.run_bzr('missing ../a --theirs-only', retcode=1)[0]
89
lines2 = lines2.splitlines()
90
self.assertEqual(lines, lines2)
91
lines3 = self.run_bzr('missing ../a --mine-only', retcode=0)[0]
92
self.assertEqualDiff('This branch is up to date.\n', lines3)
93
lines4 = self.run_bzr('missing ../a --short', retcode=1)[0]
94
lines4 = lines4.splitlines()
95
self.assertEqual(4, len(lines4))
96
lines5 = self.run_bzr('missing ../a --line', retcode=1)[0]
97
lines5 = lines5.splitlines()
98
self.assertEqual(2, len(lines5))
99
lines6 = self.run_bzr('missing ../a --reverse', retcode=1)[0]
100
lines6 = lines6.splitlines()
136
101
self.assertEqual(lines6, lines)
138
lines7 = run_missing_a(['--show-ids'])
139
self.assertLength(11, lines7)
141
lines8 = run_missing_a(['--verbose'])
102
lines7 = self.run_bzr('missing ../a --show-ids', retcode=1)[0]
103
lines7 = lines7.splitlines()
104
self.assertEqual(11, len(lines7))
105
lines8 = self.run_bzr('missing ../a --verbose', retcode=1)[0]
106
lines8 = lines8.splitlines()
142
107
self.assertEqual("modified:", lines8[-2])
143
108
self.assertEqual(" a", lines8[-1])
145
self.assertEqualDiff('Other branch has no new revisions.',
146
run_missing_b(['--theirs-only'], retcode=0)[0])
111
self.assertEqualDiff('Other branch is up to date.\n',
112
self.run_bzr('missing ../b --theirs-only')[0])
148
114
# after a pull we're back on track
149
115
b_tree.pull(a_branch)
150
self.assertEqualDiff("Branches are up to date.",
151
run_missing_b([], retcode=0)[0])
152
self.assertEqualDiff('Branches are up to date.',
153
run_missing_a([], retcode=0)[0])
116
self.assertEqualDiff("Branches are up to date.\n",
117
self.run_bzr('missing ../b')[0])
119
self.assertEqualDiff('Branches are up to date.\n',
120
self.run_bzr('missing ../a')[0])
154
121
# If you supply mine or theirs you only know one side is up to date
155
self.assertEqualDiff('This branch has no new revisions.',
156
run_missing_a(['--mine-only'], retcode=0)[0])
157
self.assertEqualDiff('Other branch has no new revisions.',
158
run_missing_a(['--theirs-only'], retcode=0)[0])
160
def test_missing_filtered(self):
161
# create a source branch
162
a_tree = self.make_branch_and_tree('a')
163
self.build_tree_contents([('a/a', 'initial\n')])
165
a_tree.commit(message='r1')
166
# clone and add differing revisions
167
b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
169
for i in range(2, 6):
170
a_tree.commit(message='a%d' % i)
171
b_tree.commit(message='b%d' % i)
174
out,err = self.run_bzr('missing ../b --my-revision 3',
175
retcode=1, working_dir='a')
176
self.assertMessages(out, ('a3', 'b2', 'b3', 'b4', 'b5'), ('a2', 'a4'))
178
out,err = self.run_bzr('missing ../b --my-revision 3..4',
179
retcode=1, working_dir='a')
180
self.assertMessages(out, ('a3', 'a4'), ('a2', 'a5'))
183
out,err = self.run_bzr('missing ../b -r 3',
184
retcode=1, working_dir='a')
185
self.assertMessages(out, ('a2', 'a3', 'a4', 'a5', 'b3'), ('b2', 'b4'))
187
out,err = self.run_bzr('missing ../b -r 3..4',
188
retcode=1, working_dir='a')
189
self.assertMessages(out, ('b3', 'b4'), ('b2', 'b5'))
192
out,err = self.run_bzr('missing ../b --my-revision 3..4 -r 3..4',
193
retcode=1, working_dir='a')
194
self.assertMessages(out, ('a3', 'a4', 'b3', 'b4'),
195
('a2', 'a5', 'b2', 'b5'))
122
self.assertEqualDiff('This branch is up to date.\n',
123
self.run_bzr('missing ../a --mine-only')[0])
124
self.assertEqualDiff('Other branch is up to date.\n',
125
self.run_bzr('missing ../a --theirs-only')[0])
197
127
def test_missing_check_last_location(self):
198
128
# check that last location shown as filepath not file URL
205
135
wt.commit('initial')
207
location = osutils.getcwd() + '/a/'
138
location = osutils.getcwd() + '/'
141
b.bzrdir.sprout('../b')
212
143
# check last location
213
lines, err = self.run_bzr('missing', working_dir='b')
214
self.assertEqual('Using saved parent location: %s\n'
215
'Branches are up to date.\n' % location,
217
self.assertEqual('', err)
219
def test_missing_directory(self):
220
"""Test --directory option"""
222
# create a source branch
223
a_tree = self.make_branch_and_tree('a')
224
self.build_tree_contents([('a/a', 'initial\n')])
226
a_tree.commit(message='initial')
228
# clone and add a differing revision
229
b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
230
self.build_tree_contents([('b/a', 'initial\nmore\n')])
231
b_tree.commit(message='more')
233
out2, err2 = self.run_bzr('missing --directory a b', retcode=1)
234
out1, err1 = self.run_bzr('missing ../b', retcode=1, working_dir='a')
235
self.assertEqualDiff(out1, out2)
236
self.assertEqualDiff(err1, err2)
238
def test_missing_tags(self):
239
"""Test showing tags"""
241
# create a source branch
242
a_tree = self.make_branch_and_tree('a')
243
self.build_tree_contents([('a/a', 'initial\n')])
245
a_tree.commit(message='initial')
247
# clone and add a differing revision
248
b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
249
self.build_tree_contents([('b/a', 'initial\nmore\n')])
250
b_tree.commit(message='more')
251
b_tree.branch.tags.set_tag('a-tag', b_tree.last_revision())
253
for log_format in ['long', 'short', 'line']:
254
out, err = self.run_bzr(
255
'missing --log-format={0} ../a'.format(log_format),
256
working_dir='b', retcode=1)
257
self.assertContainsString(out, 'a-tag')
259
out, err = self.run_bzr(
260
'missing --log-format={0} ../b'.format(log_format),
261
working_dir='a', retcode=1)
262
self.assertContainsString(out, 'a-tag')
144
lines, err = self.run_bzr('missing', working_dir='../b')
145
self.assertEquals('Using saved parent location: %s\n'
146
'Branches are up to date.\n' % location,
148
self.assertEquals('', err)