~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Robert Collins
  • Date: 2007-07-04 08:08:13 UTC
  • mfrom: (2572 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2587.
  • Revision ID: robertc@robertcollins.net-20070704080813-wzebx0r88fvwj5rq
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 by Canonical Ltd
 
1
# Copyright (C) 2005, 2006 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
21
21
import re
22
22
import sys
23
23
 
 
24
from bzrlib import (
 
25
    ignores,
 
26
    )
24
27
from bzrlib.branch import Branch
25
28
from bzrlib.bzrdir import BzrDir
26
29
from bzrlib.errors import BzrCommandError
35
38
        # If forced, it should succeed, but this is not tested here.
36
39
        self.run_bzr("init")
37
40
        self.build_tree(['hello.txt'])
38
 
        result = self.run_bzr("commit", "-m", "empty", retcode=3)
39
 
        self.assertEqual(('', 'bzr: ERROR: no changes to commit.'
40
 
                              ' use --unchanged to commit anyhow\n'),
41
 
                         result)
 
41
        out,err = self.run_bzr("commit", "-m", "empty", retcode=3)
 
42
        self.assertEqual('', out)
 
43
        self.assertStartsWith(err, 'bzr: ERROR: no changes to commit.'
 
44
                                  ' use --unchanged to commit anyhow\n')
 
45
 
 
46
    def test_commit_success(self):
 
47
        """Successful commit should not leave behind a bzr-commit-* file"""
 
48
        self.run_bzr("init")
 
49
        self.run_bzr("commit", "--unchanged", "-m", "message")
 
50
        self.assertEqual('', self.run_bzr(['unknowns'])[0])
 
51
 
 
52
        # same for unicode messages
 
53
        self.run_bzr("commit", "--unchanged", "-m", u'foo\xb5')
 
54
        self.assertEqual('', self.run_bzr(['unknowns'])[0])
42
55
 
43
56
    def test_commit_with_path(self):
44
57
        """Commit tree with path of root specified"""
63
76
 
64
77
    def test_10_verbose_commit(self):
65
78
        """Add one file and examine verbose commit output"""
66
 
        self.runbzr("init")
 
79
        self.run_bzr("init")
67
80
        self.build_tree(['hello.txt'])
68
 
        self.runbzr("add hello.txt")
 
81
        self.run_bzr("add hello.txt")
69
82
        out,err = self.run_bzr("commit", "-m", "added")
70
83
        self.assertEqual('', out)
71
84
        self.assertEqual('added hello.txt\n'
128
141
 
129
142
    def test_verbose_commit_with_unchanged(self):
130
143
        """Unchanged files should not be listed by default in verbose output"""
131
 
        self.runbzr("init")
 
144
        self.run_bzr("init")
132
145
        self.build_tree(['hello.txt', 'unchanged.txt'])
133
 
        self.runbzr('add unchanged.txt')
134
 
        self.runbzr('commit -m unchanged unchanged.txt')
135
 
        self.runbzr("add hello.txt")
 
146
        self.run_bzr('add unchanged.txt')
 
147
        self.run_bzr('commit -m unchanged unchanged.txt')
 
148
        self.run_bzr("add hello.txt")
136
149
        out,err = self.run_bzr("commit", "-m", "added")
137
150
        self.assertEqual('', out)
138
151
        self.assertEqual('added hello.txt\n'
206
219
            err)
207
220
 
208
221
    def test_empty_commit_message(self):
209
 
        self.runbzr("init")
 
222
        self.run_bzr("init")
210
223
        file('foo.c', 'wt').write('int main() {}')
211
 
        self.runbzr(['add', 'foo.c'])
212
 
        self.runbzr(["commit", "-m", ""] , retcode=3)
 
224
        self.run_bzr('add foo.c')
 
225
        self.run_bzr('commit -m ""', retcode=3)
213
226
 
214
227
    def test_other_branch_commit(self):
215
228
        # this branch is to ensure consistent behaviour, whether we're run
216
229
        # inside a branch, or not.
217
230
        os.mkdir('empty_branch')
218
231
        os.chdir('empty_branch')
219
 
        self.runbzr('init')
 
232
        self.run_bzr('init')
220
233
        os.mkdir('branch')
221
234
        os.chdir('branch')
222
 
        self.runbzr('init')
 
235
        self.run_bzr('init')
223
236
        file('foo.c', 'wt').write('int main() {}')
224
237
        file('bar.c', 'wt').write('int main() {}')
225
238
        os.chdir('..')
226
 
        self.runbzr(['add', 'branch/foo.c'])
227
 
        self.runbzr(['add', 'branch'])
 
239
        self.run_bzr(['add', 'branch/foo.c'])
 
240
        self.run_bzr(['add', 'branch'])
228
241
        # can't commit files in different trees; sane error
229
 
        self.runbzr('commit -m newstuff branch/foo.c .', retcode=3)
230
 
        self.runbzr('commit -m newstuff branch/foo.c')
231
 
        self.runbzr('commit -m newstuff branch')
232
 
        self.runbzr('commit -m newstuff branch', retcode=3)
 
242
        self.run_bzr('commit -m newstuff branch/foo.c .', retcode=3)
 
243
        self.run_bzr('commit -m newstuff branch/foo.c')
 
244
        self.run_bzr('commit -m newstuff branch')
 
245
        self.run_bzr('commit -m newstuff branch', retcode=3)
233
246
 
234
247
    def test_out_of_date_tree_commit(self):
235
248
        # check we get an error code and a clear message committing with an out
236
249
        # of date checkout
237
250
        self.make_branch_and_tree('branch')
238
251
        # make a checkout
239
 
        self.runbzr('checkout --lightweight branch checkout')
 
252
        self.run_bzr('checkout --lightweight branch checkout')
240
253
        # commit to the original branch to make the checkout out of date
241
 
        self.runbzr('commit --unchanged -m message branch')
 
254
        self.run_bzr('commit --unchanged -m message branch')
242
255
        # now commit to the checkout should emit
243
256
        # ERROR: Out of date with the branch, 'bzr update' is suggested
244
 
        output = self.runbzr('commit --unchanged -m checkout_message '
 
257
        output = self.run_bzr('commit --unchanged -m checkout_message '
245
258
                             'checkout', retcode=3)
246
259
        self.assertEqual(output,
247
260
                         ('',
300
313
        self.assertNotContainsRe(result, 'file-a')
301
314
        result = self.run_bzr('status')[0]
302
315
        self.assertContainsRe(result, 'removed:\n  file-a')
 
316
 
 
317
    def test_strict_commit(self):
 
318
        """Commit with --strict works if everything is known"""
 
319
        ignores._set_user_ignores([])
 
320
        tree = self.make_branch_and_tree('tree')
 
321
        self.build_tree(['tree/a'])
 
322
        tree.add('a')
 
323
        # A simple change should just work
 
324
        self.run_bzr('commit', '--strict', '-m', 'adding a',
 
325
                     working_dir='tree')
 
326
 
 
327
    def test_strict_commit_no_changes(self):
 
328
        """commit --strict gives "no changes" if there is nothing to commit"""
 
329
        tree = self.make_branch_and_tree('tree')
 
330
        self.build_tree(['tree/a'])
 
331
        tree.add('a')
 
332
        tree.commit('adding a')
 
333
 
 
334
        # With no changes, it should just be 'no changes'
 
335
        # Make sure that commit is failing because there is nothing to do
 
336
        self.run_bzr_error(['no changes to commit'],
 
337
                           'commit', '--strict', '-m', 'no changes',
 
338
                           working_dir='tree')
 
339
 
 
340
        # But --strict doesn't care if you supply --unchanged
 
341
        self.run_bzr('commit', '--strict', '--unchanged', '-m', 'no changes',
 
342
                     working_dir='tree')
 
343
 
 
344
    def test_strict_commit_unknown(self):
 
345
        """commit --strict fails if a file is unknown"""
 
346
        tree = self.make_branch_and_tree('tree')
 
347
        self.build_tree(['tree/a'])
 
348
        tree.add('a')
 
349
        tree.commit('adding a')
 
350
 
 
351
        # Add one file so there is a change, but forget the other
 
352
        self.build_tree(['tree/b', 'tree/c'])
 
353
        tree.add('b')
 
354
        self.run_bzr_error(['Commit refused because there are unknown files'],
 
355
                           'commit', '--strict', '-m', 'add b',
 
356
                           working_dir='tree')
 
357
 
 
358
        # --no-strict overrides --strict
 
359
        self.run_bzr('commit', '--strict', '-m', 'add b', '--no-strict',
 
360
                     working_dir='tree')
 
361
 
 
362
    def test_fixes_bug_output(self):
 
363
        """commit --fixes=lp:23452 succeeds without output."""
 
364
        tree = self.make_branch_and_tree('tree')
 
365
        self.build_tree(['tree/hello.txt'])
 
366
        tree.add('hello.txt')
 
367
        output, err = self.run_bzr(
 
368
            'commit', '-m', 'hello', '--fixes=lp:23452', 'tree/hello.txt')
 
369
        self.assertEqual('', output)
 
370
        self.assertEqual('added hello.txt\nCommitted revision 1.\n', err)
 
371
 
 
372
    def test_no_bugs_no_properties(self):
 
373
        """If no bugs are fixed, the bugs property is not set.
 
374
 
 
375
        see https://beta.launchpad.net/bzr/+bug/109613
 
376
        """
 
377
        tree = self.make_branch_and_tree('tree')
 
378
        self.build_tree(['tree/hello.txt'])
 
379
        tree.add('hello.txt')
 
380
        self.run_bzr( 'commit', '-m', 'hello', 'tree/hello.txt')
 
381
        # Get the revision properties, ignoring the branch-nick property, which
 
382
        # we don't care about for this test.
 
383
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
 
384
        properties = dict(last_rev.properties)
 
385
        del properties['branch-nick']
 
386
        self.assertFalse('bugs' in properties)
 
387
 
 
388
    def test_fixes_bug_sets_property(self):
 
389
        """commit --fixes=lp:234 sets the lp:234 revprop to 'fixed'."""
 
390
        tree = self.make_branch_and_tree('tree')
 
391
        self.build_tree(['tree/hello.txt'])
 
392
        tree.add('hello.txt')
 
393
        self.run_bzr(
 
394
            'commit', '-m', 'hello', '--fixes=lp:234', 'tree/hello.txt')
 
395
 
 
396
        # Get the revision properties, ignoring the branch-nick property, which
 
397
        # we don't care about for this test.
 
398
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
 
399
        properties = dict(last_rev.properties)
 
400
        del properties['branch-nick']
 
401
 
 
402
        self.assertEqual({'bugs': 'https://launchpad.net/bugs/234 fixed'},
 
403
                         properties)
 
404
 
 
405
    def test_fixes_multiple_bugs_sets_properties(self):
 
406
        """--fixes can be used more than once to show that bugs are fixed."""
 
407
        tree = self.make_branch_and_tree('tree')
 
408
        self.build_tree(['tree/hello.txt'])
 
409
        tree.add('hello.txt')
 
410
        self.run_bzr(
 
411
            'commit', '-m', 'hello', '--fixes=lp:123', '--fixes=lp:235',
 
412
            'tree/hello.txt')
 
413
 
 
414
        # Get the revision properties, ignoring the branch-nick property, which
 
415
        # we don't care about for this test.
 
416
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
 
417
        properties = dict(last_rev.properties)
 
418
        del properties['branch-nick']
 
419
 
 
420
        self.assertEqual(
 
421
            {'bugs': 'https://launchpad.net/bugs/123 fixed\n'
 
422
                     'https://launchpad.net/bugs/235 fixed'},
 
423
            properties)
 
424
 
 
425
    def test_fixes_bug_with_alternate_trackers(self):
 
426
        """--fixes can be used on a properly configured branch to mark bug
 
427
        fixes on multiple trackers.
 
428
        """
 
429
        tree = self.make_branch_and_tree('tree')
 
430
        tree.branch.get_config().set_user_option(
 
431
            'trac_twisted_url', 'http://twistedmatrix.com/trac')
 
432
        self.build_tree(['tree/hello.txt'])
 
433
        tree.add('hello.txt')
 
434
        self.run_bzr(
 
435
            'commit', '-m', 'hello', '--fixes=lp:123',
 
436
            '--fixes=twisted:235', 'tree/')
 
437
 
 
438
        # Get the revision properties, ignoring the branch-nick property, which
 
439
        # we don't care about for this test.
 
440
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
 
441
        properties = dict(last_rev.properties)
 
442
        del properties['branch-nick']
 
443
 
 
444
        self.assertEqual(
 
445
            {'bugs': 'https://launchpad.net/bugs/123 fixed\n'
 
446
                     'http://twistedmatrix.com/trac/ticket/235 fixed'},
 
447
            properties)
 
448
 
 
449
    def test_fixes_unknown_bug_prefix(self):
 
450
        tree = self.make_branch_and_tree('tree')
 
451
        self.build_tree(['tree/hello.txt'])
 
452
        tree.add('hello.txt')
 
453
        self.run_bzr_error(
 
454
            ["Unrecognized bug %s. Commit refused." % 'xxx:123'],
 
455
            'commit', '-m', 'add b', '--fixes=xxx:123',
 
456
            working_dir='tree')
 
457
 
 
458
    def test_fixes_invalid_bug_number(self):
 
459
        tree = self.make_branch_and_tree('tree')
 
460
        self.build_tree(['tree/hello.txt'])
 
461
        tree.add('hello.txt')
 
462
        self.run_bzr_error(
 
463
            ["Invalid bug identifier for %s. Commit refused." % 'lp:orange'],
 
464
            'commit', '-m', 'add b', '--fixes=lp:orange',
 
465
            working_dir='tree')
 
466
 
 
467
    def test_fixes_invalid_argument(self):
 
468
        """Raise an appropriate error when the fixes argument isn't tag:id."""
 
469
        tree = self.make_branch_and_tree('tree')
 
470
        self.build_tree(['tree/hello.txt'])
 
471
        tree.add('hello.txt')
 
472
        self.run_bzr_error(
 
473
            [r"Invalid bug orange. Must be in the form of 'tag:id'\. "
 
474
             r"Commit refused\."],
 
475
            'commit', '-m', 'add b', '--fixes=orange',
 
476
            working_dir='tree')