1
# Copyright (C) 2005, 2006, 2007 Aaron Bentley <aaron@aaronbentley.com>
2
# Copyright (C) 2005, 2006 Canonical Limited.
1
# Copyright (C) 2005, 2006, 2007, 2011 Aaron Bentley <aaron@aaronbentley.com>
2
# Copyright (C) 2005, 2006, 2011 Canonical Limited.
3
3
# Copyright (C) 2006 Michael Ellerman.
5
5
# This program is free software; you can redistribute it and/or modify
21
21
from bzrlib.lazy_import import lazy_import
22
22
lazy_import(globals(), """
23
23
from bzrlib import help, urlutils
24
from bzrlib.plugins.bzrtools import shelf
27
from bzrlib.plugins import bzrtools
27
28
from command import BzrToolsCommand
28
29
from errors import CommandError
29
30
from patchsource import BzrPatchSource
33
import bzrlib.builtins
34
32
import bzrlib.commands
35
33
from bzrlib.branch import Branch
36
from bzrlib.bzrdir import BzrDir
37
34
from bzrlib.commands import get_cmd_object
38
35
from bzrlib.errors import BzrCommandError
40
from bzrlib.trace import note
41
from bzrlib.option import Option
43
from command import BzrToolsCommand
46
class cmd_clean_tree(BzrToolsCommand):
47
"""Remove unwanted files from working tree.
49
By default, only unknown files, not ignored files, are deleted. Versioned
50
files are never deleted.
52
Another class is 'detritus', which includes files emitted by bzr during
53
normal operations and selftests. (The value of these files decreases with
56
If no options are specified, unknown files are deleted. Otherwise, option
57
flags are respected, and may be combined.
59
To check what clean-tree will do, use --dry-run.
61
takes_options = [Option('ignored', help='Delete all ignored files.'),
62
Option('detritus', help='Delete conflict files, merge'
63
' backups, and failed selftest dirs.'),
65
help='Delete files unknown to bzr (default).'),
66
Option('dry-run', help='Show files to delete instead of'
68
Option('force', help='Do not prompt before deleting.')]
69
def run(self, unknown=False, ignored=False, detritus=False, dry_run=False,
71
from clean_tree import clean_tree
72
if not (unknown or ignored or detritus):
76
clean_tree('.', unknown=unknown, ignored=ignored, detritus=detritus,
77
dry_run=dry_run, no_prompt=force)
36
from bzrlib.option import Option, RegistryOption
80
39
class cmd_graph_ancestry(BzrToolsCommand):
81
40
"""Produce ancestry graphs using dot.
83
42
Output format is detected according to file extension. Some of the more
84
43
common output formats are html, png, gif, svg, ps. An extension of '.dot'
85
44
will cause a dot graph file to be produced. HTML output has mouseovers
151
110
takes_options = [Option('no-fix', help="Skip additional synchonization.")]
152
111
def run(self, branch=None, no_fix=False):
153
112
from fetch_ghosts import fetch_ghosts
154
fetch_ghosts(branch, no_fix)
113
fetch_ghosts(branch, do_reconcile=not no_fix)
156
115
strip_help="""Strip the smallest prefix containing num leading slashes from \
157
116
each file name found in the patch file."""
161
120
"""Apply a named patch to the current tree.
163
122
takes_args = ['filename?']
164
takes_options = [Option('strip', type=int, help=strip_help),
123
takes_options = [Option('strip', type=int, short_name='p',
165
125
Option('silent', help='Suppress chatter.')]
166
126
def run(self, filename=None, strip=None, silent=False):
167
127
from patch import patch
374
332
--all --help --revision --show-ids
375
333
bzr bzrtools:287/> status --
337
help='Branch in which to start the shell, '
338
'rather than the one containing the working directory.',
343
def run(self, directory=None):
379
return shell.run_shell()
345
return shell.run_shell(directory)
382
348
class cmd_branch_history(BzrToolsCommand):
404
370
If --branch is specified, the branch will be deleted too, but only if the
405
371
the branch has no new commits (relative to its parent).
373
If bzr-pipeline is also installed, the --store option will store changes
374
in the branch before deleting the tree. To restore the changes, do::
376
bzr checkout --lightweight $BRANCH $CHECKOUT
377
bzr switch-pipe -d $CHECKOUT `bzr nick -d $CHECKOUT`
407
379
takes_options = [Option("branch", help="Remove associated branch from"
409
Option('force', help='Delete tree even if contents are'
381
RegistryOption('change_policy',
382
'How to handle changed files',
384
('bzrlib.plugins.bzrtools.zap',
385
'change_policy_registry'),
411
388
takes_args = ["checkout"]
412
def run(self, checkout, branch=False, force=False):
414
return zap(checkout, remove_branch=branch, allow_modified=force)
389
def run(self, checkout, branch=False, change_policy=None):
391
change_policy_registry,
395
if change_policy is None:
396
change_policy = change_policy_registry.get()
397
if change_policy is StoreChanges:
399
import bzrlib.plugins.pipeline
401
raise BzrCommandError('--store requires bzr-pipeline.')
402
return zap(checkout, remove_branch=branch, policy=change_policy)
417
405
class cmd_cbranch(BzrToolsCommand):
450
438
hardlink=hardlink)
453
class cmd_branches(BzrToolsCommand):
441
class cmd_list_branches(BzrToolsCommand):
454
442
"""Scan a location for branches"""
445
from bzrlib import commands
446
return commands.plugin_cmds.get_info('list-branches').aliases
455
448
takes_args = ["location?"]
456
449
def run(self, location=None):
457
450
from branches import branches
534
527
"""A color version of bzr's diff"""
535
528
takes_args = property(lambda x: get_cmd_object('diff').takes_args)
536
529
takes_options = list(get_cmd_object('diff').takes_options) + [
530
RegistryOption.from_kwargs('color',
531
'Color mode to use.',
532
title='Color Mode', value_switches=False, enum_switch=True,
533
never='Never colorize output.',
534
auto='Only colorize output if terminal supports it and STDOUT is a'
536
always='Always colorize output (default).'),
537
537
Option('check-style',
538
538
help='Warn if trailing whitespace or spurious changes have been'
541
def run(self, check_style=False, *args, **kwargs):
541
def run(self, color='always', check_style=False, *args, **kwargs):
542
542
from colordiff import colordiff
543
colordiff(check_style, *args, **kwargs)
543
colordiff(color, check_style, *args, **kwargs)
546
class cmd_conflict_diff(BzrToolsCommand):
548
"""Compare a conflicted file against BASE."""
550
encoding_type = 'exact'
551
takes_args = ['file*']
553
RegistryOption.from_kwargs('direction', 'Direction of comparison.',
554
value_switches=True, enum_switch=False,
555
other='Compare OTHER against common base.',
556
this='Compare THIS against common base.')]
558
def run(self, file_list, direction='other'):
559
from bzrlib.plugins.bzrtools.colordiff import DiffWriter
560
from conflict_diff import ConflictDiffer
561
dw = DiffWriter(self.outf, check_style=False, color='auto')
562
ConflictDiffer().run(dw, file_list, direction)
546
565
class cmd_rspush(BzrToolsCommand):
588
607
target_tree.unlock()
590
from heads import cmd_heads
610
class cmd_create_mirror(BzrToolsCommand):
611
"""Create a mirror of another branch.
613
This is similar to `bzr branch`, but copies more settings, including the
614
submit branch and nickname.
616
It sets the public branch and parent of the target to the source location.
619
takes_args = ['source', 'target']
621
def run(self, source, target):
622
source_branch = Branch.open(source)
623
from bzrlib.plugins.bzrtools.mirror import create_mirror
624
create_mirror(source_branch, target, [])