~abentley/bzrtools/bzrtools.dev

0.1.22 by Michael Ellerman
Add __init__.py, put cmd_shelve/unshelve in there.
1
#!/usr/bin/python
246 by Aaron Bentley
Merged shelf_v2
2
"""\
3
Various useful plugins for working with bzr.
4
"""
364.1.4 by Aaron Bentley
Changed rpush to rspush
5
import rspush
0.1.73 by Michael Ellerman
Merge most of the standalone shelf branch. This brings in a few changes which
6
from errors import CommandError
7
from patchsource import BzrPatchSource
246 by Aaron Bentley
Merged shelf_v2
8
from shelf import Shelf
360.1.1 by Aaron Bentley
Add switch command
9
from switch import cmd_switch
246 by Aaron Bentley
Merged shelf_v2
10
import sys
11
import os.path
399 by Aaron Bentley
Implement cdiff (based on old Fai code)
12
13
from bzrlib import DEFAULT_IGNORE
14
import bzrlib.builtins
0.1.22 by Michael Ellerman
Add __init__.py, put cmd_shelve/unshelve in there.
15
import bzrlib.branch
399 by Aaron Bentley
Implement cdiff (based on old Fai code)
16
import bzrlib.commands
410 by Aaron Bentley
Ensure the option settings come from the right 'diff' in colordiff
17
from bzrlib.commands import get_cmd_object
0.1.39 by Michael Ellerman
Fix shelve and unshelve to pass location to Shelf().
18
from bzrlib.errors import BzrCommandError
399 by Aaron Bentley
Implement cdiff (based on old Fai code)
19
from bzrlib.help import command_usage
20
from bzrlib.option import Option
147.1.41 by Aaron Bentley
Merge from mainline
21
sys.path.insert(0, os.path.realpath(os.path.join(os.path.dirname(__file__), 
147.4.37 by Robert Collins
Convert push to rpush.
22
                                                 "external")))
0.1.73 by Michael Ellerman
Merge most of the standalone shelf branch. This brings in a few changes which
23
325.1.2 by Aaron Bentley
Merge shelf v2
24
0.1.73 by Michael Ellerman
Merge most of the standalone shelf branch. This brings in a few changes which
25
DEFAULT_IGNORE.append('./.shelf')
0.1.93 by Michael Ellerman
Keep ignoring .bzr-shelf* so as not to suprise people
26
DEFAULT_IGNORE.append('./.bzr-shelf*')
0.1.73 by Michael Ellerman
Merge most of the standalone shelf branch. This brings in a few changes which
27
246 by Aaron Bentley
Merged shelf_v2
28
29
class cmd_clean_tree(bzrlib.commands.Command):
342 by Aaron Bentley
Tagged BZRTOOLS commands to reduce confusion
30
    """Remove unwanted files from working tree.  <BZRTOOLS>
246 by Aaron Bentley
Merged shelf_v2
31
    Normally, ignored files are left alone.
32
    """
386 by Aaron Bentley
Stop adding global options
33
    takes_options = [Option('ignored', help='delete all ignored files.'), 
34
                     Option('detritus', help='delete conflict files merge'
35
                            ' backups, and failed selftest dirs.  (*.THIS, '
36
                            '*.BASE, *.OTHER, *~, *.tmp)'), 
37
                     Option('dry-run', help='show files to delete instead of'
38
                            ' deleting them.')]
265 by Aaron Bentley
Fixed spelling of detritus
39
    def run(self, ignored=False, detritus=False, dry_run=False):
246 by Aaron Bentley
Merged shelf_v2
40
        from clean_tree import clean_tree
265 by Aaron Bentley
Fixed spelling of detritus
41
        clean_tree('.', ignored=ignored, detritus=detritus, dry_run=dry_run)
