26
__version__ = '0.18.0'
29
version_info = tuple(int(n) for n in __version__.split('.'))
32
def check_bzrlib_version(desired):
33
"""Check that bzrlib is compatible.
35
If version is < bzrtools version, assume incompatible.
36
If version == bzrtools version, assume completely compatible
37
If version == bzrtools version + 1, assume compatible, with deprecations
38
Otherwise, assume incompatible.
40
desired_plus = (desired[0], desired[1]+1)
41
bzrlib_version = bzrlib.version_info[:2]
42
if bzrlib_version == desired or (bzrlib_version == desired_plus and
43
bzrlib.version_info[3] == 'dev'):
46
from bzrlib.trace import warning
48
# get the message out any way we can
49
from warnings import warn as warning
50
if bzrlib_version < desired:
51
warning('Installed Bazaar version %s is too old to be used with'
53
'"Bzrtools" %s.' % (bzrlib.__version__, __version__))
54
# Not using BzrNewError, because it may not exist.
55
raise Exception, ('Version mismatch', version_info)
57
warning('Plugin "Bzrtools" is not up to date with installed Bazaar'
59
' There should be a newer version of Bzrtools available, e.g.'
61
% (bzrlib.__version__, bzrlib_version[0], bzrlib_version[1]))
62
if bzrlib_version != desired_plus:
63
raise Exception, 'Version mismatch'
66
check_bzrlib_version(version_info[:2])
68
25
from bzrlib.lazy_import import lazy_import
69
26
lazy_import(globals(), """
70
from bzrlib import help
27
from bzrlib import help, urlutils
31
from version import version_info, __version__
32
from command import BzrToolsCommand
74
33
from errors import CommandError, NoPyBaz
75
34
from patchsource import BzrPatchSource
79
38
import bzrlib.builtins
80
39
import bzrlib.commands
40
from bzrlib.branch import Branch
41
from bzrlib.bzrdir import BzrDir
81
42
from bzrlib.commands import get_cmd_object
82
43
from bzrlib.errors import BzrCommandError
83
44
import bzrlib.ignores
45
from bzrlib.trace import note
84
46
from bzrlib.option import Option
85
47
sys.path.insert(0, os.path.realpath(os.path.join(os.path.dirname(__file__),
51
from command import BzrToolsCommand
90
53
bzrlib.ignores.add_runtime_ignores(['./.shelf'])
93
class cmd_clean_tree(bzrlib.commands.Command):
56
class cmd_clean_tree(BzrToolsCommand):
94
57
"""Remove unwanted files from working tree.
96
59
By default, only unknown files, not ignored files, are deleted. Versioned
106
69
To check what clean-tree will do, use --dry-run.
108
takes_options = [Option('ignored', help='delete all ignored files.'),
109
Option('detritus', help='delete conflict files, merge'
71
takes_options = [Option('ignored', help='Delete all ignored files.'),
72
Option('detritus', help='Delete conflict files, merge'
110
73
' backups, and failed selftest dirs.'),
112
help='delete files unknown to bzr. (default)'),
113
Option('dry-run', help='show files to delete instead of'
75
help='Delete files unknown to bzr (default).'),
76
Option('dry-run', help='Show files to delete instead of'
114
77
' deleting them.')]
115
78
def run(self, unknown=False, ignored=False, detritus=False, dry_run=False):
116
79
from clean_tree import clean_tree
156
119
be disabled with --no-antialias.
158
121
takes_args = ['file', 'merge_branch?']
159
takes_options = [Option('no-collapse', help="Do not skip simple nodes"),
122
takes_options = [Option('no-collapse', help="Do not skip simple nodes."),
160
123
Option('no-antialias',
161
help="Do not use rsvg to produce antialiased output"),
124
help="Do not use rsvg to produce antialiased output."),
162
125
Option('merge-branch', type=str,
163
help="Use this branch to calcuate a merge base"),
126
help="Use this branch to calcuate a merge base."),
164
127
Option('cluster', help="Use clustered output."),
165
128
Option('max-distance',
166
help="Show no nodes farther than this", type=int),
129
help="Show no nodes farther than this.", type=int),
167
130
Option('directory',
168
131
help='Source branch to use (default is current'
185
148
max_distance=max_distance)
188
class cmd_fetch_ghosts(bzrlib.commands.Command):
151
class cmd_fetch_ghosts(BzrToolsCommand):
189
152
"""Attempt to retrieve ghosts from another branch.
190
153
If the other branch is not supplied, the last-pulled branch is used.
192
155
aliases = ['fetch-missing']
193
156
takes_args = ['branch?']
194
takes_options = [Option('no-fix')]
157
takes_options = [Option('no-fix', help="Skip additional synchonization.")]
195
158
def run(self, branch=None, no_fix=False):
196
159
from fetch_ghosts import fetch_ghosts
197
160
fetch_ghosts(branch, no_fix)
200
163
each file name found in the patch file."""
203
class cmd_patch(bzrlib.commands.Command):
166
class cmd_patch(BzrToolsCommand):
204
167
"""Apply a named patch to the current tree.
206
169
takes_args = ['filename?']
207
170
takes_options = [Option('strip', type=int, help=strip_help),
208
Option('silent', help='Suppress chatter')]
171
Option('silent', help='Suppress chatter.')]
209
172
def run(self, filename=None, strip=None, silent=False):
210
173
from patch import patch
211
174
from bzrlib.workingtree import WorkingTree
215
178
return patch(wt, filename, strip, silent)
218
class cmd_shelve(bzrlib.commands.Command):
181
class cmd_shelve(BzrToolsCommand):
219
182
"""Temporarily set aside some changes from the current tree.
221
184
Shelve allows you to temporarily put changes you've made "on the shelf",
248
211
takes_args = ['file*']
249
takes_options = ['message', 'revision',
250
Option('all', help='Shelve all changes without prompting'),
251
Option('no-color', help='Never display changes in color')]
212
takes_options = [Option('message',
213
help='A message to associate with the shelved changes.',
214
short_name='m', type=unicode),
216
Option('all', help='Shelve all changes without prompting.'),
217
Option('no-color', help='Never display changes in color.')]
253
219
def run(self, all=False, file_list=None, message=None, revision=None,
382
348
See 'shelve' for more information.
384
350
takes_options = [
385
Option('all', help='Unshelve all changes without prompting'),
386
Option('force', help='Force unshelving even if errors occur'),
387
Option('no-color', help='Never display changes in color')
351
Option('all', help='Unshelve all changes without prompting.'),
352
Option('force', help='Force unshelving even if errors occur.'),
353
Option('no-color', help='Never display changes in color.')
389
355
takes_args = ['patch?']
390
356
def run(self, patch=None, all=False, force=False, no_color=False):
397
class cmd_shell(bzrlib.commands.Command):
363
class cmd_shell(BzrToolsCommand):
398
364
"""Begin an interactive shell tailored for bzr.
399
365
Bzr commands can be used without typing bzr first, and will be run natively
400
366
when possible. Tab completion is tailored for bzr. The shell prompt shows
442
408
If --branch is specified, the branch will be deleted too, but only if the
443
409
the branch has no new commits (relative to its parent).
445
takes_options = [Option("branch", help="Remove associtated branch from"
411
takes_options = [Option("branch", help="Remove associated branch from"
413
Option('force', help='Delete tree even if contents are'
447
415
takes_args = ["checkout"]
448
def run(self, checkout, branch=False):
416
def run(self, checkout, branch=False, force=False):
449
417
from zap import zap
450
return zap(checkout, remove_branch=branch)
453
class cmd_cbranch(bzrlib.commands.Command):
418
return zap(checkout, remove_branch=branch, allow_modified=force)
421
class cmd_cbranch(BzrToolsCommand):
455
423
Create a new checkout, associated with a new repository branch.
472
440
takes_options = [Option("lightweight",
473
help="Create a lightweight checkout"), 'revision']
441
help="Create a lightweight checkout."), 'revision',
442
Option('files-from', type=unicode,
443
help='Accelerate checkout using files from this'
474
445
takes_args = ["source", "target?"]
475
def run(self, source, target=None, lightweight=False, revision=None):
446
def run(self, source, target=None, lightweight=False, revision=None,
476
448
from cbranch import cbranch
477
449
return cbranch(source, target, lightweight=lightweight,
481
class cmd_branches(bzrlib.commands.Command):
450
revision=revision, files_from=files_from)
453
class cmd_branches(BzrToolsCommand):
482
454
"""Scan a location for branches"""
483
455
takes_args = ["location?"]
484
456
def run(self, location=None):
485
457
from branches import branches
486
458
return branches(location)
460
class cmd_trees(BzrToolsCommand):
461
"""Scan a location for trees"""
462
takes_args = ['location?']
463
def run(self, location='.'):
464
from bzrlib.workingtree import WorkingTree
465
from bzrlib.transport import get_transport
466
t = get_transport(location)
467
for tree in WorkingTree.find_trees(location):
468
self.outf.write('%s\n' % t.relpath(
469
tree.bzrdir.root_transport.base))
489
class cmd_multi_pull(bzrlib.commands.Command):
471
class cmd_multi_pull(BzrToolsCommand):
490
472
"""Pull all the branches under a location, e.g. a repository.
492
474
Both branches present in the directory and the branches of checkouts are
495
477
takes_args = ["location?"]
496
478
def run(self, location=None):
497
from bzrlib.branch import Branch
498
479
from bzrlib.transport import get_transport
499
480
from bzrtools import iter_branch_tree
500
481
if location is None:
502
483
t = get_transport(location)
484
possible_transports = []
503
485
if not t.listable():
504
486
print "Can't list this type of location."
522
504
print "Pulling %s from %s" % (relpath, parent)
524
pullable.pull(Branch.open(parent))
506
branch_t = get_transport(parent, possible_transports)
507
pullable.pull(Branch.open_from_transport(branch_t))
525
508
except Exception, e:
529
class cmd_branch_mark(bzrlib.commands.Command):
531
Add, view or list branch markers <EXPERIMENTAL>
533
To add a mark, do 'bzr branch-mark MARK'.
534
To list marks, do 'bzr branch-mark' (this lists all marks for the branch's
536
To delete a mark, do 'bzr branch-mark --delete MARK'
538
These marks can be used to track a branch's status.
540
takes_args = ['mark?', 'branch?']
541
takes_options = [Option('delete', help='Delete this mark')]
542
def run(self, mark=None, branch=None, delete=False):
543
from branch_mark import branch_mark
544
branch_mark(mark, branch, delete)
547
class cmd_import(bzrlib.commands.Command):
513
class cmd_import(BzrToolsCommand):
548
514
"""Import sources from a directory, tarball or zip file
550
516
This command will import a directory, tarball or zip file into a bzr
564
530
do_import(source, tree)
567
class cmd_cdiff(bzrlib.commands.Command):
533
class cmd_cdiff(BzrToolsCommand):
568
534
"""A color version of bzr's diff"""
569
535
takes_args = property(lambda x: get_cmd_object('diff').takes_args)
571
def _takes_options(self):
572
options = list(get_cmd_object('diff').takes_options)
573
options.append(Option('check-style',
536
takes_options = list(get_cmd_object('diff').takes_options) + [
537
Option('check-style',
574
538
help='Warn if trailing whitespace or spurious changes have been'
578
takes_options = property(_takes_options)
580
541
def run(self, check_style=False, *args, **kwargs):
581
542
from colordiff import colordiff
582
543
colordiff(check_style, *args, **kwargs)
585
class cmd_baz_import(bzrlib.commands.Command):
546
class cmd_baz_import(BzrToolsCommand):
586
547
"""Import an Arch or Baz archive into a bzr repository.
588
549
This command should be used on local archives (or mirrors) only. It is
610
571
takes_args = ['to_root_dir', 'from_archive', 'reuse_history*']
611
572
takes_options = ['verbose', Option('prefixes', type=str,
612
help="Prefixes of branches to import, colon-separated"),
573
help="Prefixes of branches to import, colon-separated."),
613
574
Option('encoding', type=str,
614
575
help='Force encoding to specified value. See WARNING.')]
624
585
print "This command is disabled. Please install PyBaz."
627
class cmd_baz_import_branch(bzrlib.commands.Command):
588
class cmd_baz_import_branch(BzrToolsCommand):
628
589
"""Import an Arch or Baz branch into a bzr branch.
630
591
WARNING: Encoding should not be specified unless necessary, because if you
635
596
are incompatible.
637
598
takes_args = ['to_location', 'from_branch?', 'reuse_history*']
638
takes_options = ['verbose', Option('max-count', type=int),
599
takes_options = ['verbose',
600
Option('max-count', type=int,
601
help='Maximim revisions to import at once.'),
639
602
Option('encoding', type=str,
640
603
help='Force encoding to specified value. See WARNING.')]
652
615
print "This command is disabled. Please install PyBaz."
655
class cmd_rspush(bzrlib.commands.Command):
618
class cmd_rspush(BzrToolsCommand):
656
619
"""Upload this branch to another location using rsync.
658
621
If no location is specified, the last-used location will be used. To
663
626
takes_args = ['location?']
664
627
takes_options = [Option('overwrite', help='Ignore differences between'
665
' branches and overwrite unconditionally'),
628
' branches and overwrite unconditionally.'),
666
629
Option('no-tree', help='Do not push the working tree,'
667
630
' just the .bzr.')]
674
637
working_tree=not no_tree)
677
class cmd_switch(bzrlib.commands.Command):
678
"""Set the branch of a lightweight checkout and update."""
680
takes_args = ['to_location']
682
def run(self, to_location):
683
from switch import cmd_switch
684
cmd_switch().run(to_location)
689
642
cmd_baz_import_branch,
691
645
cmd_branch_history,