/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

merge bzr.dev r4164

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
    config,
36
36
    errors,
37
37
    globbing,
 
38
    hooks,
38
39
    log,
39
40
    merge as _mod_merge,
40
41
    merge_directive,
839
840
    with bzr send.
840
841
    """
841
842
 
842
 
    _see_also = ['push', 'update', 'status-flags']
 
843
    _see_also = ['push', 'update', 'status-flags', 'send']
843
844
    takes_options = ['remember', 'overwrite', 'revision',
844
845
        custom_help('verbose',
845
846
            help='Show logs of pulled revisions.'),
2439
2440
        tree.unlock()
2440
2441
        if len(matches) > 0:
2441
2442
            print "Warning: the following files are version controlled and" \
2442
 
                  " match your ignore pattern:\n%s" % ("\n".join(matches),)
 
2443
                  " match your ignore pattern:\n%s" \
 
2444
                  "\nThese files will continue to be version controlled" \
 
2445
                  " unless you 'bzr remove' them." % ("\n".join(matches),)
2443
2446
 
2444
2447
 
2445
2448
class cmd_ignored(Command):
2589
2592
            tree = b.basis_tree()
2590
2593
        rev_tree = _get_one_revision_tree('cat', revision, branch=b)
2591
2594
 
2592
 
        cur_file_id = tree.path2id(relpath)
2593
2595
        old_file_id = rev_tree.path2id(relpath)
2594
2596
 
2595
2597
        if name_from_revision:
 
2598
            # Try in revision if requested
2596
2599
            if old_file_id is None:
2597
2600
                raise errors.BzrCommandError(
2598
2601
                    "%r is not present in revision %s" % (
2599
2602
                        filename, rev_tree.get_revision_id()))
2600
2603
            else:
2601
2604
                content = rev_tree.get_file_text(old_file_id)
2602
 
        elif cur_file_id is not None:
2603
 
            content = rev_tree.get_file_text(cur_file_id)
2604
 
        elif old_file_id is not None:
2605
 
            content = rev_tree.get_file_text(old_file_id)
2606
2605
        else:
2607
 
            raise errors.BzrCommandError(
2608
 
                "%r is not present in revision %s" % (
2609
 
                    filename, rev_tree.get_revision_id()))
 
2606
            cur_file_id = tree.path2id(relpath)
 
2607
            found = False
 
2608
            if cur_file_id is not None:
 
2609
                # Then try with the actual file id
 
2610
                try:
 
2611
                    content = rev_tree.get_file_text(cur_file_id)
 
2612
                    found = True
 
2613
                except errors.NoSuchId:
 
2614
                    # The actual file id didn't exist at that time
 
2615
                    pass
 
2616
            if not found and old_file_id is not None:
 
2617
                # Finally try with the old file id
 
2618
                content = rev_tree.get_file_text(old_file_id)
 
2619
                found = True
 
2620
            if not found:
 
2621
                # Can't be found anywhere
 
2622
                raise errors.BzrCommandError(
 
2623
                    "%r is not present in revision %s" % (
 
2624
                        filename, rev_tree.get_revision_id()))
2610
2625
        if filtered:
2611
2626
            from bzrlib.filters import (
2612
2627
                ContentFilterContext,
2698
2713
                    help="Refuse to commit if there are unknown "
2699
2714
                    "files in the working tree."),
2700
2715
             ListOption('fixes', type=str,
2701
 
                    help="Mark a bug as being fixed by this revision."),
 
2716
                    help="Mark a bug as being fixed by this revision "
 
2717
                         "(see \"bzr help bugs\")."),
2702
2718
             ListOption('author', type=unicode,
2703
2719
                    help="Set the author's name, if it's different "
2704
2720
                         "from the committer."),
2714
2730
             ]
2715
2731
    aliases = ['ci', 'checkin']
2716
2732
 
2717
 
    def _get_bug_fix_properties(self, fixes, branch):
2718
 
        properties = []
 
2733
    def _iter_bug_fix_urls(self, fixes, branch):
2719
2734
        # Configure the properties for bug fixing attributes.
2720
2735
        for fixed_bug in fixes:
2721
2736
            tokens = fixed_bug.split(':')
2722
2737
            if len(tokens) != 2:
2723
2738
                raise errors.BzrCommandError(
2724
 
                    "Invalid bug %s. Must be in the form of 'tag:id'. "
2725
 
                    "Commit refused." % fixed_bug)
 
2739
                    "Invalid bug %s. Must be in the form of 'tracker:id'. "
 
2740
                    "See \"bzr help bugs\" for more information on this "
 
2741
                    "feature.\nCommit refused." % fixed_bug)
2726
2742
            tag, bug_id = tokens
2727
2743
            try:
2728
 
                bug_url = bugtracker.get_bug_url(tag, branch, bug_id)
 
2744
                yield bugtracker.get_bug_url(tag, branch, bug_id)
2729
2745
            except errors.UnknownBugTrackerAbbreviation:
2730
2746
                raise errors.BzrCommandError(
2731
2747
                    'Unrecognized bug %s. Commit refused.' % fixed_bug)
2732
 
            except errors.MalformedBugIdentifier:
 
2748
            except errors.MalformedBugIdentifier, e:
2733
2749
                raise errors.BzrCommandError(
2734
 
                    "Invalid bug identifier for %s. Commit refused."
2735
 
                    % fixed_bug)
2736
 
            properties.append('%s fixed' % bug_url)
2737
 
        return '\n'.join(properties)
 
2750
                    "%s\nCommit refused." % (str(e),))
2738
2751
 
2739
2752
    def run(self, message=None, file=None, verbose=False, selected_list=None,
2740
2753
            unchanged=False, strict=False, local=False, fixes=None,
2767
2780
 
2768
2781
        if fixes is None:
2769
2782
            fixes = []
2770
 
        bug_property = self._get_bug_fix_properties(fixes, tree.branch)
 
2783
        bug_property = bugtracker.encode_fixes_bug_urls(
 
2784
            self._iter_bug_fix_urls(fixes, tree.branch))
2771
2785
        if bug_property:
2772
2786
            properties['bugs'] = bug_property
2773
2787
 
3342
3356
    """