246 by Aaron Bentley
Merged shelf_v2
42
43
class cmd_graph_ancestry(bzrlib.commands.Command):
342 by Aaron Bentley
Tagged BZRTOOLS commands to reduce confusion
44
    """Produce ancestry graphs using dot.  <BZRTOOLS>
246 by Aaron Bentley
Merged shelf_v2
45
    
46
    Output format is detected according to file extension.  Some of the more
296 by Aaron Bentley
Updated graph-ancestry help
47
    common output formats are html, png, gif, svg, ps.  An extension of '.dot'
48
    will cause a dot graph file to be produced.  HTML output has mouseovers
49
    that show the commit message.
246 by Aaron Bentley
Merged shelf_v2
50
51
    Branches are labeled r?, where ? is the revno.  If they have no revno,
52
    with the last 5 characters of their revision identifier are used instead.
296 by Aaron Bentley
Updated graph-ancestry help
53
54
    The value starting with d is "(maximum) distance from the null revision".
246 by Aaron Bentley
Merged shelf_v2
55
    
56
    If --merge-branch is specified, the two branches are compared and a merge
57
    base is selected.
58
    
59
    Legend:
60
    white    normal revision
61
    yellow   THIS  history
62
    red      OTHER history
63
    orange   COMMON history
64
    blue     COMMON non-history ancestor
296 by Aaron Bentley
Updated graph-ancestry help
65
    green    Merge base (COMMON ancestor farthest from the null revision)
66
    dotted   Ghost revision (missing from branch storage)
246 by Aaron Bentley
Merged shelf_v2
67
296 by Aaron Bentley
Updated graph-ancestry help
68
    Ancestry is usually collapsed by skipping revisions with a single parent
246 by Aaron Bentley
Merged shelf_v2
69
    and descendant.  The number of skipped revisions is shown on the arrow.
70
    This feature can be disabled with --no-collapse.
71
72
    By default, revisions are ordered by distance from root, but they can be
73
    clustered instead using --cluster.
74
75
    If available, rsvg is used to antialias PNG and JPEG output, but this can
76
    be disabled with --no-antialias.
77
    """
78
    takes_args = ['branch', 'file']
296 by Aaron Bentley
Updated graph-ancestry help
79
    takes_options = [Option('no-collapse', help="Do not skip simple nodes"), 
80
                     Option('no-antialias',
81
                     help="Do not use rsvg to produce antialiased output"), 
82
                     Option('merge-branch', type=str, 
83
                     help="Use this branch to calcuate a merge base"), 
84
                     Option('cluster', help="Use clustered output.")]
246 by Aaron Bentley
Merged shelf_v2
85
    def run(self, branch, file, no_collapse=False, no_antialias=False,
86
        merge_branch=None, cluster=False):
87
        import graph
88
        if cluster:
89
            ranking = "cluster"
90
        else:
91
            ranking = "forced"
92
        graph.write_ancestry_file(branch, file, not no_collapse, 
93
                                  not no_antialias, merge_branch, ranking)
94
95
class cmd_fetch_ghosts(bzrlib.commands.Command):
342 by Aaron Bentley
Tagged BZRTOOLS commands to reduce confusion
96
    """Attempt to retrieve ghosts from another branch.  <BZRTOOLS>
246 by Aaron Bentley
Merged shelf_v2
97
    If the other branch is not supplied, the last-pulled branch is used.
98
    """
99
    aliases = ['fetch-missing']
100
    takes_args = ['branch?']
275.1.3 by Daniel Silverstone
Fix up fetch_ghosts to lock the branches, and to invoke bzr fix if it fetches any ghosts into the tree
101
    takes_options = [Option('no-fix')]
102
    def run(self, branch=None, no_fix=False):
246 by Aaron Bentley
Merged shelf_v2
103
        from fetch_ghosts import fetch_ghosts
275.1.3 by Daniel Silverstone
Fix up fetch_ghosts to lock the branches, and to invoke bzr fix if it fetches any ghosts into the tree
104
        fetch_ghosts(branch, no_fix)
246 by Aaron Bentley
Merged shelf_v2
105
106
strip_help="""Strip the smallest prefix containing num leading slashes  from \
107
each file name found in the patch file."""
321.2.1 by ghigo
add support for bazaar diff
108
Option.OPTIONS['bzrdiff'] = Option('bzrdiff',type=None,
109
                                help="""Handle extra bzr tags""")
246 by Aaron Bentley
Merged shelf_v2
110
class cmd_patch(bzrlib.commands.Command):
342 by Aaron Bentley
Tagged BZRTOOLS commands to reduce confusion
111
    """Apply a named patch to the current tree.  <BZRTOOLS>
246 by Aaron Bentley
Merged shelf_v2
112
    """
113
    takes_args = ['filename?']
386 by Aaron Bentley
Stop adding global options
114
    takes_options = [Option('strip', type=int, help=strip_help)]
321.2.1 by ghigo
add support for bazaar diff
115
    def run(self, filename=None, strip=-1, bzrdiff=0):
246 by Aaron Bentley
Merged shelf_v2
116
        from patch import patch
