45
41
class BranchStatus(TestCaseWithTransport):
47
def assertStatus(self, expected_lines, working_tree,
48
revision=None, short=False):
49
"""Run status in working_tree and look for output.
51
:param expected_lines: The lines to look for.
52
:param working_tree: The tree to run status in.
54
output_string = self.status_string(working_tree, revision, short)
55
self.assertEqual(expected_lines, output_string.splitlines(True))
57
def status_string(self, wt, revision=None, short=False):
58
# use a real file rather than StringIO because it doesn't handle
60
tof = codecs.getwriter('utf-8')(TemporaryFile())
61
show_tree_status(wt, to_file=tof, revision=revision, short=short)
63
return tof.read().decode('utf-8')
65
43
def test_branch_status(self):
66
44
"""Test basic branch status"""
67
45
wt = self.make_branch_and_tree('.')
69
# status with no commits or files - it must
70
# work and show no output. We do this with no
71
# commits to be sure that it's not going to fail
73
self.assertStatus([], wt)
48
ignores._set_user_ignores(['./.bazaar'])
52
show_tree_status(wt, to_file=tof)
53
self.assertEquals(tof.getvalue(), "")
75
56
self.build_tree(['hello.c', 'bye.c'])
88
# add a commit to allow showing pending merges.
89
wt.commit('create a parent to allow testing merge output')
91
wt.add_parent_tree_id('pending@pending-0-0')
97
' pending@pending-0-0\n',
103
'P pending@pending-0-0\n',
57
wt.add_pending_merge('pending@pending-0-0')
58
show_tree_status(wt, to_file=tof)
60
self.assertEquals(tof.readlines(),
65
' pending@pending-0-0\n'
107
68
def test_branch_status_revisions(self):
108
69
"""Tests branch status with revisions"""
109
70
wt = self.make_branch_and_tree('.')
73
ignores._set_user_ignores(['./.bazaar'])
111
76
self.build_tree(['hello.c', 'bye.c'])
114
79
wt.commit('Test message')
116
revs = [RevisionSpec.from_string('0')]
83
revs.append(RevisionSpec(0))
85
show_tree_status(wt, to_file=tof, revision=revs)
88
self.assertEquals(tof.readlines(),
125
93
self.build_tree(['more.c'])
127
95
wt.commit('Another test message')
129
revs.append(RevisionSpec.from_string('1'))
98
revs.append(RevisionSpec(1))
100
show_tree_status(wt, to_file=tof, revision=revs)
103
self.assertEquals(tof.readlines(),
108
def status_string(self, wt):
109
# use a real file rather than StringIO because it doesn't handle
111
tof = codecs.getwriter('utf-8')(TemporaryFile())
112
show_tree_status(wt, to_file=tof)
114
return tof.read().decode('utf-8')
138
116
def test_pending(self):
139
117
"""Pending merges display works, including Unicode"""
147
125
wt.commit(u"\N{TIBETAN DIGIT TWO} Empty commit 2")
148
126
merge(["./branch", -1], [None, None], this_dir = './copy')
149
127
message = self.status_string(wt2)
150
self.assertStartsWith(message, "pending merges:\n")
151
self.assertEndsWith(message, "Empty commit 2\n")
128
self.assert_(message.startswith("pending merges:\n"))
129
self.assert_(message.endswith("Empty commit 2\n"))
152
130
wt2.commit("merged")
153
131
# must be long to make sure we see elipsis at the end
154
wt.commit("Empty commit 3 " +
155
"blah blah blah blah " * 100)
132
wt.commit("Empty commit 3 " +
133
"blah blah blah blah " * 10)
156
134
merge(["./branch", -1], [None, None], this_dir = './copy')
157
135
message = self.status_string(wt2)
158
self.assertStartsWith(message, "pending merges:\n")
136
self.assert_(message.startswith("pending merges:\n"))
159
137
self.assert_("Empty commit 3" in message)
160
self.assertEndsWith(message, "...\n")
162
def test_tree_status_ignores(self):
163
"""Tests branch status with ignores"""
164
wt = self.make_branch_and_tree('.')
165
self.run_bzr('ignore *~')
166
wt.commit('commit .bzrignore')
167
self.build_tree(['foo.c', 'foo.c~'])
178
def test_tree_status_specific_files(self):
138
self.assert_(message.endswith("...\n"))
140
def test_branch_status_specific_files(self):
179
141
"""Tests branch status with given specific files"""
180
142
wt = self.make_branch_and_tree('.')
145
ignores._set_user_ignores(['./.bazaar'])
183
147
self.build_tree(['directory/','directory/hello.c', 'bye.c','test.c','dir2/'])
184
148
wt.add('directory')
186
150
wt.commit('testing')
192
' directory/hello.c\n'
199
'? directory/hello.c\n'
153
show_tree_status(wt, to_file=tof)
155
self.assertEquals(tof.readlines(),
159
' directory/hello.c\n'
204
162
self.assertRaises(errors.PathsDoNotExist,
205
163
show_tree_status,
206
164
wt, specific_files=['bye.c','test.c','absent.c'],
214
172
' directory/hello.c\n'
217
show_tree_status(wt, specific_files=['directory'], to_file=tof,
220
self.assertEquals(tof.readlines(), ['? directory/hello.c\n'])
223
175
show_tree_status(wt, specific_files=['dir2'], to_file=tof)
225
177
self.assertEquals(tof.readlines(),
230
show_tree_status(wt, specific_files=['dir2'], to_file=tof, short=True)
232
self.assertEquals(tof.readlines(), ['? dir2/\n'])
234
def test_specific_files_conflicts(self):
235
tree = self.make_branch_and_tree('.')
236
self.build_tree(['dir2/'])
238
tree.commit('added dir2')
239
tree.set_conflicts(conflicts.ConflictList(
240
[conflicts.ContentsConflict('foo')]))
242
show_tree_status(tree, specific_files=['dir2'], to_file=tof)
243
self.assertEqualDiff('', tof.getvalue())
244
tree.set_conflicts(conflicts.ConflictList(
245
[conflicts.ContentsConflict('dir2')]))
247
show_tree_status(tree, specific_files=['dir2'], to_file=tof)
248
self.assertEqualDiff('conflicts:\n Contents conflict in dir2\n',
251
tree.set_conflicts(conflicts.ConflictList(
252
[conflicts.ContentsConflict('dir2/file1')]))
254
show_tree_status(tree, specific_files=['dir2'], to_file=tof)
255
self.assertEqualDiff('conflicts:\n Contents conflict in dir2/file1\n',
258
182
def test_status_nonexistent_file(self):
259
183
# files that don't exist in either the basis tree or working tree
260
184
# should give an error
261
185
wt = self.make_branch_and_tree('.')
262
out, err = self.run_bzr('status does-not-exist', retcode=3)
186
out, err = self.run_bzr('status', 'does-not-exist', retcode=3)
263
187
self.assertContainsRe(err, r'do not exist.*does-not-exist')
265
def test_status_out_of_date(self):
266
"""Simulate status of out-of-date tree after remote push"""
267
tree = self.make_branch_and_tree('.')
268
self.build_tree_contents([('a', 'foo\n')])
272
tree.commit('add test file')
273
# simulate what happens after a remote push
274
tree.set_last_revision("0")
276
# before run another commands we should unlock tree
278
out, err = self.run_bzr('status')
279
self.assertEqual("working tree is out of date, run 'bzr update'\n",
283
190
class CheckoutStatus(BranchStatus):
297
204
class TestStatus(TestCaseWithTransport):
299
def test_status_plain(self):
302
self.build_tree(['hello.txt'])
303
result = self.run_bzr("status")[0]
304
self.assertContainsRe(result, "unknown:\n hello.txt\n")
306
self.run_bzr("add hello.txt")
307
result = self.run_bzr("status")[0]
308
self.assertContainsRe(result, "added:\n hello.txt\n")
310
self.run_bzr("commit -m added")
311
result = self.run_bzr("status -r 0..1")[0]
312
self.assertContainsRe(result, "added:\n hello.txt\n")
314
self.build_tree(['world.txt'])
315
result = self.run_bzr("status -r 0")[0]
316
self.assertContainsRe(result, "added:\n hello.txt\n" \
317
"unknown:\n world.txt\n")
318
result2 = self.run_bzr("status -r 0..")[0]
319
self.assertEquals(result2, result)
321
def test_status_short(self):
324
self.build_tree(['hello.txt'])
325
result = self.run_bzr("status --short")[0]
326
self.assertContainsRe(result, "[?] hello.txt\n")
328
self.run_bzr("add hello.txt")
329
result = self.run_bzr("status --short")[0]
330
self.assertContainsRe(result, "[+]N hello.txt\n")
332
self.run_bzr("commit -m added")
333
result = self.run_bzr("status --short -r 0..1")[0]
334
self.assertContainsRe(result, "[+]N hello.txt\n")
336
self.build_tree(['world.txt'])
337
result = self.run_bzr("status --short -r 0")[0]
338
self.assertContainsRe(result, "[+]N hello.txt\n" \
340
result2 = self.run_bzr("status --short -r 0..")[0]
341
self.assertEquals(result2, result)
343
def test_status_versioned(self):
346
self.build_tree(['hello.txt'])
347
result = self.run_bzr("status --versioned")[0]
348
self.assertNotContainsRe(result, "unknown:\n hello.txt\n")
350
self.run_bzr("add hello.txt")
351
result = self.run_bzr("status --versioned")[0]
352
self.assertContainsRe(result, "added:\n hello.txt\n")
354
self.run_bzr("commit -m added")
355
result = self.run_bzr("status --versioned -r 0..1")[0]
356
self.assertContainsRe(result, "added:\n hello.txt\n")
358
self.build_tree(['world.txt'])
359
result = self.run_bzr("status --versioned -r 0")[0]
360
self.assertContainsRe(result, "added:\n hello.txt\n")
361
self.assertNotContainsRe(result, "unknown:\n world.txt\n")
362
result2 = self.run_bzr("status --versioned -r 0..")[0]
363
self.assertEquals(result2, result)
365
def assertStatusContains(self, pattern):
366
"""Run status, and assert it contains the given pattern"""
367
result = self.run_bzr("status --short")[0]
368
self.assertContainsRe(result, pattern)
370
def test_kind_change_short(self):
371
tree = self.make_branch_and_tree('.')
372
self.build_tree(['file'])
374
tree.commit('added file')
376
self.build_tree(['file/'])
377
self.assertStatusContains('K file => file/')
378
tree.rename_one('file', 'directory')
379
self.assertStatusContains('RK file => directory/')
381
self.assertStatusContains('RD file => directory')
206
def test_status(self):
207
ignores._set_user_ignores(['./.bazaar'])
210
self.build_tree(['hello.txt'])
211
result = self.run_bzr("status")[0]
212
self.assert_("unknown:\n hello.txt\n" in result, result)
213
self.run_bzr("add", "hello.txt")
214
result = self.run_bzr("status")[0]
215
self.assert_("added:\n hello.txt\n" in result, result)
216
self.run_bzr("commit", "-m", "added")
217
result = self.run_bzr("status", "-r", "0..1")[0]
218
self.assert_("added:\n hello.txt\n" in result, result)
219
self.build_tree(['world.txt'])
220
result = self.run_bzr("status", "-r", "0")[0]
221
self.assert_("added:\n hello.txt\n" \
222
"unknown:\n world.txt\n" in result, result)
224
result2 = self.run_bzr("status", "-r", "0..")[0]
225
self.assertEquals(result2, result)
384
228
class TestStatusEncodings(TestCaseWithTransport):