~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Alexander Belchenko
  • Date: 2006-07-31 16:12:57 UTC
  • mto: (1711.2.111 jam-integration)
  • mto: This revision was merged to the branch mainline in revision 1906.
  • Revision ID: bialix@ukr.net-20060731161257-91a231523255332c
new official bzr.ico

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 Canonical Ltd
 
1
# Copyright (C) 2005, 2006 by Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
24
24
 
25
25
from cStringIO import StringIO
26
26
import codecs
27
 
from os import mkdir, chdir, rmdir, unlink
 
27
from os import mkdir, chdir
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, ignores
36
32
import bzrlib.branch
37
33
from bzrlib.builtins import merge
38
34
from bzrlib.osutils import pathjoin
44
40
 
45
41
class BranchStatus(TestCaseWithTransport):
46
42
    
47
 
    def assertStatus(self, expected_lines, working_tree,
48
 
        revision=None, short=False):
49
 
        """Run status in working_tree and look for output.
50
 
        
51
 
        :param expected_lines: The lines to look for.
52
 
        :param working_tree: The tree to run status in.
53
 
        """
54
 
        output_string = self.status_string(working_tree, revision, short)
55
 
        self.assertEqual(expected_lines, output_string.splitlines(True))
56
 
    
57
 
    def status_string(self, wt, revision=None, short=False):
58
 
        # use a real file rather than StringIO because it doesn't handle
59
 
        # Unicode very well.
60
 
        tof = codecs.getwriter('utf-8')(TemporaryFile())
61
 
        show_tree_status(wt, to_file=tof, revision=revision, short=short)
62
 
        tof.seek(0)
63
 
        return tof.read().decode('utf-8')
64
 
 
65
43
    def test_branch_status(self):
66
44
        """Test basic branch status"""
67
45
        wt = self.make_branch_and_tree('.')
68
 
 
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
72
 
        # as a corner case.
73
 
        self.assertStatus([], wt)
74
 
 
 
46
        b = wt.branch
 
47
 
 
48
        ignores._set_user_ignores(['./.bazaar'])
 
49
 
 
50
        # status with nothing
 
51
        tof = StringIO()
 
52
        show_tree_status(wt, to_file=tof)
 
53
        self.assertEquals(tof.getvalue(), "")
 
54
 
 
55
        tof = StringIO()
75
56
        self.build_tree(['hello.c', 'bye.c'])
76
 
        self.assertStatus([
77
 
                'unknown:\n',
78
 
                '  bye.c\n',
79
 
                '  hello.c\n',
80
 
            ],
81
 
            wt)
82
 
        self.assertStatus([
83
 
                '?   bye.c\n',
84
 
                '?   hello.c\n',
85
 
            ],
86
 
            wt, short=True)
87
 
 
88
 
        # add a commit to allow showing pending merges.
89
 
        wt.commit('create a parent to allow testing merge output')
90
 
 
91
 
        wt.add_parent_tree_id('pending@pending-0-0')
92
 
        self.assertStatus([
93
 
                'unknown:\n',
94
 
                '  bye.c\n',
95
 
                '  hello.c\n',
96
 
                'pending merges:\n',
97
 
                '  pending@pending-0-0\n',
98
 
            ],
99
 
            wt)
100
 
        self.assertStatus([
101
 
                '?   bye.c\n',
102
 
                '?   hello.c\n',
103
 
                'P   pending@pending-0-0\n',
104
 
            ],
105
 
            wt, short=True)
 
57
        wt.add_pending_merge('pending@pending-0-0')
 
58
        show_tree_status(wt, to_file=tof)
 
59
        tof.seek(0)
 
60
        self.assertEquals(tof.readlines(),
 
61
                          ['unknown:\n',
 
62
                           '  bye.c\n',
 
63
                           '  hello.c\n',
 
64
                           'pending merges:\n',
 
65
                           '  pending@pending-0-0\n'
 
66
                           ])
106
67
 
107
68
    def test_branch_status_revisions(self):
108
69
        """Tests branch status with revisions"""
109
70
        wt = self.make_branch_and_tree('.')
110
 
 
 
71
        b = wt.branch
 
72
 
 
73
        ignores._set_user_ignores(['./.bazaar'])
 
74
 
 
75
        tof = StringIO()
111
76
        self.build_tree(['hello.c', 'bye.c'])
112
77
        wt.add('hello.c')
113
78
        wt.add('bye.c')
114
79
        wt.commit('Test message')
115
80
 
116
 
        revs = [RevisionSpec.from_string('0')]