340 by Aaron Bentley
Fixed patch on checkouts
117
        from bzrlib.workingtree import WorkingTree
118
        wt = WorkingTree.open_containing('.')[0]
321.2.1 by ghigo
add support for bazaar diff
119
        if strip == -1:
120
            if bzrdiff: strip = 0
369 by Aaron Bentley
Treat patches as p0 by default
121
            else:       strip = 0
321.2.1 by ghigo
add support for bazaar diff
122
340 by Aaron Bentley
Fixed patch on checkouts
123
        return patch(wt, filename, strip, legacy= not bzrdiff)
246 by Aaron Bentley
Merged shelf_v2
124
0.1.73 by Michael Ellerman
Merge most of the standalone shelf branch. This brings in a few changes which
125
class cmd_shelve(bzrlib.commands.Command):
342 by Aaron Bentley
Tagged BZRTOOLS commands to reduce confusion
126
    """Temporarily set aside some changes from the current tree.  <BZRTOOLS>
0.1.73 by Michael Ellerman
Merge most of the standalone shelf branch. This brings in a few changes which
127
128
    Shelve allows you to temporarily put changes you've made "on the shelf",
129
    ie. out of the way, until a later time when you can bring them back from
130
    the shelf with the 'unshelve' command.
131
289 by Aaron Bentley
Updated shelf help
132
    Shelve is intended to help separate several sets of text changes that have
133
    been inappropriately mingled.  If you just want to get rid of all changes
134
    (text and otherwise) and you don't need to restore them later, use revert.
135
    If you want to shelve all text changes at once, use shelve --all.
136
0.1.90 by Michael Ellerman
Update help text to try and be clearer, some stolen from bzrtools.
137
    By default shelve asks you what you want to shelve, press '?' at the
138
    prompt to get help. To shelve everything run shelve --all.
139
0.1.73 by Michael Ellerman
Merge most of the standalone shelf branch. This brings in a few changes which
140
    If filenames are specified, only the changes to those files will be
141
    shelved, other files will be left untouched.
142
143
    If a revision is specified, changes since that revision will be shelved.
0.1.113 by Michael Ellerman
Support for unshelving in arbitrary order.
144
145
    You can put multiple items on the shelf. Normally each time you run
146
    unshelve the most recently shelved changes will be reinstated. However,
147
    you can also unshelve changes in a different order by explicitly
148
    specifiying which changes to unshelve. This works best when the changes
149
    don't depend on each other.
0.1.90 by Michael Ellerman
Update help text to try and be clearer, some stolen from bzrtools.
150
    """
0.1.73 by Michael Ellerman
Merge most of the standalone shelf branch. This brings in a few changes which
151
152
    takes_args = ['file*']
0.1.90 by Michael Ellerman
Update help text to try and be clearer, some stolen from bzrtools.
153
    takes_options = ['message', 'revision',
154
            Option('all', help='Shelve all changes without prompting')]
155
0.1.80 by Michael Ellerman
After extensive user testing, ie. me using it, I've decided --pick should be
156
    def run(self, all=False, file_list=None, message=None, revision=None):
0.1.73 by Michael Ellerman
Merge most of the standalone shelf branch. This brings in a few changes which
157
        if revision is not None and revision:
158
            if len(revision) == 1:
159
                revision = revision[0]
160
            else:
161
                raise CommandError("shelve only accepts a single revision "
162
                                  "parameter.")
163
164
        source = BzrPatchSource(revision, file_list)
0.1.74 by Michael Ellerman
Adapt to BzrDir changes and deprecation of show_diff().
165
        s = Shelf(source.base)
0.1.80 by Michael Ellerman
After extensive user testing, ie. me using it, I've decided --pick should be
166
        s.shelve(source, all, message)
0.1.73 by Michael Ellerman
Merge most of the standalone shelf branch. This brings in a few changes which
167
        return 0
168
0.1.109 by Michael Ellerman
Hijack the bzr command infrastructure to do subcommands for 'shelf'.
169
170
# The following classes are only used as subcommands for 'shelf', they're
171
# not to be registered directly with bzr.
172
173
class cmd_shelf_list(bzrlib.commands.Command):
174
    """List the patches on the current shelf."""
175
    aliases = ['list', 'ls']
176
    def run(self):
177
        self.shelf.list()
178
179
180
class cmd_shelf_delete(bzrlib.commands.Command):
181
    """Delete the patch from the current shelf."""
