27
29
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)
51
31
def test_missing(self):
32
def bzr(*args, **kwargs):
33
return self.run_bzr(*args, **kwargs)[0]
52
34
missing = "You are missing 1 revision(s):"
54
36
# create a source branch
55
a_tree = self.make_branch_and_tree('a')
56
self.build_tree_contents([('a/a', 'initial\n')])
58
a_tree.commit(message='initial')
40
open('a', 'wb').write('initial\n')
42
bzr('commit -m inital')
60
44
# clone and add a differing revision
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')
47
open('a', 'ab').write('more\n')
65
50
# run missing in a against b
66
# this should not require missing to take out a write lock on a
52
# this should not require missing to take out a write lock on a
67
53
# or b. So we take a write lock on both to test that at the same
68
54
# time. This may let the test pass while the default branch is an
69
55
# os-locking branch, but it will trigger failures with lockdir based
71
a_branch = a_tree.branch
73
b_branch = b_tree.branch
57
branch_a = Branch.open('.')
59
branch_b = Branch.open('../b')
76
61
out,err = self.run_bzr('missing ../b', retcode=1)
77
62
lines = out.splitlines()
78
63
# we're missing the extra revision here
83
68
# we do not expect any error output.
84
69
self.assertEqual('', err)
85
70
# unlock the branches for the rest of the test
89
74
# get extra revision from b
90
a_tree.merge_from_branch(b_branch)
91
a_tree.commit(message='merge')
76
bzr('commit -m merge')
93
78
# compare again, but now we have the 'merge' commit extra
94
lines = self.run_bzr('missing ../b', retcode=1)[0].splitlines()
79
lines = bzr('missing ../b', retcode=1).splitlines()
95
80
self.assertEqual("You have 1 extra revision(s):", lines[0])
96
81
self.assertEqual(8, len(lines))
97
lines2 = self.run_bzr('missing ../b --mine-only', retcode=1)[0]
82
lines2 = bzr('missing ../b --mine-only', retcode=1)
98
83
lines2 = lines2.splitlines()
99
84
self.assertEqual(lines, lines2)
100
lines3 = self.run_bzr('missing ../b --theirs-only', retcode=0)[0]
101
self.assertEqualDiff('Other branch is up to date.\n', lines3)
85
lines3 = bzr('missing ../b --theirs-only', retcode=1)
86
lines3 = lines3.splitlines()
87
self.assertEqual(0, len(lines3))
103
# relative to a, missing the 'merge' commit
89
# relative to a, missing the 'merge' commit
105
lines = self.run_bzr('missing ../a', retcode=1)[0].splitlines()
91
lines = bzr('missing ../a', retcode=1).splitlines()
106
92
self.assertEqual(missing, lines[0])
107
93
self.assertEqual(8, len(lines))
108
lines2 = self.run_bzr('missing ../a --theirs-only', retcode=1)[0]
94
lines2 = bzr('missing ../a --theirs-only', retcode=1)
109
95
lines2 = lines2.splitlines()
110
96
self.assertEqual(lines, lines2)
111
lines3 = self.run_bzr('missing ../a --mine-only', retcode=0)[0]
112
self.assertEqualDiff('This branch is up to date.\n', lines3)
113
lines4 = self.run_bzr('missing ../a --short', retcode=1)[0]
97
lines3 = bzr('missing ../a --mine-only', retcode=1)
98
lines3 = lines3.splitlines()
99
self.assertEqual(0, len(lines3))
100
lines4 = bzr('missing ../a --short', retcode=1)
114
101
lines4 = lines4.splitlines()
115
102
self.assertEqual(4, len(lines4))
116
lines5 = self.run_bzr('missing ../a --line', retcode=1)[0]
103
lines5 = bzr('missing ../a --line', retcode=1)
117
104
lines5 = lines5.splitlines()
118
105
self.assertEqual(2, len(lines5))
119
lines6 = self.run_bzr('missing ../a --reverse', retcode=1)[0]
106
lines6 = bzr('missing ../a --reverse', retcode=1)
120
107
lines6 = lines6.splitlines()
121
108
self.assertEqual(lines6, lines)
122
lines7 = self.run_bzr('missing ../a --show-ids', retcode=1)[0]
109
lines7 = bzr('missing ../a --show-ids', retcode=1)
123
110
lines7 = lines7.splitlines()
124
111
self.assertEqual(11, len(lines7))
125
lines8 = self.run_bzr('missing ../a --verbose', retcode=1)[0]
112
lines8 = bzr('missing ../a --verbose', retcode=1)
126
113
lines8 = lines8.splitlines()
127
114
self.assertEqual("modified:", lines8[-2])
128
115
self.assertEqual(" a", lines8[-1])
131
self.assertEqualDiff('Other branch is up to date.\n',
132
self.run_bzr('missing ../b --theirs-only')[0])
134
117
# after a pull we're back on track
135
b_tree.pull(a_branch)
136
self.assertEqualDiff("Branches are up to date.\n",
137
self.run_bzr('missing ../b')[0])
139
self.assertEqualDiff('Branches are up to date.\n',
140
self.run_bzr('missing ../a')[0])
141
# If you supply mine or theirs you only know one side is up to date
142
self.assertEqualDiff('This branch is up to date.\n',
143
self.run_bzr('missing ../a --mine-only')[0])
144
self.assertEqualDiff('Other branch is up to date.\n',
145
self.run_bzr('missing ../a --theirs-only')[0])
147
def test_missing_filtered(self):
148
# create a source branch
149
a_tree = self.make_branch_and_tree('a')
150
self.build_tree_contents([('a/a', 'initial\n')])
152
a_tree.commit(message='r1')
153
# clone and add differing revisions
154
b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
156
for i in range(2, 6):
157
a_tree.commit(message='a%d' % i)
158
b_tree.commit(message='b%d' % i)
162
out,err = self.run_bzr('missing ../b --my-revision 3', retcode=1)
163
self.assertMessages(out, ('a3', 'b2', 'b3', 'b4', 'b5'), ('a2', 'a4'))
165
out,err = self.run_bzr('missing ../b --my-revision 3..4', retcode=1)
166
self.assertMessages(out, ('a3', 'a4'), ('a2', 'a5'))
169
out,err = self.run_bzr('missing ../b -r 3', retcode=1)
170
self.assertMessages(out, ('a2', 'a3', 'a4', 'a5', 'b3'), ('b2', 'b4'))
172
out,err = self.run_bzr('missing ../b -r 3..4', retcode=1)
173
self.assertMessages(out, ('b3', 'b4'), ('b2', 'b5'))
176
out,err = self.run_bzr('missing ../b --my-revision 3..4 -r 3..4',
178
self.assertMessages(out, ('a3', 'a4', 'b3', 'b4'),
179
('a2', 'a5', 'b2', 'b5'))
119
self.assertEqual("Branches are up to date.\n", bzr('missing ../a'))
181
121
def test_missing_check_last_location(self):
182
122
# check that last location shown as filepath not file URL
184
124
# create a source branch
185
wt = self.make_branch_and_tree('a')
127
wt = self.make_branch_and_tree('.')
187
self.build_tree(['a/foo'])
129
self.build_tree(['foo'])
189
131
wt.commit('initial')
192
133
location = osutils.getcwd() + '/'