117
 
        self.assertStatus([
118
 
                'added:\n',
119
 
                '  bye.c\n',
120
 
                '  hello.c\n'
121
 
            ],
122
 
            wt,
123
 
            revision=revs)
 
81
        tof = StringIO()
 
82
        revs =[]
 
83
        revs.append(RevisionSpec(0))
 
84
        
 
85
        show_tree_status(wt, to_file=tof, revision=revs)
 
86
        
 
87
        tof.seek(0)
 
88
        self.assertEquals(tof.readlines(),
 
89
                          ['added:\n',
 
90
                           '  bye.c\n',
 
91
                           '  hello.c\n'])
124
92
 
125
93
        self.build_tree(['more.c'])
126
94
        wt.add('more.c')
127
95
        wt.commit('Another test message')
128
96
        
129
 
        revs.append(RevisionSpec.from_string('1'))
130
 
        self.assertStatus([
131
 
                'added:\n',
132
 
                '  bye.c\n',
133
 
                '  hello.c\n',
134
 
            ],
135
 
            wt,
136
 
            revision=revs)
 
97
        tof = StringIO()
 
98
        revs.append(RevisionSpec(1))
 
99
        
 
100
        show_tree_status(wt, to_file=tof, revision=revs)
 
101
        
 
102
        tof.seek(0)
 
103
        self.assertEquals(tof.readlines(),
 
104
                          ['added:\n',
 
105
                           '  bye.c\n',
 
106
                           '  hello.c\n'])
 
107
 
 
108
    def status_string(self, wt):
 
109
        # use a real file rather than StringIO because it doesn't handle
 
110
        # Unicode very well.
 
111
        tof = codecs.getwriter('utf-8')(TemporaryFile())
 
112
        show_tree_status(wt, to_file=tof)
 
113
        tof.seek(0)
 
114
        return tof.read().decode('utf-8')
137
115
 
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")
161
 
 
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~'])
168
 
        self.assertStatus([
169
 
                'unknown:\n',
170
 
                '  foo.c\n',
171
 
                ],
172
 
                wt)
173
 
        self.assertStatus([
174
 
                '?   foo.c\n',
175
 
                ],
176
 
                wt, short=True)
177
 
 
178
 
    def test_tree_status_specific_files(self):
 
138
        self.assert_(message.endswith("...\n")) 
 
139
 
 
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('.')
181
143
        b = wt.branch
182
144
 
 
145
        ignores._set_user_ignores(['./.bazaar'])
 
146
 
183
147
        self.build_tree(['directory/','directory/hello.c', 'bye.c','test.c','dir2/'])
184
148
        wt.add('directory')
185
149
        wt.add('test.c')
186
150
        wt.commit('testing')
187
151
        
188
 
        self.assertStatus([
189
 
                'unknown:\n',
190
 
                '  bye.c\n',
191
 
                '  dir2/\n',
192
 
                '  directory/hello.c\n'
193
 
                ],
194
 
                wt)
195
 
 
196
 
        self.assertStatus([
197
 
                '?   bye.c\n',
198
 
                '?   dir2/\n',
199
 
                '?   directory/hello.c\n'
200
 
                ],
201
 
                wt, short=True)
202
 
 
203
152
        tof = StringIO()
 
153
        show_tree_status(wt, to_file=tof)
 
154
        tof.seek(0)
 
155
        self.assertEquals(tof.readlines(),
 
156
                          ['unknown:\n',
 
157
                           '  bye.c\n',
 
158
                           '  dir2\n',
 
159
                           '  directory/hello.c\n'
 
160
                           ])
 
161
 
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'
215
173
                           ])
216
174
        tof = StringIO()
217
 
        show_tree_status(wt, specific_files=['directory'], to_file=tof,
218
 
                         short=True)
219
 
        tof.seek(0)
220
 
        self.assertEquals(tof.readlines(), ['?   directory/hello.c\n'])
221
 
 
222
 
        tof = StringIO()
223
175
        show_tree_status(wt, specific_files=['dir2'], to_file=tof)
224
176
        tof.seek(0)
225
177
        self.assertEquals(tof.readlines(),
226
178
                          ['unknown:\n',
227
 
                           '  dir2/\n'
 
179
                           '  dir2\n'
228
180
                           ])
229
 
        tof = StringIO()
230
 
        show_tree_status(wt, specific_files=['dir2'], to_file=tof, short=True)
231
 
        tof.seek(0)
232
 
        self.assertEquals(tof.readlines(), ['?   dir2/\n'])
233
 
 
234
 
    def test_specific_files_conflicts(self):
235
 
        tree = self.make_branch_and_tree('.')
236
 
        self.build_tree(['dir2/'])
237
 
        tree.add('dir2')