182
    aliases = ['delete', 'del']
183
    takes_args = ['patch']
184
    def run(self, patch):
185
        self.shelf.delete(patch)
186
187
188
class cmd_shelf_switch(bzrlib.commands.Command):
189
    """Switch to the other shelf, create it if necessary."""
190
    aliases = ['switch']
0.1.117 by Michael Ellerman
Arg names with hyphens don't seem to work (broke shelf switch).
191
    takes_args = ['othershelf']
192
    def run(self, othershelf):
193
        s = Shelf(self.shelf.base, othershelf)
0.1.109 by Michael Ellerman
Hijack the bzr command infrastructure to do subcommands for 'shelf'.
194
        s.make_default()
195
196
197
class cmd_shelf_show(bzrlib.commands.Command):
0.1.110 by Michael Ellerman
Make the patch argument to 'shelf show' optional.
198
    """Show the contents of the specified or topmost patch."""
0.1.109 by Michael Ellerman
Hijack the bzr command infrastructure to do subcommands for 'shelf'.
199
    aliases = ['show', 'cat', 'display']
0.1.110 by Michael Ellerman
Make the patch argument to 'shelf show' optional.
200
    takes_args = ['patch?']
201
    def run(self, patch=None):
0.1.109 by Michael Ellerman
Hijack the bzr command infrastructure to do subcommands for 'shelf'.
202
        self.shelf.display(patch)
203
204
205
class cmd_shelf_upgrade(bzrlib.commands.Command):
206
    """Upgrade old format shelves."""
207
    aliases = ['upgrade']
208
    def run(self):
209
        self.shelf.upgrade()
210
211
0.1.73 by Michael Ellerman
Merge most of the standalone shelf branch. This brings in a few changes which
212
class cmd_shelf(bzrlib.commands.Command):
0.1.109 by Michael Ellerman
Hijack the bzr command infrastructure to do subcommands for 'shelf'.
213
    """Perform various operations on your shelved patches. See also shelve."""
0.1.73 by Michael Ellerman
Merge most of the standalone shelf branch. This brings in a few changes which
214
    takes_args = ['subcommand', 'args*']
215
0.1.109 by Michael Ellerman
Hijack the bzr command infrastructure to do subcommands for 'shelf'.
216
    subcommands = [cmd_shelf_list, cmd_shelf_delete, cmd_shelf_switch,
217
        cmd_shelf_show, cmd_shelf_upgrade]
218
0.1.73 by Michael Ellerman
Merge most of the standalone shelf branch. This brings in a few changes which
219
    def run(self, subcommand, args_list):
220
        import sys
221
0.1.109 by Michael Ellerman
Hijack the bzr command infrastructure to do subcommands for 'shelf'.
222
        cmd = self._get_cmd_object(subcommand)
0.1.73 by Michael Ellerman
Merge most of the standalone shelf branch. This brings in a few changes which
223
        source = BzrPatchSource()
0.1.74 by Michael Ellerman
Adapt to BzrDir changes and deprecation of show_diff().
224
        s = Shelf(source.base)
0.1.109 by Michael Ellerman
Hijack the bzr command infrastructure to do subcommands for 'shelf'.
225
        cmd.shelf = s
226
        return cmd.run_argv_aliases(args_list)
227
228
    def _get_cmd_object(self, cmd_name):
229
        for cmd_class in self.subcommands:
230
            for alias in cmd_class.aliases:
231
                if alias == cmd_name:
232
                    return cmd_class()
233
        raise CommandError("Unknown shelf subcommand '%s'" % cmd_name)
234
235
    def help(self):
0.1.111 by Michael Ellerman
Make help for subcommands more readable, print options in help also.
236
        text = ["%s\n\nSubcommands:\n" % self.__doc__]
0.1.109 by Michael Ellerman
Hijack the bzr command infrastructure to do subcommands for 'shelf'.
237
238
        for cmd_class in self.subcommands:
0.1.111 by Michael Ellerman
Make help for subcommands more readable, print options in help also.
239
            text.extend(self.sub_help(cmd_class) + ['\n'])
240
241
        return ''.join(text)
242
243
    def sub_help(self, cmd_class):
244
        text = []
245
        cmd_obj = cmd_class()
246
        indent = 2 * ' '
247
248
        usage = command_usage(cmd_obj)
249
        usage = usage.replace('bzr shelf-', '')
250
        text.append('%s%s\n' % (indent, usage))