3343
3357
 
3344
3358
    encoding_type = 'exact'
3345
 
    _see_also = ['update', 'remerge', 'status-flags']
 
3359
    _see_also = ['update', 'remerge', 'status-flags', 'send']
3346
3360
    takes_args = ['location?']
3347
3361
    takes_options = [
3348
3362
        'change',
3390
3404
            basis_tree = tree.revision_tree(tree.last_revision())
3391
3405
        except errors.NoSuchRevision:
3392
3406
            basis_tree = tree.basis_tree()
3393
 
        changes = tree.changes_from(basis_tree)
3394
 
        if changes.has_changed():
3395
 
            raise errors.UncommittedChanges(tree)
 
3407
        if not force:
 
3408
            changes = tree.changes_from(basis_tree)
 
3409
            if changes.has_changed():
 
3410
                raise errors.UncommittedChanges(tree)
3396
3411
 
3397
3412
        view_info = _get_view_info_for_change_reporter(tree)
3398
3413
        change_reporter = delta._ChangeReporter(
3811
3826
 
3812
3827
    OTHER_BRANCH may be local or remote.
3813
3828
 
3814
 
    To filter on a range of revirions, you can use the command -r begin..end
 
3829
    To filter on a range of revisions, you can use the command -r begin..end
3815
3830
    -r revision requests a specific revision, -r ..end or -r begin.. are
3816
3831
    also valid.
3817
3832
 
4729
4744
    default.  "0.9" uses revision bundle format 0.9 and merge directive
4730
4745
    format 1.  It is compatible with Bazaar 0.12 - 0.18.
4731
4746
 
4732
 
    Merge directives are applied using the merge command or the pull command.
 
4747
    The merge directives created by bzr send may be applied using bzr merge or
 
4748
    bzr pull by specifying a file containing a merge directive as the location.
4733
4749
    """
4734
4750
 
4735
4751
    encoding_type = 'exact'
4758
4774
               type=unicode),
4759
4775
        'revision',
4760
4776
        'message',
 
4777
        Option('body', help='Body for the email.', type=unicode),
4761
4778
        RegistryOption.from_kwargs('format',
4762
4779
        'Use the specified output format.',
4763
4780
        **{'4': 'Bundle format 4, Merge Directive 2 (default)',
4766
4783
 
4767
4784
    def run(self, submit_branch=None, public_branch=None, no_bundle=False,
4768
4785
            no_patch=False, revision=None, remember=False, output=None,
4769
 
            format='4', mail_to=None, message=None, **kwargs):
 
4786
            format='4', mail_to=None, message=None, body=None, **kwargs):
4770
4787
        return self._run(submit_branch, revision, public_branch, remember,
4771
4788
                         format, no_bundle, no_patch, output,
4772
 
                         kwargs.get('from', '.'), mail_to, message)
 
4789
                         kwargs.get('from', '.'), mail_to, message, body)
4773
4790
 
4774
4791
    def _run(self, submit_branch, revision, public_branch, remember, format,
4775
 
             no_bundle, no_patch, output, from_, mail_to, message):
 
4792
             no_bundle, no_patch, output, from_, mail_to, message, body):
4776
4793
        from bzrlib.revision import NULL_REVISION
4777
4794
        branch = Branch.open_containing(from_)[0]
4778
4795
        if output is None:
4790
4807
                if mail_to is None:
4791
4808
                    mail_to = config.get_user_option('submit_to')
4792
4809
                mail_client = config.get_mail_client()
 
4810
                if (not getattr(mail_client, 'supports_body', False)
 
4811
                    and body is not None):
 
4812
                    raise errors.BzrCommandError(
 
4813
                        'Mail client "%s" does not support specifying body' %
 
4814
                        mail_client.__class__.__name__)
4793
4815
            if remember and submit_branch is None:
4794
4816
                raise errors.BzrCommandError(
4795
4817
                    '--remember requires a branch to be specified.')
4872
4894
                    subject += revision.get_summary()
4873
4895
                basename = directive.get_disk_name(branch)
4874
4896
                mail_client.compose_merge_request(mail_to, subject,
4875
 
                                                  outfile.getvalue(), basename)
 
4897
                                                  outfile.getvalue(),
 
4898
                                                  basename, body)
4876
4899
        finally:
4877
4900
            if output != '-':
4878
4901
                outfile.close()
4946
4969
            output = '-'
4947
4970
        return self._run(submit_branch, revision, public_branch, remember,
4948
4971
                         format, no_bundle, no_patch, output,
4949
 
                         kwargs.get('from', '.'), None, None)
 
4972
                         kwargs.get('from', '.'), None, None, None)
4950
4973
 
4951
4974
 
4952
4975
class cmd_tag(Command):
5355
5378
 
5356
5379
 
5357
5380
class cmd_hooks(Command):
5358
 
    """Show a branch's currently registered hooks.
5359
 
    """
 
5381
    """Show hooks."""
5360
5382
 
5361
5383
    hidden = True
5362
 
    takes_args = ['path?']
5363
5384
 
5364
 
    def run(self, path=None):
5365
 
        if path is None:
5366
 
            path = '.'
5367
 
        branch_hooks = Branch.open(path).hooks
5368
 
        for hook_type in branch_hooks:
5369
 
            hooks = branch_hooks[hook_type]
5370
 
            self.outf.write("%s:\n" % (hook_type,))
5371
 
            if hooks:
5372
 
                for hook in hooks:
5373
 
                    self.outf.write("  %s\n" %
5374
 
                                    (branch_hooks.get_hook_name(hook),))
5375
 
            else:
5376
 
                self.outf.write("  <no hooks installed>\n")
 
5385
    def run(self):
 
5386
        for hook_key in sorted(hooks.known_hooks.keys()):
 
5387
            some_hooks = hooks.known_hooks_key_to_object(hook_key)
 
5388
            self.outf.write("%s:\n" % type(some_hooks).__name__)
 
5389
            for hook_name, hook_point in sorted(some_hooks.items()):
 
5390
                self.outf.write("  %s:\n" % (hook_name,))
 
5391
                found_hooks = list(hook_point)
 
5392
                if found_hooks:
 
5393
                    for hook in found_hooks:
 
5394
                        self.outf.write("    %s\n" %
 
5395
                                        (some_hooks.get_hook_name(hook),))
 
5396
                else:
 
5397
                    self.outf.write("    <no hooks installed>\n")
5377
5398
 
5378
5399
 
5379
5400
class cmd_shelve(Command):
5412
5433
                       value_switches=True, enum_switch=False),
5413
5434
 
5414
5435
        Option('list', help='List shelved changes.'),
 
5436
        Option('destroy',
 
5437
               help='Destroy removed changes instead of shelving them.'),
5415
5438
    ]
5416
5439
    _see_also = ['unshelve']
5417
5440
 
5418
5441
    def run(self, revision=None, all=False, file_list=None, message=None,
5419
 
            writer=None, list=False):
 
5442
            writer=None, list=False, destroy=False):
5420
5443
        if list:
5421
5444
            return self.run_for_list()
5422
5445
        from bzrlib.shelf_ui import Shelver
5424
5447
            writer = bzrlib.option.diff_writer_registry.get()
5425
5448
        try:
5426
5449
            Shelver.from_args(writer(sys.stdout), revision, all, file_list,
5427
 
                              message).run()
 
5450
                              message, destroy=destroy).run()
5428
5451
        except errors.UserAbort:
5429
5452
            return 0
5430
5453
 
5472
5495
        Unshelver.from_args(shelf_id, action).run()
5473
5496
 
5474
5497
 
 
5498
class cmd_clean_tree(Command):
 
5499
    """Remove unwanted files from working tree.
 
5500
 
 
5501
    By default, only unknown files, not ignored files, are deleted.  Versioned
 
5502
    files are never deleted.
 
5503
 
 
5504
    Another class is 'detritus', which includes files emitted by bzr during
 
5505
    normal operations and selftests.  (The value of these files decreases with
 
5506
    time.)
 
5507
 
 
5508
    If no options are specified, unknown files are deleted.  Otherwise, option
 
5509
    flags are respected, and may be combined.
 
5510
 
 
5511
    To check what clean-tree will do, use --dry-run.
 
5512
    """
 
5513
    takes_options = [Option('ignored', help='Delete all ignored files.'),
 
5514
                     Option('detritus', help='Delete conflict files, merge'
 
5515
                            ' backups, and failed selftest dirs.'),
 
5516
                     Option('unknown',
 
5517
                            help='Delete files unknown to bzr (default).'),
 
5518
                     Option('dry-run', help='Show files to delete instead of'
 
5519
                            ' deleting them.'),
 
5520
                     Option('force', help='Do not prompt before deleting.')]
 
5521
    def run(self, unknown=False, ignored=False, detritus=False, dry_run=False,
 
5522
            force=False):
 
5523
        from bzrlib.clean_tree import clean_tree
 
5524
        if not (unknown or ignored or detritus):
 
5525
            unknown = True
 
5526
        if dry_run:
 
5527
            force = True
 
5528
        clean_tree('.', unknown=unknown, ignored=ignored, detritus=detritus,
 
5529
                   dry_run=dry_run, no_prompt=force)
 
5530
 
 
5531
 
5475
5532
def _create_prefix(cur_transport):
5476
5533
    needed = [cur_transport]
5477
5534
    # Recurse upwards until we can create a directory successfully