~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_status.py

  • Committer: Andrew Bennetts
  • Date: 2007-03-26 06:24:01 UTC
  • mto: This revision was merged to the branch mainline in revision 2376.
  • Revision ID: andrew.bennetts@canonical.com-20070326062401-k3nbefzje5332jaf
Deal with review comments from Robert:

  * Add my name to the NEWS file
  * Move the test case to a new module in branch_implementations
  * Remove revision_history cruft from identitymap and test_identitymap
  * Improve some docstrings

Also, this fixes a bug where revision_history was not returning a copy of the
cached data, allowing the cache to be corrupted.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
import sys
29
29
from tempfile import TemporaryFile
30
30
 
31
 
from bzrlib import (
32
 
    bzrdir,
33
 
    conflicts,
34
 
    errors,
35
 
    )
 
31
from bzrlib import bzrdir, errors
36
32
import bzrlib.branch
 
33
from bzrlib.builtins import merge
37
34
from bzrlib.osutils import pathjoin
38
35
from bzrlib.revisionspec import RevisionSpec
39
36
from bzrlib.status import show_tree_status
44
41
class BranchStatus(TestCaseWithTransport):
45
42
    
46
43
    def assertStatus(self, expected_lines, working_tree,
47
 
        revision=None, short=False, pending=True):
 
44
        revision=None, short=False):
48
45
        """Run status in working_tree and look for output.
49
46
        
50
47
        :param expected_lines: The lines to look for.
51
48
        :param working_tree: The tree to run status in.
52
49
        """
53
 
        output_string = self.status_string(working_tree, revision, short,
54
 
                pending)
 
50
        output_string = self.status_string(working_tree, revision, short)
55
51
        self.assertEqual(expected_lines, output_string.splitlines(True))
56
52
    
57
 
    def status_string(self, wt, revision=None, short=False, pending=True):
 
53
    def status_string(self, wt, revision=None, short=False):
58
54
        # use a real file rather than StringIO because it doesn't handle
59
55
        # Unicode very well.
60
56
        tof = codecs.getwriter('utf-8')(TemporaryFile())
61
 
        show_tree_status(wt, to_file=tof, revision=revision, short=short,
62
 
                show_pending=pending)
 
57
        show_tree_status(wt, to_file=tof, revision=revision, short=short)
63
58
        tof.seek(0)
64
59
        return tof.read().decode('utf-8')
65
60
 
95
90
                '  bye.c\n',
96
91
                '  hello.c\n',
97
92
                'pending merges:\n',
98
 
                '  (ghost) pending@pending-0-0\n',
 
93
                '  pending@pending-0-0\n',
99
94
            ],
100
95
            wt)
101
96
        self.assertStatus([
102
97
                '?   bye.c\n',
103
98
                '?   hello.c\n',
104
 
                'P   (ghost) pending@pending-0-0\n',
 
99
                'P   pending@pending-0-0\n',
105
100
            ],
106
101
            wt, short=True)
107
 
        self.assertStatus([
108
 
                'unknown:\n',
109
 
                '  bye.c\n',
110
 
                '  hello.c\n',
111
 
            ],
112
 
            wt, pending=False)
113
 
        self.assertStatus([
114
 
                '?   bye.c\n',
115
 
                '?   hello.c\n',
116
 
            ],
117
 
            wt, short=True, pending=False)
118
102
 
119
103
    def test_branch_status_revisions(self):
120
104
        """Tests branch status with revisions"""
157
141
        b_2 = b_2_dir.open_branch()
158
142
        wt2 = b_2_dir.open_workingtree()
159
143
        wt.commit(u"\N{TIBETAN DIGIT TWO} Empty commit 2")
160
 
        wt2.merge_from_branch(wt.branch)
 
144
        merge(["./branch", -1], [None, None], this_dir = './copy')
161
145
        message = self.status_string(wt2)
162
146
        self.assertStartsWith(message, "pending merges:\n")