251
252
        text.append('%s%s\n' % (2 * indent, cmd_class.__doc__))
253
254
        # Somewhat copied from bzrlib.help.help_on_command_options
255
        option_help = []
256
        for option_name, option in sorted(cmd_obj.options().items()):
257
            if option_name == 'help':
258
                continue
259
            option_help.append('%s--%s' % (3 * indent, option_name))
260
            if option.type is not None:
261
                option_help.append(' %s' % option.argname.upper())
262
            if option.short_name():
263
                option_help.append(', -%s' % option.short_name())
264
            option_help.append('%s%s\n' % (2 * indent, option.help))
265
266
        if len(option_help) > 0:
267
            text.append('%soptions:\n' % (2 * indent))
268
            text.extend(option_help)
269
270
        return text
0.1.109 by Michael Ellerman
Hijack the bzr command infrastructure to do subcommands for 'shelf'.
271
0.1.73 by Michael Ellerman
Merge most of the standalone shelf branch. This brings in a few changes which
272
246 by Aaron Bentley
Merged shelf_v2
273
0.1.73 by Michael Ellerman
Merge most of the standalone shelf branch. This brings in a few changes which
274
class cmd_unshelve(bzrlib.commands.Command):
393 by Aaron Bentley
Pull in latest shelf stuff
275
    """Restore shelved changes.  <BZRTOOLS>
0.1.113 by Michael Ellerman
Support for unshelving in arbitrary order.
276
277
    By default the most recently shelved changes are restored. However if you
278
    specify a patch by name those changes will be restored instead.
279
0.1.73 by Michael Ellerman
Merge most of the standalone shelf branch. This brings in a few changes which
280
    See 'shelve' for more information.
281
    """
0.1.91 by Michael Ellerman
Add --force option to unshelve, which runs the shelved changes through
282
    takes_options = [
283
            Option('all', help='Unshelve all changes without prompting'),
284
            Option('force', help='Force unshelving even if errors occur'),
285
    ]
0.1.113 by Michael Ellerman
Support for unshelving in arbitrary order.
286
    takes_args = ['patch?']
287
    def run(self, patch=None, all=False, force=False):
0.1.73 by Michael Ellerman
Merge most of the standalone shelf branch. This brings in a few changes which
288
        source = BzrPatchSource()
0.1.74 by Michael Ellerman
Adapt to BzrDir changes and deprecation of show_diff().
289
        s = Shelf(source.base)
0.1.113 by Michael Ellerman
Support for unshelving in arbitrary order.
290
        s.unshelve(source, patch, all, force)
0.1.73 by Michael Ellerman
Merge most of the standalone shelf branch. This brings in a few changes which
291
        return 0
292
0.1.22 by Michael Ellerman
Add __init__.py, put cmd_shelve/unshelve in there.
293
249 by Aaron Bentley
Got the shell basics working properly
294
class cmd_shell(bzrlib.commands.Command):
342 by Aaron Bentley
Tagged BZRTOOLS commands to reduce confusion
295
    """Begin an interactive shell tailored for bzr.  <BZRTOOLS>
287 by Aaron Bentley
Added shell docstring
296
    Bzr commands can be used without typing bzr first, and will be run natively
297
    when possible.  Tab completion is tailored for bzr.  The shell prompt shows
298
    the branch nick, revno, and path.
299
300
    If it encounters any moderately complicated shell command, it will punt to
301
    the system shell.
302
303
    Example:
304
    $ bzr shell
305
    bzr bzrtools:287/> status
306
    modified:
307
      __init__.py
308
    bzr bzrtools:287/> status --[TAB][TAB]
309
    --all        --help       --revision   --show-ids
310
    bzr bzrtools:287/> status --
311
    """
249 by Aaron Bentley
Got the shell basics working properly
312
    def run(self):
313
        import shell
281 by Aaron Bentley
Handled whitespace branch names better
314
        return shell.run_shell()
246 by Aaron Bentley
Merged shelf_v2
315
292 by Aaron Bentley
Introduced branch-history command
316
class cmd_branch_history(bzrlib.commands.Command):
317
    """\
342 by Aaron Bentley
Tagged BZRTOOLS commands to reduce confusion
318
    Display the development history of a branch  <BZRTOOLS>.
292 by Aaron Bentley
Introduced branch-history command
319
293 by Aaron Bentley
Updated help
320
    Each different committer or branch nick is considered a different line of
321
    development.  Committers are treated as the same if they have the same
322
    name, or if they have the same email address.
292 by Aaron Bentley
Introduced branch-history command
323
    """