238
 
        tree.commit('added dir2')
239
 
        tree.set_conflicts(conflicts.ConflictList(
240
 
            [conflicts.ContentsConflict('foo')]))
241
 
        tof = StringIO()
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')]))
246
 
        tof = StringIO()
247
 
        show_tree_status(tree, specific_files=['dir2'], to_file=tof)
248
 
        self.assertEqualDiff('conflicts:\n  Contents conflict in dir2\n',
249
 
                             tof.getvalue())
250
 
 
251
 
        tree.set_conflicts(conflicts.ConflictList(
252
 
            [conflicts.ContentsConflict('dir2/file1')]))
253
 
        tof = StringIO()
254
 
        show_tree_status(tree, specific_files=['dir2'], to_file=tof)
255
 
        self.assertEqualDiff('conflicts:\n  Contents conflict in dir2/file1\n',
256
 
                             tof.getvalue())
257
181
 
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')
264
188
 
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')])
269
 
        tree.lock_write()
270
 
        try:
271
 
            tree.add(['a'])
272
 
            tree.commit('add test file')
273
 
            # simulate what happens after a remote push
274
 
            tree.set_last_revision("0")
275
 
        finally:
276
 
            # before run another commands we should unlock tree
277
 
            tree.unlock()
278
 
        out, err = self.run_bzr('status')
279
 
        self.assertEqual("working tree is out of date, run 'bzr update'\n",
280
 
                         err)
281
 
 
282
189
 
283
190
class CheckoutStatus(BranchStatus):
284
191
 
296
203
 
297
204
class TestStatus(TestCaseWithTransport):
298
205
 
299
 
    def test_status_plain(self):
300
 
        self.run_bzr("init")
301
 
 
302
 
        self.build_tree(['hello.txt'])
303
 
        result = self.run_bzr("status")[0]
304
 
        self.assertContainsRe(result, "unknown:\n  hello.txt\n")
305
 
 
306
 
        self.run_bzr("add hello.txt")
307
 
        result = self.run_bzr("status")[0]
308
 
        self.assertContainsRe(result, "added:\n  hello.txt\n")
309
 
 
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")
313
 
 
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)
320
 
 
321
 
    def test_status_short(self):
322
 
        self.run_bzr("init")
323
 
 
324
 
        self.build_tree(['hello.txt'])
325
 
        result = self.run_bzr("status --short")[0]
326
 
        self.assertContainsRe(result, "[?]   hello.txt\n")
327
 
 
328
 
        self.run_bzr("add hello.txt")
329
 
        result = self.run_bzr("status --short")[0]
330
 
        self.assertContainsRe(result, "[+]N  hello.txt\n")
331
 
 
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")
335
 
 
336
 
        self.build_tree(['world.txt'])
337
 
        result = self.run_bzr("status --short -r 0")[0]
338
 
        self.assertContainsRe(result, "[+]N  hello.txt\n" \
339
 
                                      "[?]   world.txt\n")
340
 
        result2 = self.run_bzr("status --short -r 0..")[0]
341
 
        self.assertEquals(result2, result)
342
 
 
343
 
    def test_status_versioned(self):
344
 
        self.run_bzr("init")
345
 
 
346
 
        self.build_tree(['hello.txt'])
347
 
        result = self.run_bzr("status --versioned")[0]
348
 
        self.assertNotContainsRe(result, "unknown:\n  hello.txt\n")
349
 
 
350
 
        self.run_bzr("add hello.txt")
351
 
        result = self.run_bzr("status --versioned")[0]
352
 
        self.assertContainsRe(result, "added:\n  hello.txt\n")
353
 
 
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")
357
 
 
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)
364
 
 
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)
369
 
 
370
 
    def test_kind_change_short(self):
371
 
        tree = self.make_branch_and_tree('.')
372
 
        self.build_tree(['file'])
373
 
        tree.add('file')
374
 
        tree.commit('added file')
375
 
        unlink('file')
376
 
        self.build_tree(['file/'])
377
 
        self.assertStatusContains('K  file => file/')
378
 
        tree.rename_one('file', 'directory')
379
 
        self.assertStatusContains('RK  file => directory/')
380
 
        rmdir('directory')
381
 
        self.assertStatusContains('RD  file => directory')
 
206
    def test_status(self):
 
207
        ignores._set_user_ignores(['./.bazaar'])
 
208
 
 
209
        self.run_bzr("init")
 
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)
 
223
 
 
224
        result2 = self.run_bzr("status", "-r", "0..")[0]
 
225
        self.assertEquals(result2, result)
382
226
 
383
227
 
384
228
class TestStatusEncodings(TestCaseWithTransport):