163
147
        self.assertEndsWith(message, "Empty commit 2\n")
165
149
        # must be long to make sure we see elipsis at the end
166
150
        wt.commit("Empty commit 3 " +
167
151
                   "blah blah blah blah " * 100)
168
 
        wt2.merge_from_branch(wt.branch)
 
152
        merge(["./branch", -1], [None, None], this_dir = './copy')
169
153
        message = self.status_string(wt2)
170
154
        self.assertStartsWith(message, "pending merges:\n")
171
155
        self.assert_("Empty commit 3" in message)
174
158
    def test_tree_status_ignores(self):
175
159
        """Tests branch status with ignores"""
176
160
        wt = self.make_branch_and_tree('.')
177
 
        self.run_bzr('ignore *~')
 
161
        self.run_bzr('ignore', '*~')
178
162
        wt.commit('commit .bzrignore')
179
163
        self.build_tree(['foo.c', 'foo.c~'])
180
164
        self.assertStatus([
243
227
        tof.seek(0)
244
228
        self.assertEquals(tof.readlines(), ['?   dir2/\n'])
245
229
 
246
 
        tof = StringIO()
247
 
        revs = [RevisionSpec.from_string('0'), RevisionSpec.from_string('1')]
248
 
        show_tree_status(wt, specific_files=['test.c'], to_file=tof,
249
 
                         short=True, revision=revs)
250
 
        tof.seek(0)
251
 
        self.assertEquals(tof.readlines(), ['+N  test.c\n'])
252
 
 
253
 
    def test_specific_files_conflicts(self):
254
 
        tree = self.make_branch_and_tree('.')
255
 
        self.build_tree(['dir2/'])
256
 
        tree.add('dir2')
257
 
        tree.commit('added dir2')
258
 
        tree.set_conflicts(conflicts.ConflictList(
259
 
            [conflicts.ContentsConflict('foo')]))
260
 
        tof = StringIO()
261
 
        show_tree_status(tree, specific_files=['dir2'], to_file=tof)
262
 
        self.assertEqualDiff('', tof.getvalue())
263
 
        tree.set_conflicts(conflicts.ConflictList(
264
 
            [conflicts.ContentsConflict('dir2')]))
265
 
        tof = StringIO()
266
 
        show_tree_status(tree, specific_files=['dir2'], to_file=tof)
267
 
        self.assertEqualDiff('conflicts:\n  Contents conflict in dir2\n',
268
 
                             tof.getvalue())
269
 
 
270
 
        tree.set_conflicts(conflicts.ConflictList(
271
 
            [conflicts.ContentsConflict('dir2/file1')]))
272
 
        tof = StringIO()
273
 
        show_tree_status(tree, specific_files=['dir2'], to_file=tof)
274
 
        self.assertEqualDiff('conflicts:\n  Contents conflict in dir2/file1\n',
275
 
                             tof.getvalue())
276
 
 
277
230
    def test_status_nonexistent_file(self):
278
231
        # files that don't exist in either the basis tree or working tree
279
232
        # should give an error
280
233
        wt = self.make_branch_and_tree('.')
281
 
        out, err = self.run_bzr('status does-not-exist', retcode=3)
 
234
        out, err = self.run_bzr('status', 'does-not-exist', retcode=3)
282
235
        self.assertContainsRe(err, r'do not exist.*does-not-exist')
283
236
 
284
237
    def test_status_out_of_date(self):
291
244
            tree.commit('add test file')
292
245
            # simulate what happens after a remote push
293
246
            tree.set_last_revision("0")
 
247
            out, err = self.run_bzr('status')
 
248
            self.assertEqual("working tree is out of date, run 'bzr update'\n",
 
249
                             err)
294
250
        finally:
295
 
            # before run another commands we should unlock tree
296
251
            tree.unlock()
297
 
        out, err = self.run_bzr('status')
298
 
        self.assertEqual("working tree is out of date, run 'bzr update'\n",
299
 
                         err)
300
252
 
301
253
 
302
254
class CheckoutStatus(BranchStatus):
316
268
class TestStatus(TestCaseWithTransport):
317
269
 
318
270
    def test_status_plain(self):
319
 
        tree = self.make_branch_and_tree('.')
 
271
        self.run_bzr("init")
320
272
 
321
273
        self.build_tree(['hello.txt'])
322
274
        result = self.run_bzr("status")[0]
323
275
        self.assertContainsRe(result, "unknown:\n  hello.txt\n")
324
276
 
325
 
        tree.add("hello.txt")
 
277
        self.run_bzr("add", "hello.txt")
326
278
        result = self.run_bzr("status")[0]
327
279
        self.assertContainsRe(result, "added:\n  hello.txt\n")
328
280
 
329
 
        tree.commit(message="added")
330
 
        result = self.run_bzr("status -r 0..1")[0]
331
 
        self.assertContainsRe(result, "added:\n  hello.txt\n")
332
 
 
333
 
        result = self.run_bzr("status -c 1")[0]
 
281
        self.run_bzr("commit", "-m", "added")
 
282
        result = self.run_bzr("status", "-r", "0..1")[0]
334
283
        self.assertContainsRe(result, "added:\n  hello.txt\n")
335
284
 
336
285
        self.build_tree(['world.txt'])
337
 
        result = self.run_bzr("status -r 0")[0]
 
286
        result = self.run_bzr("status", "-r", "0")[0]
338
287
        self.assertContainsRe(result, "added:\n  hello.txt\n" \
339
288
                                      "unknown:\n  world.txt\n")
340
 
        result2 = self.run_bzr("status -r 0..")[0]
 
289
        result2 = self.run_bzr("status", "-r", "0..")[0]
341
290
        self.assertEquals(result2, result)
342
291
 
343
292
    def test_status_short(self):
344
 
        tree = self.make_branch_and_tree('.')
 
293
        self.run_bzr("init")
345
294
 
346
295
        self.build_tree(['hello.txt'])
347
 
        result = self.run_bzr("status --short")[0]
 
296
        result = self.run_bzr("status","--short")[0]
348
297
        self.assertContainsRe(result, "[?]   hello.txt\n")
349
298
 
350
 
        tree.add("hello.txt")
351
 
        result = self.run_bzr("status --short")[0]
 
299
        self.run_bzr("add", "hello.txt")
 
300
        result = self.run_bzr("status","--short")[0]
352
301
        self.assertContainsRe(result, "[+]N  hello.txt\n")
353
302
 
354
 
        tree.commit(message="added")
355
 
        result = self.run_bzr("status --short -r 0..1")[0]
 
303
        self.run_bzr("commit", "-m", "added")
 
304
        result = self.run_bzr("status", "--short", "-r", "0..1")[0]
356
305
        self.assertContainsRe(result, "[+]N  hello.txt\n")
357
306
 
358
307
        self.build_tree(['world.txt'])
359
 
        result = self.run_bzr("status --short -r 0")[0]
 
308
        result = self.run_bzr("status", "--short", "-r", "0")[0]
360
309
        self.assertContainsRe(result, "[+]N  hello.txt\n" \
361
310
                                      "[?]   world.txt\n")
362
 
        result2 = self.run_bzr("status --short -r 0..")[0]
 
311
        result2 = self.run_bzr("status", "--short", "-r", "0..")[0]
363
312
        self.assertEquals(result2, result)
364
313
 
365
314
    def test_status_versioned(self):
366
 
        tree = self.make_branch_and_tree('.')
 
315
        self.run_bzr("init")
367
316
 
368
317
        self.build_tree(['hello.txt'])
369
 
        result = self.run_bzr("status --versioned")[0]
 
318
        result = self.run_bzr("status", "--versioned")[0]
370
319
        self.assertNotContainsRe(result, "unknown:\n  hello.txt\n")
371
320
 
372
 
        tree.add("hello.txt")
373
 
        result = self.run_bzr("status --versioned")[0]
 
321
        self.run_bzr("add", "hello.txt")
 
322
        result = self.run_bzr("status", "--versioned")[0]
374
323
        self.assertContainsRe(result, "added:\n  hello.txt\n")
375
324
 
376
 
        tree.commit("added")
377
 
        result = self.run_bzr("status --versioned -r 0..1")[0]
 
325
        self.run_bzr("commit", "-m", "added")
 
326
        result = self.run_bzr("status", "--versioned", "-r", "0..1")[0]
378
327
        self.assertContainsRe(result, "added:\n  hello.txt\n")
379
328
 
380
329
        self.build_tree(['world.txt'])
381
 
        result = self.run_bzr("status --versioned -r 0")[0]
 
330
        result = self.run_bzr("status", "--versioned", "-r", "0")[0]
382
331
        self.assertContainsRe(result, "added:\n  hello.txt\n")
383
332
        self.assertNotContainsRe(result, "unknown:\n  world.txt\n")
384
 
        result2 = self.run_bzr("status --versioned -r 0..")[0]
385
 
        self.assertEquals(result2, result)
386
 
 
387
 
    def test_status_SV(self):
388
 
        tree = self.make_branch_and_tree('.')
389
 
 
390
 
        self.build_tree(['hello.txt'])
391
 
        result = self.run_bzr("status -SV")[0]
392
 
        self.assertNotContainsRe(result, "hello.txt")
393
 
 
394
 
        tree.add("hello.txt")
395
 
        result = self.run_bzr("status -SV")[0]
396
 
        self.assertContainsRe(result, "[+]N  hello.txt\n")
397
 
 
398
 
        tree.commit(message="added")
399
 
        result = self.run_bzr("status -SV -r 0..1")[0]
400
 
        self.assertContainsRe(result, "[+]N  hello.txt\n")
401
 
 
402
 
        self.build_tree(['world.txt'])
403
 
        result = self.run_bzr("status -SV -r 0")[0]
404
 
        self.assertContainsRe(result, "[+]N  hello.txt\n")
405
 
 
406
 
        result2 = self.run_bzr("status -SV -r 0..")[0]
 
333
        result2 = self.run_bzr("status", "--versioned", "-r", "0..")[0]
407
334
        self.assertEquals(result2, result)
408
335
 
409
336
    def assertStatusContains(self, pattern):
410
337
        """Run status, and assert it contains the given pattern"""
411
 
        result = self.run_bzr("status --short")[0]
 
338
        result = self.run_bzr("status", "--short")[0]
412
339
        self.assertContainsRe(result, pattern)
413
340
 
414
341
    def test_kind_change_short(self):
424
351
        rmdir('directory')
425
352
        self.assertStatusContains('RD  file => directory')
426
353
 
427
 
    def test_status_illegal_revision_specifiers(self):
428
 
        out, err = self.run_bzr('status -r 1..23..123', retcode=3)
429
 
        self.assertContainsRe(err, 'one or two revision specifiers')
430
 
 
431
 
    def test_status_no_pending(self):
432
 
        a_tree = self.make_branch_and_tree('a')
433
 
        self.build_tree(['a/a'])
434
 
        a_tree.add('a')
435
 
        a_tree.commit('a')
436
 
        b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
437
 
        self.build_tree(['b/b'])
438
 
        b_tree.add('b')
439
 
        b_tree.commit('b')
440
 
 
441
 
        self.run_bzr('merge ../b', working_dir='a')
442
 
        out, err = self.run_bzr('status --no-pending', working_dir='a')
443
 
        self.assertEquals(out, "added:\n  b\n")
444
 
 
445
354
 
446
355
class TestStatusEncodings(TestCaseWithTransport):
447
356