324
    takes_args = ["branch?"]
325
    def run(self, branch=None):
326
        from branchhistory import branch_history 
327
        return branch_history(branch)
328
345 by Aaron Bentley
Added zap command
329
330
class cmd_zap(bzrlib.commands.Command):
331
    """\
411 by Aaron Bentley
Update zap documentation
332
    Remove a lightweight checkout, if it can be done safely. <BZRTOOLS>
333
334
    This command will remove a lightweight checkout without losing data.  That
335
    means it only removes lightweight checkouts, and only if they have no
336
    uncommitted changes.
337
338
    If --branch is specified, the branch will be deleted too, but only if the
339
    the branch has no new commits (relative to its parent).
345 by Aaron Bentley
Added zap command
340
    """
355.1.1 by Aaron Bentley
Provided --branch option to for zapping branches
341
    takes_options = [Option("branch", help="Remove associtated branch from"
342
                                           " repository")]
345 by Aaron Bentley
Added zap command
343
    takes_args = ["checkout"]
355.1.1 by Aaron Bentley
Provided --branch option to for zapping branches
344
    def run(self, checkout, branch=False):
345 by Aaron Bentley
Added zap command
345
        from zap import zap
355.1.1 by Aaron Bentley
Provided --branch option to for zapping branches
346
        return zap(checkout, remove_branch=branch)
345 by Aaron Bentley
Added zap command
347
348
349 by Aaron Bentley
Added cbranch command
349
class cmd_cbranch(bzrlib.commands.Command):
350
    """
351
    Create a new checkout, associated with a new repository branch. <BZRTOOLS>
352
    
353
    When you cbranch, bzr looks up the repository associated with your current
354
    directory in branches.conf.  It creates a new branch in that repository
355
    with the same name and relative path as the checkout you request.
351 by Aaron Bentley
Improved cbranch docs
356
357
    The branches.conf parameter is "cbranch_root".  So if you want 
358
    cbranch operations in /home/jrandom/bigproject to produce branches in 
359
    /home/jrandom/bigproject/repository, you'd add this:
360
361
    [/home/jrandom/bigproject]
362
    cbranch_root = /home/jrandom/bigproject/repository
363
364
    Note that if "/home/jrandom/bigproject/repository" isn't a repository,
365
    standalone branches will be produced.  Standalone branches will also
366
    be produced if the source branch is in 0.7 format (or earlier).
349 by Aaron Bentley
Added cbranch command
367
    """
355.1.2 by Aaron Bentley
cbranch mimics checkout wrt --lightweight
368
    takes_options = [Option("lightweight", 
369
                            help="Create a lightweight checkout")]
370
    takes_args = ["source", "target?"]
371
    def run(self, source, target=None, lightweight=False):
349 by Aaron Bentley
Added cbranch command
372
        from cbranch import cbranch
355.1.2 by Aaron Bentley
cbranch mimics checkout wrt --lightweight
373
        return cbranch(source, target, lightweight=lightweight)
374
349 by Aaron Bentley
Added cbranch command
375
352 by Aaron Bentley
Added branches subcommand
376
class cmd_branches(bzrlib.commands.Command):
377
    """Scan a location for branches <BZRTOOLS>"""
378
    takes_args = ["location?"]
379
    def run(self, location=None):
380
        from branches import branches
381
        return branches(location)
382
353 by Aaron Bentley
Added multi-pull, working on branches and checkouts
383
384
class cmd_multi_pull(bzrlib.commands.Command):
385
    """Pull all the branches under a location, e.g. a repository. <BZRTOOLS>
386
    
387
    Both branches present in the directory and the branches of checkouts are
388
    pulled.
389
    """
390
    takes_args = ["location?"]
391
    def run(self, location=None):
392
        from bzrlib.branch import Branch
393
        from bzrlib.transport import get_transport
394
        from bzrtools import iter_branch_tree
395
        if location is None:
396
            location = '.'
397
        t = get_transport(location)
398
        if not t.listable():
399
            print "Can't list this type of location."
400
            return 3
401
        for branch, wt in iter_branch_tree(t):
402
            if wt is None:
403
                pullable = branch
404
            else:
405
                pullable = wt
406
            parent = branch.get_parent()
407
            if parent is None:
408
                continue
409
            if wt is not None:
410
                base = wt.basedir
411
            else:
412
                base = branch.base
413
            if base.startswith(t.base):
414
                relpath = base[len(t.base):].rstrip('/')
415
            else:
416
                relpath = base
417
            print "Pulling %s from %s" % (relpath, parent)
418
            try:
419
                pullable.pull(Branch.open(parent))
420
            except Exception, e:
421
                print e
422
423
360.1.3 by Aaron Bentley
Add experimental branch-mark command
424
class cmd_branch_mark(bzrlib.commands.Command):
425
    """
426
    Add, view or list branch markers <EXPERIMENTAL>
427
428
    To add a mark, do 'bzr branch-mark MARK'.
429
    To list marks, do 'bzr branch-mark' (this lists all marks for the branch's
430
    repository).
431
    To delete a mark, do 'bzr branch-mark --delete MARK'
432
433
    These marks can be used to track a branch's status.
434
    """
435
    takes_args = ['mark?', 'branch?']
436
    takes_options = [Option('delete', help='Delete this mark')]
437
    def run(self, mark=None, branch=None, delete=False):
438
        from branch_mark import branch_mark
439
        branch_mark(mark, branch, delete)
440
377 by Aaron Bentley
Got import command working
441
class cmd_import(bzrlib.commands.Command):
380 by Aaron Bentley
Got import working decently
442
    """Import sources from a tarball <BZRTOOLS>
443
    
444
    This command will import a tarball into a bzr tree, replacing any versioned
445
    files already present.  If a directory is specified, it is used as the
446
    target.  If the directory does not exist, or is not versioned, it is
447
    created.
448
449
    Tarballs may be gzip or bzip2 compressed.  This is autodetected.
450
451
    If the tarball has a single root directory, that directory is stripped
452
    when extracting the tarball.
453
    """
454
    
455
    takes_args = ['source', 'tree?']
456
    def run(self, source, tree=None):
377 by Aaron Bentley
Got import command working
457
        from upstream_import import do_import
380 by Aaron Bentley
Got import working decently
458
        do_import(source, tree)
377 by Aaron Bentley
Got import command working
459
392.1.1 by Aaron Bentley
Implement 'shove' for moving changes to other trees
460
class cmd_shove(bzrlib.commands.Command):
461
    """Apply uncommitted changes to another tree <BZRTOOLS>
462
    
463
    This is useful when you start to make changes in one tree, then realize
464
    they should really be done in a different tree.
465
466
    Shove is implemented using merge, so:
467
     - All changes, including renames and adds, will be applied.
468
     - No changes that have already been applied will be applied.
469
     - If the target is significantly different from the source, conflicts may
470
       be produced.
471
    """
472
408 by Aaron Bentley
Revert shove to previous argument order
473
    takes_args = ['target', 'source?']
392.1.1 by Aaron Bentley
Implement 'shove' for moving changes to other trees
474
    def run(self, target, source='.'):
475
        from shove import do_shove
476
        do_shove(source, target)
477
399 by Aaron Bentley
Implement cdiff (based on old Fai code)
478
class cmd_cdiff(bzrlib.commands.Command):
479
    """A color version of bzr's diff <BZRTOOLS>"""
410 by Aaron Bentley
Ensure the option settings come from the right 'diff' in colordiff
480
    takes_args = property(lambda x: get_cmd_object('diff').takes_args)
481
    takes_options = property(lambda x: get_cmd_object('diff').takes_options)
399 by Aaron Bentley
Implement cdiff (based on old Fai code)
482
    def run(*args, **kwargs):
483
        from colordiff import colordiff
484
        colordiff(*args, **kwargs)
360.1.3 by Aaron Bentley
Add experimental branch-mark command
485
391 by Aaron Bentley
Updates from the bzr clean-tree branch
486
commands = [cmd_shelve, cmd_unshelve, cmd_shelf, cmd_clean_tree,
487
            cmd_graph_ancestry, cmd_fetch_ghosts, cmd_patch, cmd_shell,
488
            cmd_branch_history, cmd_zap, cmd_cbranch, cmd_branches, 
399 by Aaron Bentley
Implement cdiff (based on old Fai code)
489
            cmd_multi_pull, cmd_switch, cmd_branch_mark, cmd_import, cmd_shove,
490
            cmd_cdiff]
491
492
364.1.4 by Aaron Bentley
Changed rpush to rspush
493
commands.append(rspush.cmd_rspush)
246 by Aaron Bentley
Merged shelf_v2
494
495
from errors import NoPyBaz
496
try:
497
    import baz_import
147.1.41 by Aaron Bentley
Merge from mainline
498
    commands.append(baz_import.cmd_baz_import_branch)
246 by Aaron Bentley
Merged shelf_v2
499
    commands.append(baz_import.cmd_baz_import)
500
501
except NoPyBaz:
147.1.72 by Aaron Bentley
Handle missing pybaz properly
502
    class cmd_baz_import_branch(bzrlib.commands.Command):
342 by Aaron Bentley
Tagged BZRTOOLS commands to reduce confusion
503
        """Disabled. (Requires PyBaz)   <BZRTOOLS>"""
147.1.72 by Aaron Bentley
Handle missing pybaz properly
504
        takes_args = ['to_location?', 'from_branch?', 'reuse_history*']
505
        takes_options = ['verbose', Option('max-count', type=int)]
506
        def run(self, to_location=None, from_branch=None, fast=False, 
507
                max_count=None, verbose=False, dry_run=False,
508
                reuse_history_list=[]):
509
            print "This command is disabled.  Please install PyBaz."
510
511
246 by Aaron Bentley
Merged shelf_v2
512
    class cmd_baz_import(bzrlib.commands.Command):
342 by Aaron Bentley
Tagged BZRTOOLS commands to reduce confusion
513
        """Disabled. (Requires PyBaz)   <BZRTOOLS>"""
147.1.72 by Aaron Bentley
Handle missing pybaz properly
514
        takes_args = ['to_root_dir?', 'from_archive?', 'reuse_history*']
515
        takes_options = ['verbose', Option('prefixes', type=str,
516
                         help="Prefixes of branches to import")]
517
        def run(self, to_root_dir=None, from_archive=None, verbose=False,
518
                reuse_history_list=[], prefixes=None):
519
                print "This command is disabled.  Please install PyBaz."
520
    commands.extend((cmd_baz_import_branch, cmd_baz_import))
246 by Aaron Bentley
Merged shelf_v2
521
271 by Aaron Bentley
Cherry-picked Robert's diff and push fixes
522
246 by Aaron Bentley
Merged shelf_v2
523
if hasattr(bzrlib.commands, 'register_command'):
524
    for command in commands:
525
        bzrlib.commands.register_command(command)
271 by Aaron Bentley
Cherry-picked Robert's diff and push fixes
526
0.1.73 by Michael Ellerman
Merge most of the standalone shelf branch. This brings in a few changes which
527
528
def test_suite():
529
    from bzrlib.tests.TestUtil import TestLoader
147.1.41 by Aaron Bentley
Merge from mainline
530
    import tests
321.1.3 by Aaron Bentley
Fixed up Robert's test changes
531
    from doctest import DocTestSuite, ELLIPSIS
325.1.2 by Aaron Bentley
Merge shelf v2
532
    from unittest import TestSuite
391 by Aaron Bentley
Updates from the bzr clean-tree branch
533
    import tests.clean_tree
374 by Aaron Bentley
Start work on import plugin
534
    import upstream_import
345 by Aaron Bentley
Added zap command
535
    import zap
339 by Aaron Bentley
Moved tests into a subdir
536
    import tests.blackbox
537
    import tests.shelf_tests
246 by Aaron Bentley
Merged shelf_v2
538
    result = TestSuite()
321.1.3 by Aaron Bentley
Fixed up Robert's test changes
539
    result.addTest(DocTestSuite(bzrtools, optionflags=ELLIPSIS))
391 by Aaron Bentley
Updates from the bzr clean-tree branch
540
    result.addTest(tests.clean_tree.test_suite())
387 by Aaron Bentley
Got test suite running with PyBaz unavailable
541
    try:
542
        import baz_import
543
        result.addTest(DocTestSuite(baz_import))
544
    except NoPyBaz:
545
        pass
147.1.41 by Aaron Bentley
Merge from mainline
546
    result.addTest(tests.test_suite())
339 by Aaron Bentley
Moved tests into a subdir
547
    result.addTest(TestLoader().loadTestsFromModule(tests.shelf_tests))
548
    result.addTest(tests.blackbox.test_suite())
374 by Aaron Bentley
Start work on import plugin
549
    result.addTest(upstream_import.test_suite())
345 by Aaron Bentley
Added zap command
550
    result.addTest(zap.test_suite())
246 by Aaron Bentley
Merged shelf_v2
551
    return result