/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
1
# Copyright (C) 2004, 2005 by Canonical Ltd
2
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
17
18
import sys
19
import os
20
21
import bzrlib
22
import bzrlib.trace
23
from bzrlib.trace import mutter, note, log_error, warning
1371 by Martin Pool
- raise NotBranchError if format file can't be read
24
from bzrlib.errors import BzrError, BzrCheckError, BzrCommandError, NotBranchError
1441 by Robert Collins
tests passing is a good idea - move the branch open in cmd_branch to ensure this, and remove noise from the test suite
25
from bzrlib.errors import DivergedBranches
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
26
from bzrlib.branch import Branch
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
27
from bzrlib import BZRDIR
28
from bzrlib.commands import Command
29
30
31
class cmd_status(Command):
32
    """Display status summary.
33
34
    This reports on versioned and unknown files, reporting them
35
    grouped by state.  Possible states are:
36
37
    added
38
        Versioned in the working copy but not in the previous revision.
39
40
    removed
41
        Versioned in the previous revision but removed or deleted
42
        in the working copy.
43
44
    renamed
45
        Path of this file changed from the previous revision;
46
        the text may also have changed.  This includes files whose
47
        parent directory was renamed.
48
49
    modified
50
        Text has changed since the previous revision.
51
52
    unchanged
53
        Nothing about this file has changed since the previous revision.
54
        Only shown with --all.
55
56
    unknown
57
        Not versioned and not matching an ignore pattern.
58
59
    To see ignored files use 'bzr ignored'.  For details in the
60
    changes to file texts, use 'bzr diff'.
61
62
    If no arguments are specified, the status of the entire working
63
    directory is shown.  Otherwise, only the status of the specified
64
    files or directories is reported.  If a directory is given, status
65
    is reported for everything inside that directory.
1185.1.35 by Robert Collins
Heikki Paajanen's status -r patch
66
67
    If a revision argument is given, the status is calculated against
68
    that revision, or between two revisions if two are provided.
1185.3.2 by Martin Pool
- remove -r option from status command because it's not used
69
    """
1185.1.11 by Robert Collins
fixme note for bzr status
70
    # XXX: FIXME: bzr status should accept a -r option to show changes
71
    # relative to a revision, or between revisions
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
72
73
    takes_args = ['file*']
1092.3.4 by Robert Collins
update symlink branch to integration
74
    takes_options = ['all', 'show-ids']
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
75
    aliases = ['st', 'stat']
76
    
1185.1.35 by Robert Collins
Heikki Paajanen's status -r patch
77
    def run(self, all=False, show_ids=False, file_list=None, revision=None):
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
78
        if file_list:
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
79
            b = Branch.open_containing(file_list[0])
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
80
            file_list = [b.relpath(x) for x in file_list]
81
            # special case: only one path was given and it's the root
82
            # of the branch
83
            if file_list == ['']:
84
                file_list = None
85
        else:
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
86
            b = Branch.open_containing('.')
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
87
            
88
        from bzrlib.status import show_status
89
        show_status(b, show_unchanged=all, show_ids=show_ids,
1185.1.35 by Robert Collins
Heikki Paajanen's status -r patch
90
                    specific_files=file_list, revision=revision)
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
91
92
93
class cmd_cat_revision(Command):
1185.5.3 by John Arbash Meinel
cat-revision allows --revision for easier investigation.
94
    """Write out metadata for a revision.
95
    
96
    The revision to print can either be specified by a specific
97
    revision identifier, or you can use --revision.
98
    """
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
99
100
    hidden = True
1185.5.3 by John Arbash Meinel
cat-revision allows --revision for easier investigation.
101
    takes_args = ['revision_id?']
102
    takes_options = ['revision']
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
103
    
1185.5.3 by John Arbash Meinel
cat-revision allows --revision for easier investigation.
104
    def run(self, revision_id=None, revision=None):
105
        from bzrlib.revisionspec import RevisionSpec
106
107
        if revision_id is not None and revision is not None:
108
            raise BzrCommandError('You can only supply one of revision_id or --revision')
109
        if revision_id is None and revision is None:
110
            raise BzrCommandError('You must supply either --revision or a revision_id')
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
111
        b = Branch.open_containing('.')
1185.5.3 by John Arbash Meinel
cat-revision allows --revision for easier investigation.
112
        if revision_id is not None:
113
            sys.stdout.write(b.get_revision_xml_file(revision_id).read())
114
        elif revision is not None:
115
            for rev in revision:
116
                if rev is None:
117
                    raise BzrCommandError('You cannot specify a NULL revision.')
118
                revno, rev_id = rev.in_history(b)
119
                sys.stdout.write(b.get_revision_xml_file(rev_id).read())
1185.1.29 by Robert Collins
merge merge tweaks from aaron, which includes latest .dev
120
    
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
121
122
class cmd_revno(Command):
123
    """Show current revision number.
124
125
    This is equal to the number of revisions on this branch."""
126
    def run(self):
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
127
        print Branch.open_containing('.').revno()
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
128
1182 by Martin Pool
- more disentangling of xml storage format from objects
129
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
130
class cmd_revision_info(Command):
131
    """Show revision number and revision id for a given revision identifier.
132
    """
133
    hidden = True
134
    takes_args = ['revision_info*']
135
    takes_options = ['revision']
1185.5.4 by John Arbash Meinel
Updated bzr revision-info, created tests.
136
    def run(self, revision=None, revision_info_list=[]):
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
137
        from bzrlib.revisionspec import RevisionSpec
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
138
139
        revs = []
140
        if revision is not None:
141
            revs.extend(revision)
1185.5.4 by John Arbash Meinel
Updated bzr revision-info, created tests.
142
        if revision_info_list is not None:
143
            for rev in revision_info_list:
144
                revs.append(RevisionSpec(rev))
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
145
        if len(revs) == 0:
146
            raise BzrCommandError('You must supply a revision identifier')
147
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
148
        b = Branch.open_containing('.')
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
149
150
        for rev in revs:
1185.5.4 by John Arbash Meinel
Updated bzr revision-info, created tests.
151
            revinfo = rev.in_history(b)
152
            if revinfo.revno is None:
153
                print '     %s' % revinfo.rev_id
154
            else:
155
                print '%4d %s' % (revinfo.revno, revinfo.rev_id)
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
156
157
    
158
class cmd_add(Command):
159
    """Add specified files or directories.
160
161
    In non-recursive mode, all the named items are added, regardless
162
    of whether they were previously ignored.  A warning is given if
163
    any of the named files are already versioned.
164
165
    In recursive mode (the default), files are treated the same way
166
    but the behaviour for directories is different.  Directories that
167
    are already versioned do not give a warning.  All directories,
168
    whether already versioned or not, are searched for files or
169
    subdirectories that are neither versioned or ignored, and these
170
    are added.  This search proceeds recursively into versioned
171
    directories.  If no names are given '.' is assumed.
172
173
    Therefore simply saying 'bzr add' will version all files that
174
    are currently unknown.
175
1185.3.3 by Martin Pool
- patch from mpe to automatically add parent directories
176
    Adding a file whose parent directory is not versioned will
177
    implicitly add the parent, and so on up to the root. This means
178
    you should never need to explictly add a directory, they'll just
179
    get added when you add a file in the directory.
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
180
    """
181
    takes_args = ['file*']
1446 by Robert Collins
fixup the verbose-does-nothing for add - add a --quiet instead
182
    takes_options = ['no-recurse', 'quiet']
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
183
    
1446 by Robert Collins
fixup the verbose-does-nothing for add - add a --quiet instead
184
    def run(self, file_list, no_recurse=False, quiet=False):
185
        from bzrlib.add import smart_add, add_reporter_print, add_reporter_null
186
        if quiet:
187
            reporter = add_reporter_null
188
        else:
189
            reporter = add_reporter_print
190
        smart_add(file_list, not no_recurse, reporter)
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
191
192
193
class cmd_mkdir(Command):
194
    """Create a new versioned directory.
195
196
    This is equivalent to creating the directory and then adding it.
197
    """
198
    takes_args = ['dir+']
199
200
    def run(self, dir_list):
201
        b = None
202
        
203
        for d in dir_list:
204
            os.mkdir(d)
205
            if not b:
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
206
                b = Branch.open_containing(d)
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
207
            b.add([d])
208
            print 'added', d
209
210
211
class cmd_relpath(Command):
212
    """Show path of a file relative to root"""
213
    takes_args = ['filename']
214
    hidden = True
215
    
216
    def run(self, filename):
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
217
        print Branch.open_containing(filename).relpath(filename)
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
218
219
220
221
class cmd_inventory(Command):
222
    """Show inventory of the current working copy or a revision."""
223
    takes_options = ['revision', 'show-ids']
224
    
225
    def run(self, revision=None, show_ids=False):
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
226
        b = Branch.open_containing('.')
227
        if revision is None:
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
228
            inv = b.read_working_inventory()
229
        else:
230
            if len(revision) > 1:
231
                raise BzrCommandError('bzr inventory --revision takes'
232
                    ' exactly one revision identifier')
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
233
            inv = b.get_revision_inventory(revision[0].in_history(b).rev_id)
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
234
235
        for path, entry in inv.entries():
236
            if show_ids:
237
                print '%-50s %s' % (path, entry.file_id)
238
            else:
239
                print path
240
241
242
class cmd_move(Command):
243
    """Move files to a different directory.
244
245
    examples:
246
        bzr move *.txt doc
247
248
    The destination must be a versioned directory in the same branch.
249
    """
250
    takes_args = ['source$', 'dest']
251
    def run(self, source_list, dest):
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
252
        b = Branch.open_containing('.')
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
253
254
        # TODO: glob expansion on windows?
255
        b.move([b.relpath(s) for s in source_list], b.relpath(dest))
256
257
258
class cmd_rename(Command):
259
    """Change the name of an entry.
260
261
    examples:
262
      bzr rename frob.c frobber.c
263
      bzr rename src/frob.c lib/frob.c
264
265
    It is an error if the destination name exists.
266
267
    See also the 'move' command, which moves files into a different
268
    directory without changing their name.
1185.16.3 by Martin Pool
- remove all TODOs from bzr help messages
269
    """
270
    # TODO: Some way to rename multiple files without invoking 
271
    # bzr for each one?"""
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
272
    takes_args = ['from_name', 'to_name']
273
    
274
    def run(self, from_name, to_name):
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
275
        b = Branch.open_containing('.')
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
276
        b.rename_one(b.relpath(from_name), b.relpath(to_name))
277
278
279
280
class cmd_mv(Command):
281
    """Move or rename a file.
282
283
    usage:
284
        bzr mv OLDNAME NEWNAME
285
        bzr mv SOURCE... DESTINATION
286
287
    If the last argument is a versioned directory, all the other names
288
    are moved into it.  Otherwise, there must be exactly two arguments
289
    and the file is changed to a new name, which must not already exist.
290
291
    Files cannot be moved between branches.
292
    """
293
    takes_args = ['names*']
294
    def run(self, names_list):
295
        if len(names_list) < 2:
296
            raise BzrCommandError("missing file argument")
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
297
        b = Branch.open_containing(names_list[0])
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
298
299
        rel_names = [b.relpath(x) for x in names_list]
300
        
301
        if os.path.isdir(names_list[-1]):
302
            # move into existing directory
303
            for pair in b.move(rel_names[:-1], rel_names[-1]):
304
                print "%s => %s" % pair
305
        else:
306
            if len(names_list) != 2:
307
                raise BzrCommandError('to mv multiple files the destination '
308
                                      'must be a versioned directory')
1185.1.8 by Robert Collins
David Clymers patch to use rename rather than mv for two argument non-directory target bzr mv calls.
309
            b.rename_one(rel_names[0], rel_names[1])
310
            print "%s => %s" % (rel_names[0], rel_names[1])
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
311
            
312
    
313
314
315
class cmd_pull(Command):
316
    """Pull any changes from another branch into the current one.
317
318
    If the location is omitted, the last-used location will be used.
319
    Both the revision history and the working directory will be
320
    updated.
321
322
    This command only works on branches that have not diverged.  Branches are
323
    considered diverged if both branches have had commits without first
324
    pulling from the other.
325
326
    If branches have diverged, you can use 'bzr merge' to pull the text changes
327
    from one into the other.
328
    """
1185.12.11 by Aaron Bentley
Made pull only save the parent location if it is unset, or on --remember
329
    takes_options = ['remember']
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
330
    takes_args = ['location?']
331
1185.12.11 by Aaron Bentley
Made pull only save the parent location if it is unset, or on --remember
332
    def run(self, location=None, remember=False):
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
333
        from bzrlib.merge import merge
334
        import tempfile
335
        from shutil import rmtree
336
        import errno
337
        
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
338
        br_to = Branch.open_containing('.')
974.1.79 by Aaron Bentley
Fixed issues with pull not having a default location after branch
339
        stored_loc = br_to.get_parent()
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
340
        if location is None:
341
            if stored_loc is None:
342
                raise BzrCommandError("No pull location known or specified.")
343
            else:
1185.12.12 by Aaron Bentley
Made merge use pull location or die if no branch specified.
344
                print "Using saved location: %s" % stored_loc
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
345
                location = stored_loc
346
        cache_root = tempfile.mkdtemp()
1441 by Robert Collins
tests passing is a good idea - move the branch open in cmd_branch to ensure this, and remove noise from the test suite
347
        br_from = Branch.open(location)
348
        br_from.lock_read()
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
349
        try:
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
350
            br_from.setup_caching(cache_root)
1185.2.3 by Lalo Martins
unifying 'base' (from Branch) and 'baseurl' (from RemoteBranch) attributes;
351
            location = br_from.base
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
352
            old_revno = br_to.revno()
1442 by Robert Collins
only do a local merge during pull if the revision history changed
353
            old_revision_history = br_to.revision_history()
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
354
            try:
355
                br_to.update_revisions(br_from)
356
            except DivergedBranches:
357
                raise BzrCommandError("These branches have diverged."
358
                    "  Try merge.")
1442 by Robert Collins
only do a local merge during pull if the revision history changed
359
            new_revision_history = br_to.revision_history()
360
            if new_revision_history != old_revision_history:
361
                merge(('.', -1), ('.', old_revno), check_clean=False)
1185.12.11 by Aaron Bentley
Made pull only save the parent location if it is unset, or on --remember
362
            if stored_loc is None or remember:
974.1.79 by Aaron Bentley
Fixed issues with pull not having a default location after branch
363
                br_to.set_parent(location)
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
364
        finally:
1439 by Robert Collins
fix a prior bad merge of cmd_pull, which had resulted in double opens of remote branches
365
            br_from.unlock()
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
366
            rmtree(cache_root)
367
368
369
370
class cmd_branch(Command):
371
    """Create a new copy of a branch.
372
373
    If the TO_LOCATION is omitted, the last component of the FROM_LOCATION will
374
    be used.  In other words, "branch ../foo/bar" will attempt to create ./bar.
375
376
    To retrieve the branch as of a particular revision, supply the --revision
377
    parameter, as in "branch foo/bar -r 5".
1185.10.2 by Aaron Bentley
Updated help message
378
379
    --basis is to speed up branching from remote branches.  When specified, it
380
    copies all the file-contents, inventory and revision data from the basis
381
    branch before copying anything from the remote branch.
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
382
    """
383
    takes_args = ['from_location', 'to_location?']
1185.10.1 by Aaron Bentley
Added --basis option to bzr branch
384
    takes_options = ['revision', 'basis']
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
385
    aliases = ['get', 'clone']
386
1185.10.1 by Aaron Bentley
Added --basis option to bzr branch
387
    def run(self, from_location, to_location=None, revision=None, basis=None):
1393.1.5 by Martin Pool
- move copy_branch into bzrlib.clone
388
        from bzrlib.clone import copy_branch
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
389
        import tempfile
390
        import errno
391
        from shutil import rmtree
392
        cache_root = tempfile.mkdtemp()
393
        try:
394
            if revision is None:
395
                revision = [None]
396
            elif len(revision) > 1:
397
                raise BzrCommandError(
398
                    'bzr branch --revision takes exactly 1 revision value')
399
            try:
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
400
                br_from = Branch.open(from_location)
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
401
            except OSError, e:
402
                if e.errno == errno.ENOENT:
403
                    raise BzrCommandError('Source location "%s" does not'
404
                                          ' exist.' % to_location)
405
                else:
406
                    raise
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
407
            br_from.setup_caching(cache_root)
1185.10.1 by Aaron Bentley
Added --basis option to bzr branch
408
            if basis is not None:
409
                basis_branch = Branch.open_containing(basis)
410
            else:
411
                basis_branch = None
1185.8.4 by Aaron Bentley
Fixed branch -r
412
            if len(revision) == 1 and revision[0] is not None:
1390 by Robert Collins
pair programming worx... merge integration and weave
413
                revision_id = revision[0].in_history(br_from)[1]
1185.8.4 by Aaron Bentley
Fixed branch -r
414
            else:
1390 by Robert Collins
pair programming worx... merge integration and weave
415
                revision_id = None
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
416
            if to_location is None:
417
                to_location = os.path.basename(from_location.rstrip("/\\"))
418
            try:
419
                os.mkdir(to_location)
420
            except OSError, e:
421
                if e.errno == errno.EEXIST:
422
                    raise BzrCommandError('Target directory "%s" already'
423
                                          ' exists.' % to_location)
424
                if e.errno == errno.ENOENT:
425
                    raise BzrCommandError('Parent of "%s" does not exist.' %
426
                                          to_location)
427
                else:
428
                    raise
429
            try:
1391 by Robert Collins
merge from integration
430
                copy_branch(br_from, to_location, revision_id, basis_branch)
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
431
            except bzrlib.errors.NoSuchRevision:
432
                rmtree(to_location)
433
                msg = "The branch %s has no revision %d." % (from_location, revision[0])
434
                raise BzrCommandError(msg)
1185.10.1 by Aaron Bentley
Added --basis option to bzr branch
435
            except bzrlib.errors.UnlistableBranch:
436
                msg = "The branch %s cannot be used as a --basis"
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
437
        finally:
438
            rmtree(cache_root)
439
440
441
class cmd_renames(Command):
442
    """Show list of renamed files.
443
    """
1185.16.3 by Martin Pool
- remove all TODOs from bzr help messages
444
    # TODO: Option to show renames between two historical versions.
445
446
    # TODO: Only show renames under dir, rather than in the whole branch.
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
447
    takes_args = ['dir?']
448
449
    def run(self, dir='.'):
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
450
        b = Branch.open_containing(dir)
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
451
        old_inv = b.basis_tree().inventory
452
        new_inv = b.read_working_inventory()
453
454
        renames = list(bzrlib.tree.find_renames(old_inv, new_inv))
455
        renames.sort()
456
        for old_name, new_name in renames:
457
            print "%s => %s" % (old_name, new_name)        
458
459
460
class cmd_info(Command):
461
    """Show statistical information about a branch."""
462
    takes_args = ['branch?']
463
    
464
    def run(self, branch=None):
465
        import info
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
466
        b = Branch.open_containing(branch)
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
467
        info.show_info(b)
468
469
470
class cmd_remove(Command):
471
    """Make a file unversioned.
472
473
    This makes bzr stop tracking changes to a versioned file.  It does
474
    not delete the working copy.
475
    """
476
    takes_args = ['file+']
477
    takes_options = ['verbose']
1424 by Robert Collins
add rm alias to remove
478
    aliases = ['rm']
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
479
    
480
    def run(self, file_list, verbose=False):
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
481
        b = Branch.open_containing(file_list[0])
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
482
        b.remove([b.relpath(f) for f in file_list], verbose=verbose)
483
484
485
class cmd_file_id(Command):
486
    """Print file_id of a particular file or directory.
487
488
    The file_id is assigned when the file is first added and remains the
489
    same through all revisions where the file exists, even when it is
490
    moved or renamed.
491
    """
492
    hidden = True
493
    takes_args = ['filename']
494
    def run(self, filename):
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
495
        b = Branch.open_containing(filename)
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
496
        i = b.inventory.path2id(b.relpath(filename))
497
        if i == None:
498
            raise BzrError("%r is not a versioned file" % filename)
499
        else:
500
            print i
501
502
503
class cmd_file_path(Command):
504
    """Print path of file_ids to a file or directory.
505
506
    This prints one line for each directory down to the target,
507
    starting at the branch root."""
508
    hidden = True
509
    takes_args = ['filename']
510
    def run(self, filename):
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
511
        b = Branch.open_containing(filename)
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
512
        inv = b.inventory
513
        fid = inv.path2id(b.relpath(filename))
514
        if fid == None:
515
            raise BzrError("%r is not a versioned file" % filename)
516
        for fip in inv.get_idpath(fid):
517
            print fip
518
519
520
class cmd_revision_history(Command):
521
    """Display list of revision ids on this branch."""
522
    hidden = True
523
    def run(self):
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
524
        for patchid in Branch.open_containing('.').revision_history():
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
525
            print patchid
526
527
1225 by Martin Pool
- branch now tracks ancestry - all merged revisions
528
class cmd_ancestry(Command):
529
    """List all revisions merged into this branch."""
530
    hidden = True
531
    def run(self):
532
        b = find_branch('.')
1241 by Martin Pool
- rename last_patch to last_revision
533
        for revision_id in b.get_ancestry(b.last_revision()):
1225 by Martin Pool
- branch now tracks ancestry - all merged revisions
534
            print revision_id
535
536
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
537
class cmd_directories(Command):
538
    """Display list of versioned directories in this branch."""
539
    def run(self):
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
540
        for name, ie in Branch.open_containing('.').read_working_inventory().directories():
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
541
            if name == '':
542
                print '.'
543
            else:
544
                print name
545
546
547
class cmd_init(Command):
548
    """Make a directory into a versioned branch.
549
550
    Use this to create an empty branch, or before importing an
551
    existing project.
552
553
    Recipe for importing a tree of files:
554
        cd ~/project
555
        bzr init
556
        bzr add -v .
557
        bzr status
558
        bzr commit -m 'imported project'
559
    """
560
    def run(self):
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
561
        Branch.initialize('.')
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
562
563
564
class cmd_diff(Command):
565
    """Show differences in working tree.
566
    
567
    If files are listed, only the changes in those files are listed.
568
    Otherwise, all changes for the tree are listed.
569
570
    examples:
571
        bzr diff
572
        bzr diff -r1
1185.1.2 by Martin Pool
- merge various windows and other fixes from Ollie Rutherfurd
573
        bzr diff -r1..2
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
574
    """
1185.16.3 by Martin Pool
- remove all TODOs from bzr help messages
575
    # TODO: Allow diff across branches.
576
    # TODO: Option to use external diff command; could be GNU diff, wdiff,
577
    #       or a graphical diff.
578
579
    # TODO: Python difflib is not exactly the same as unidiff; should
580
    #       either fix it up or prefer to use an external diff.
581
582
    # TODO: If a directory is given, diff everything under that.
583
584
    # TODO: Selected-file diff is inefficient and doesn't show you
585
    #       deleted files.
586
587
    # TODO: This probably handles non-Unix newlines poorly.
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
588
    
589
    takes_args = ['file*']
590
    takes_options = ['revision', 'diff-options']
591
    aliases = ['di', 'dif']
592
593
    def run(self, revision=None, file_list=None, diff_options=None):
594
        from bzrlib.diff import show_diff
595
596
        if file_list:
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
597
            b = Branch.open_containing(file_list[0])
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
598
            file_list = [b.relpath(f) for f in file_list]
599
            if file_list == ['']:
600
                # just pointing to top-of-tree
601
                file_list = None
602
        else:
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
603
            b = Branch.open_containing('.')
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
604
605
        if revision is not None:
606
            if len(revision) == 1:
607
                show_diff(b, revision[0], specific_files=file_list,
608
                          external_diff_options=diff_options)
609
            elif len(revision) == 2:
610
                show_diff(b, revision[0], specific_files=file_list,
611
                          external_diff_options=diff_options,
612
                          revision2=revision[1])
613
            else:
614
                raise BzrCommandError('bzr diff --revision takes exactly one or two revision identifiers')
615
        else:
616
            show_diff(b, None, specific_files=file_list,
617
                      external_diff_options=diff_options)
618
619
        
620
621
622
class cmd_deleted(Command):
623
    """List files deleted in the working tree.
624
    """
1185.16.3 by Martin Pool
- remove all TODOs from bzr help messages
625
    # TODO: Show files deleted since a previous revision, or
626
    # between two revisions.
627
    # TODO: Much more efficient way to do this: read in new
628
    # directories with readdir, rather than stating each one.  Same
629
    # level of effort but possibly much less IO.  (Or possibly not,
630
    # if the directories are very large...)
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
631
    def run(self, show_ids=False):
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
632
        b = Branch.open_containing('.')
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
633
        old = b.basis_tree()
634
        new = b.working_tree()
635
        for path, ie in old.inventory.iter_entries():
636
            if not new.has_id(ie.file_id):
637
                if show_ids:
638
                    print '%-50s %s' % (path, ie.file_id)
639
                else:
640
                    print path
641
642
643
class cmd_modified(Command):
644
    """List files modified in working tree."""
645
    hidden = True
646
    def run(self):
647
        from bzrlib.delta import compare_trees
648
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
649
        b = Branch.open_containing('.')
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
650
        td = compare_trees(b.basis_tree(), b.working_tree())
651
1398 by Robert Collins
integrate in Gustavos x-bit patch
652
        for path, id, kind, text_modified, meta_modified in td.modified:
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
653
            print path
654
655
656
657
class cmd_added(Command):
658
    """List files added in working tree."""
659
    hidden = True
660
    def run(self):
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
661
        b = Branch.open_containing('.')
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
662
        wt = b.working_tree()
663
        basis_inv = b.basis_tree().inventory
664
        inv = wt.inventory
665
        for file_id in inv:
666
            if file_id in basis_inv:
667
                continue
668
            path = inv.id2path(file_id)
669
            if not os.access(b.abspath(path), os.F_OK):
670
                continue
671
            print path
672
                
673
        
674
675
class cmd_root(Command):
676
    """Show the tree root directory.
677
678
    The root is the nearest enclosing directory with a .bzr control
679
    directory."""
680
    takes_args = ['filename?']
681
    def run(self, filename=None):
682
        """Print the branch root."""
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
683
        b = Branch.open_containing(filename)
1185.2.3 by Lalo Martins
unifying 'base' (from Branch) and 'baseurl' (from RemoteBranch) attributes;
684
        print b.base
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
685
686
687
class cmd_log(Command):
688
    """Show log of this branch.
689
690
    To request a range of logs, you can use the command -r begin:end
691
    -r revision requests a specific revision, -r :end or -r begin: are
692
    also valid.
693
694
    --message allows you to give a regular expression, which will be evaluated
695
    so that only matching entries will be displayed.
696
    """
697
1393.1.55 by Martin Pool
doc
698
    # TODO: Make --revision support uuid: and hash: [future tag:] notation.
699
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
700
    takes_args = ['filename?']
701
    takes_options = ['forward', 'timezone', 'verbose', 'show-ids', 'revision',
702
                     'long', 'message', 'short',]
703
    
704
    def run(self, filename=None, timezone='original',
705
            verbose=False,
706
            show_ids=False,
707
            forward=False,
708
            revision=None,
709
            message=None,
710
            long=False,
711
            short=False):
712
        from bzrlib.log import log_formatter, show_log
713
        import codecs
714
715
        direction = (forward and 'forward') or 'reverse'
716
        
717
        if filename:
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
718
            b = Branch.open_containing(filename)
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
719
            fp = b.relpath(filename)
720
            if fp:
721
                file_id = b.read_working_inventory().path2id(fp)
722
            else:
723
                file_id = None  # points to branch root
724
        else:
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
725
            b = Branch.open_containing('.')
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
726
            file_id = None
727
728
        if revision is None:
729
            rev1 = None
730
            rev2 = None
731
        elif len(revision) == 1:
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
732
            rev1 = rev2 = revision[0].in_history(b).revno
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
733
        elif len(revision) == 2:
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
734
            rev1 = revision[0].in_history(b).revno
735
            rev2 = revision[1].in_history(b).revno
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
736
        else:
737
            raise BzrCommandError('bzr log --revision takes one or two values.')
738
739
        if rev1 == 0:
740
            rev1 = None
741
        if rev2 == 0:
742
            rev2 = None
743
744
        mutter('encoding log as %r' % bzrlib.user_encoding)
745
746
        # use 'replace' so that we don't abort if trying to write out
747
        # in e.g. the default C locale.
748
        outf = codecs.getwriter(bzrlib.user_encoding)(sys.stdout, errors='replace')
749
750
        if not short:
751
            log_format = 'long'
752
        else:
753
            log_format = 'short'
754
        lf = log_formatter(log_format,
755
                           show_ids=show_ids,
756
                           to_file=outf,
757
                           show_timezone=timezone)
758
759
        show_log(b,
760
                 lf,
761
                 file_id,
762
                 verbose=verbose,
763
                 direction=direction,
764
                 start_revision=rev1,
765
                 end_revision=rev2,
766
                 search=message)
767
768
769
770
class cmd_touching_revisions(Command):
771
    """Return revision-ids which affected a particular file.
772
773
    A more user-friendly interface is "bzr log FILE"."""
774
    hidden = True
775
    takes_args = ["filename"]
776
    def run(self, filename):
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
777
        b = Branch.open_containing(filename)
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
778
        inv = b.read_working_inventory()
779
        file_id = inv.path2id(b.relpath(filename))
780
        for revno, revision_id, what in bzrlib.log.find_touching_revisions(b, file_id):
781
            print "%6d %s" % (revno, what)
782
783
784
class cmd_ls(Command):
785
    """List files in a tree.
786
    """
1185.16.3 by Martin Pool
- remove all TODOs from bzr help messages
787
    # TODO: Take a revision or remote path and list that tree instead.
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
788
    hidden = True
789
    def run(self, revision=None, verbose=False):
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
790
        b = Branch.open_containing('.')
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
791
        if revision == None:
792
            tree = b.working_tree()
793
        else:
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
794
            tree = b.revision_tree(revision.in_history(b).rev_id)
1399.1.2 by Robert Collins
push kind character creation into InventoryEntry and TreeEntry
795
        for fp, fc, kind, fid, entry in tree.list_files():
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
796
            if verbose:
1399.1.2 by Robert Collins
push kind character creation into InventoryEntry and TreeEntry
797
                kindch = entry.kind_character()
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
798
                print '%-8s %s%s' % (fc, fp, kindch)
799
            else:
800
                print fp
801
802
803
804
class cmd_unknowns(Command):
805
    """List unknown files."""
806
    def run(self):
807
        from bzrlib.osutils import quotefn
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
808
        for f in Branch.open_containing('.').unknowns():
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
809
            print quotefn(f)
810
811
812
813
class cmd_ignore(Command):
814
    """Ignore a command or pattern.
815
816
    To remove patterns from the ignore list, edit the .bzrignore file.
817
818
    If the pattern contains a slash, it is compared to the whole path
1185.16.4 by Martin Pool
- doc and todo for ignore command
819
    from the branch root.  Otherwise, it is compared to only the last
820
    component of the path.  To match a file only in the root directory,
821
    prepend './'.
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
822
823
    Ignore patterns are case-insensitive on case-insensitive systems.
824
825
    Note: wildcards must be quoted from the shell on Unix.
826
827
    examples:
828
        bzr ignore ./Makefile
829
        bzr ignore '*.class'
830
    """
1185.16.4 by Martin Pool
- doc and todo for ignore command
831
    # TODO: Complain if the filename is absolute
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
832
    takes_args = ['name_pattern']
833
    
834
    def run(self, name_pattern):
835
        from bzrlib.atomicfile import AtomicFile
836
        import os.path
837
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
838
        b = Branch.open_containing('.')
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
839
        ifn = b.abspath('.bzrignore')
840
841
        if os.path.exists(ifn):
842
            f = open(ifn, 'rt')
843
            try:
844
                igns = f.read().decode('utf-8')
845
            finally:
846
                f.close()
847
        else:
848
            igns = ''
849
850
        # TODO: If the file already uses crlf-style termination, maybe
851
        # we should use that for the newly added lines?
852
853
        if igns and igns[-1] != '\n':
854
            igns += '\n'
855
        igns += name_pattern + '\n'
856
857
        try:
858
            f = AtomicFile(ifn, 'wt')
859
            f.write(igns.encode('utf-8'))
860
            f.commit()
861
        finally:
862
            f.close()
863
864
        inv = b.working_tree().inventory
865
        if inv.path2id('.bzrignore'):
866
            mutter('.bzrignore is already versioned')
867
        else:
868
            mutter('need to make new .bzrignore file versioned')
869
            b.add(['.bzrignore'])
870
871
872
873
class cmd_ignored(Command):
874
    """List ignored files and the patterns that matched them.
875
876
    See also: bzr ignore"""
877
    def run(self):
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
878
        tree = Branch.open_containing('.').working_tree()
1399.1.2 by Robert Collins
push kind character creation into InventoryEntry and TreeEntry
879
        for path, file_class, kind, file_id, entry in tree.list_files():
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
880
            if file_class != 'I':
881
                continue
882
            ## XXX: Slightly inefficient since this was already calculated
883
            pat = tree.is_ignored(path)
884
            print '%-50s %s' % (path, pat)
885
886
887
class cmd_lookup_revision(Command):
888
    """Lookup the revision-id from a revision-number
889
890
    example:
891
        bzr lookup-revision 33
892
    """
893
    hidden = True
894
    takes_args = ['revno']
895
    
896
    def run(self, revno):
897
        try:
898
            revno = int(revno)
899
        except ValueError:
900
            raise BzrCommandError("not a valid revision-number: %r" % revno)
901
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
902
        print Branch.open_containing('.').get_rev_id(revno)
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
903
904
905
class cmd_export(Command):
906
    """Export past revision to destination directory.
907
908
    If no revision is specified this exports the last committed revision.
909
910
    Format may be an "exporter" name, such as tar, tgz, tbz2.  If none is
911
    given, try to find the format with the extension. If no extension
912
    is found exports to a directory (equivalent to --format=dir).
913
914
    Root may be the top directory for tar, tgz and tbz2 formats. If none
915
    is given, the top directory will be the root name of the file."""
916
    # TODO: list known exporters
917
    takes_args = ['dest']
918
    takes_options = ['revision', 'format', 'root']
919
    def run(self, dest, revision=None, format=None, root=None):
920
        import os.path
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
921
        b = Branch.open_containing('.')
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
922
        if revision is None:
1241 by Martin Pool
- rename last_patch to last_revision
923
            rev_id = b.last_revision()
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
924
        else:
925
            if len(revision) != 1:
926
                raise BzrError('bzr export --revision takes exactly 1 argument')
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
927
            rev_id = revision[0].in_history(b).rev_id
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
928
        t = b.revision_tree(rev_id)
1185.12.1 by Aaron Bentley
Fixed export
929
        arg_root, ext = os.path.splitext(os.path.basename(dest))
930
        if ext in ('.gz', '.bz2'):
931
            new_root, new_ext = os.path.splitext(arg_root)
932
            if new_ext == '.tar':
933
                arg_root = new_root
934
                ext = new_ext + ext
935
        if root is None:
936
            root = arg_root
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
937
        if not format:
938
            if ext in (".tar",):
939
                format = "tar"
1185.12.1 by Aaron Bentley
Fixed export
940
            elif ext in (".tar.gz", ".tgz"):
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
941
                format = "tgz"
1185.12.1 by Aaron Bentley
Fixed export
942
            elif ext in (".tar.bz2", ".tbz2"):
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
943
                format = "tbz2"
944
            else:
945
                format = "dir"
946
        t.export(dest, format, root)
947
948
949
class cmd_cat(Command):
950
    """Write a file's text from a previous revision."""
951
952
    takes_options = ['revision']
953
    takes_args = ['filename']
954
955
    def run(self, filename, revision=None):
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
956
        if revision is None:
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
957
            raise BzrCommandError("bzr cat requires a revision number")
958
        elif len(revision) != 1:
959
            raise BzrCommandError("bzr cat --revision takes exactly one number")
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
960
        b = Branch.open_containing('.')
961
        b.print_file(b.relpath(filename), revision[0].in_history(b).revno)
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
962
963
964
class cmd_local_time_offset(Command):
965
    """Show the offset in seconds from GMT to local time."""
966
    hidden = True    
967
    def run(self):
968
        print bzrlib.osutils.local_time_offset()
969
970
971
972
class cmd_commit(Command):
973
    """Commit changes into a new revision.
974
    
975
    If no arguments are given, the entire tree is committed.
976
977
    If selected files are specified, only changes to those files are
978
    committed.  If a directory is specified then the directory and everything 
979
    within it is committed.
980
981
    A selected-file commit may fail in some cases where the committed
982
    tree would be invalid, such as trying to commit a file in a
983
    newly-added directory that is not itself committed.
984
    """
1185.16.3 by Martin Pool
- remove all TODOs from bzr help messages
985
    # TODO: Run hooks on tree to-be-committed, and after commit.
986
987
    # TODO: Strict commit that fails if there are unknown or deleted files.
988
    # TODO: Give better message for -s, --summary, used by tla people
989
990
    # XXX: verbose currently does nothing
991
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
992
    takes_args = ['selected*']
993
    takes_options = ['message', 'file', 'verbose', 'unchanged']
994
    aliases = ['ci', 'checkin']
995
996
    def run(self, message=None, file=None, verbose=True, selected_list=None,
997
            unchanged=False):
1185.14.10 by Aaron Bentley
Commit aborts with conflicts in the tree.
998
        from bzrlib.errors import PointlessCommit, ConflictsInTree
1167 by Martin Pool
- split commit message editor functions out into own file
999
        from bzrlib.msgeditor import edit_commit_message
1169 by Martin Pool
- clean up nasty code for inserting the status summary into commit template
1000
        from bzrlib.status import show_status
1001
        from cStringIO import StringIO
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
1002
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
1003
        b = Branch.open_containing('.')
1169 by Martin Pool
- clean up nasty code for inserting the status summary into commit template
1004
        if selected_list:
1005
            selected_list = [b.relpath(s) for s in selected_list]
1185.14.10 by Aaron Bentley
Commit aborts with conflicts in the tree.
1006
1169 by Martin Pool
- clean up nasty code for inserting the status summary into commit template
1007
            
1414 by Robert Collins
merge in an adjusted version of Jelmer's empty-log detection patch.
1008
        if message is None and not file:
1169 by Martin Pool
- clean up nasty code for inserting the status summary into commit template
1009
            catcher = StringIO()
1010
            show_status(b, specific_files=selected_list,
1011
                        to_file=catcher)
1012
            message = edit_commit_message(catcher.getvalue())
1393.3.2 by Jelmer Vernooij
Fix error message when an empty commit message was specified (when using an editor). Previously bzr warned that it wanted either --message or --file.
1013
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
1014
            if message is None:
1169 by Martin Pool
- clean up nasty code for inserting the status summary into commit template
1015
                raise BzrCommandError("please specify a commit message"
1016
                                      " with either --message or --file")
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
1017
        elif message and file:
1018
            raise BzrCommandError("please specify either --message or --file")
1019
        
1020
        if file:
1021
            import codecs
1022
            message = codecs.open(file, 'rt', bzrlib.user_encoding).read()
1023
1414 by Robert Collins
merge in an adjusted version of Jelmer's empty-log detection patch.
1024
        if message == "":
1025
                raise BzrCommandError("empty commit message specified")
1026
            
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
1027
        try:
1189 by Martin Pool
- BROKEN: partial support for commit into weave
1028
            b.commit(message,
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
1029
                     specific_files=selected_list,
1030
                     allow_pointless=unchanged)
1031
        except PointlessCommit:
1032
            # FIXME: This should really happen before the file is read in;
1033
            # perhaps prepare the commit; get the message; then actually commit
1034
            raise BzrCommandError("no changes to commit",
1035
                                  ["use --unchanged to commit anyhow"])
1185.14.10 by Aaron Bentley
Commit aborts with conflicts in the tree.
1036
        except ConflictsInTree:
1037
            raise BzrCommandError("Conflicts detected in working tree.  "
1038
                'Use "bzr conflicts" to list, "bzr resolve FILE" to resolve.')
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
1039
1040
1041
class cmd_check(Command):
1042
    """Validate consistency of branch history.
1043
1044
    This command checks various invariants about the branch storage to
1045
    detect data corruption or bzr bugs.
1046
    """
1047
    takes_args = ['dir?']
1449 by Robert Collins
teach check about ghosts
1048
    takes_options = ['verbose']
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
1049
1449 by Robert Collins
teach check about ghosts
1050
    def run(self, dir='.', verbose=False):
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
1051
        from bzrlib.check import check
1449 by Robert Collins
teach check about ghosts
1052
        check(Branch.open_containing(dir), verbose)
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
1053
1054
1055
class cmd_scan_cache(Command):
1056
    hidden = True
1057
    def run(self):
1058
        from bzrlib.hashcache import HashCache
1059
1060
        c = HashCache('.')
1061
        c.read()
1062
        c.scan()
1063
            
1064
        print '%6d stats' % c.stat_count
1065
        print '%6d in hashcache' % len(c._cache)
1066
        print '%6d files removed from cache' % c.removed_count
1067
        print '%6d hashes updated' % c.update_count
1068
        print '%6d files changed too recently to cache' % c.danger_count
1069
1070
        if c.needs_write:
1071
            c.write()
1072
            
1073
1074
1075
class cmd_upgrade(Command):
1076
    """Upgrade branch storage to current format.
1077
1078
    The check command or bzr developers may sometimes advise you to run
1079
    this command.
1377 by Martin Pool
- run conversion to weaves from the 'bzr upgrade' command
1080
1081
    This version of this command upgrades from the full-text storage
1082
    used by bzr 0.0.8 and earlier to the weave format (v5).
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
1083
    """
1084
    takes_args = ['dir?']
1085
1086
    def run(self, dir='.'):
1087
        from bzrlib.upgrade import upgrade
1377 by Martin Pool
- run conversion to weaves from the 'bzr upgrade' command
1088
        upgrade(dir)
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
1089
1090
1091
class cmd_whoami(Command):
1092
    """Show bzr user id."""
1093
    takes_options = ['email']
1094
    
1095
    def run(self, email=False):
1371 by Martin Pool
- raise NotBranchError if format file can't be read
1096
        try:
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
1097
            b = bzrlib.branch.Branch.open_containing('.')
1442.1.6 by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs
1098
            config = bzrlib.config.BranchConfig(b)
1371 by Martin Pool
- raise NotBranchError if format file can't be read
1099
        except NotBranchError:
1442.1.6 by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs
1100
            config = bzrlib.config.GlobalConfig()
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
1101
        
1102
        if email:
1442.1.6 by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs
1103
            print config.user_email()
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
1104
        else:
1442.1.6 by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs
1105
            print config.username()
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
1106
1107
1108
class cmd_selftest(Command):
1393.1.46 by Martin Pool
- bzr selftest arguments can be partial ids of tests to run
1109
    """Run internal test suite.
1110
    
1111
    This creates temporary test directories in the working directory,
1112
    but not existing data is affected.  These directories are deleted
1113
    if the tests pass, or left behind to help in debugging if they
1114
    fail.
1115
    
1116
    If arguments are given, they are regular expressions that say
1117
    which tests should run."""
1118
    # TODO: --list should give a list of all available tests
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
1119
    hidden = True
1185.1.57 by Robert Collins
nuke --pattern to selftest, replace with regexp.search calls.
1120
    takes_args = ['testspecs*']
1121
    takes_options = ['verbose']
1122
    def run(self, testspecs_list=None, verbose=False):
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
1123
        import bzrlib.ui
1124
        from bzrlib.selftest import selftest
1125
        # we don't want progress meters from the tests to go to the
1126
        # real output; and we don't want log messages cluttering up
1127
        # the real logs.
1128
        save_ui = bzrlib.ui.ui_factory
1129
        bzrlib.trace.info('running tests...')
1130
        try:
1131
            bzrlib.ui.ui_factory = bzrlib.ui.SilentUIFactory()
1185.1.57 by Robert Collins
nuke --pattern to selftest, replace with regexp.search calls.
1132
            if testspecs_list is not None:
1133
                pattern = '|'.join(testspecs_list)
1134
            else:
1135
                pattern = ".*"
1393.1.46 by Martin Pool
- bzr selftest arguments can be partial ids of tests to run
1136
            result = selftest(verbose=verbose, 
1185.1.57 by Robert Collins
nuke --pattern to selftest, replace with regexp.search calls.
1137
                              pattern=pattern)
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
1138
            if result:
1139
                bzrlib.trace.info('tests passed')
1140
            else:
1141
                bzrlib.trace.info('tests failed')
1142
            return int(not result)
1143
        finally:
1144
            bzrlib.ui.ui_factory = save_ui
1145
1146
1147
def show_version():
1148
    print "bzr (bazaar-ng) %s" % bzrlib.__version__
1149
    # is bzrlib itself in a branch?
1150
    bzrrev = bzrlib.get_bzr_revision()
1151
    if bzrrev:
1152
        print "  (bzr checkout, revision %d {%s})" % bzrrev
1153
    print bzrlib.__copyright__
1154
    print "http://bazaar-ng.org/"
1155
    print
1156
    print "bzr comes with ABSOLUTELY NO WARRANTY.  bzr is free software, and"
1157
    print "you may use, modify and redistribute it under the terms of the GNU"
1158
    print "General Public License version 2 or later."
1159
1160
1161
class cmd_version(Command):
1162
    """Show version of bzr."""
1163
    def run(self):
1164
        show_version()
1165
1166
class cmd_rocks(Command):
1167
    """Statement of optimism."""
1168
    hidden = True
1169
    def run(self):
1170
        print "it sure does!"
1171
1172
1173
class cmd_find_merge_base(Command):
1174
    """Find and print a base revision for merging two branches.
1175
    """
1185.16.3 by Martin Pool
- remove all TODOs from bzr help messages
1176
    # TODO: Options to specify revisions on either side, as if
1177
    #       merging only part of the history.
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
1178
    takes_args = ['branch', 'other']
1179
    hidden = True
1180
    
1181
    def run(self, branch, other):
1155 by Martin Pool
- update find-merge-base to use new common_ancestor code
1182
        from bzrlib.revision import common_ancestor, MultipleRevisionSources
1183
        
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
1184
        branch1 = Branch.open_containing(branch)
1185
        branch2 = Branch.open_containing(other)
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
1186
1155 by Martin Pool
- update find-merge-base to use new common_ancestor code
1187
        history_1 = branch1.revision_history()
1188
        history_2 = branch2.revision_history()
1189
1241 by Martin Pool
- rename last_patch to last_revision
1190
        last1 = branch1.last_revision()
1191
        last2 = branch2.last_revision()
1155 by Martin Pool
- update find-merge-base to use new common_ancestor code
1192
1193
        source = MultipleRevisionSources(branch1, branch2)
1194
        
1195
        base_rev_id = common_ancestor(last1, last2, source)
1196
1197
        print 'merge base is revision %s' % base_rev_id
1198
        
1199
        return
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
1200
1201
        if base_revno is None:
1202
            raise bzrlib.errors.UnrelatedBranches()
1203
1204
        print ' r%-6d in %s' % (base_revno, branch)
1205
1206
        other_revno = branch2.revision_id_to_revno(base_revid)
1207
        
1208
        print ' r%-6d in %s' % (other_revno, other)
1209
1210
1211
1212
class cmd_merge(Command):
1213
    """Perform a three-way merge.
1214
    
1172 by Martin Pool
- better explanation when merge fails with AmbiguousBase
1215
    The branch is the branch you will merge from.  By default, it will
1216
    merge the latest revision.  If you specify a revision, that
1217
    revision will be merged.  If you specify two revisions, the first
1218
    will be used as a BASE, and the second one as OTHER.  Revision
1219
    numbers are always relative to the specified branch.
1220
1221
    By default bzr will try to merge in all new work from the other
1222
    branch, automatically determining an appropriate base.  If this
1223
    fails, you may need to give an explicit base.
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
1224
    
1225
    Examples:
1226
1227
    To merge the latest revision from bzr.dev
1228
    bzr merge ../bzr.dev
1229
1230
    To merge changes up to and including revision 82 from bzr.dev
1231
    bzr merge -r 82 ../bzr.dev
1232
1233
    To merge the changes introduced by 82, without previous changes:
1234
    bzr merge -r 81..82 ../bzr.dev
1235
    
1236
    merge refuses to run if there are any uncommitted changes, unless
1237
    --force is given.
1238
    """
1239
    takes_args = ['branch?']
1240
    takes_options = ['revision', 'force', 'merge-type']
1241
1185.12.12 by Aaron Bentley
Made merge use pull location or die if no branch specified.
1242
    def run(self, branch=None, revision=None, force=False, 
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
1243
            merge_type=None):
1244
        from bzrlib.merge import merge
1245
        from bzrlib.merge_core import ApplyMerge3
1246
        if merge_type is None:
1247
            merge_type = ApplyMerge3
1185.12.12 by Aaron Bentley
Made merge use pull location or die if no branch specified.
1248
        if branch is None:
1249
            branch = Branch.open_containing('.').get_parent()
1250
            if branch is None:
1251
                raise BzrCommandError("No merge location known or specified.")
1252
            else:
1253
                print "Using saved location: %s" % branch 
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
1254
        if revision is None or len(revision) < 1:
1255
            base = [None, None]
974.1.52 by aaron.bentley at utoronto
Merged mpool's latest changes (~0.0.7)
1256
            other = [branch, -1]
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
1257
        else:
1258
            if len(revision) == 1:
974.1.52 by aaron.bentley at utoronto
Merged mpool's latest changes (~0.0.7)
1259
                base = [None, None]
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
1260
                other = [branch, revision[0].in_history(branch).revno]
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
1261
            else:
1262
                assert len(revision) == 2
1263
                if None in revision:
1264
                    raise BzrCommandError(
1265
                        "Merge doesn't permit that revision specifier.")
1185.5.1 by John Arbash Meinel
Applying bad-merge revision patch.
1266
                b = Branch.open(branch)
1267
1268
                base = [branch, revision[0].in_history(b).revno]
1269
                other = [branch, revision[1].in_history(b).revno]
1172 by Martin Pool
- better explanation when merge fails with AmbiguousBase
1270
1271
        try:
1272
            merge(other, base, check_clean=(not force), merge_type=merge_type)
1273
        except bzrlib.errors.AmbiguousBase, e:
1173 by Martin Pool
- message typo
1274
            m = ("sorry, bzr can't determine the right merge base yet\n"
1172 by Martin Pool
- better explanation when merge fails with AmbiguousBase
1275
                 "candidates are:\n  "
1276
                 + "\n  ".join(e.bases)
1277
                 + "\n"
1278
                 "please specify an explicit base with -r,\n"
1279
                 "and (if you want) report this to the bzr developers\n")
1280
            log_error(m)
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
1281
1282
1283
class cmd_revert(Command):
1284
    """Reverse all changes since the last commit.
1285
1286
    Only versioned files are affected.  Specify filenames to revert only 
1287
    those files.  By default, any files that are changed will be backed up
1288
    first.  Backup files have a '~' appended to their name.
1289
    """
1290
    takes_options = ['revision', 'no-backup']
1291
    takes_args = ['file*']
1292
    aliases = ['merge-revert']
1293
1294
    def run(self, revision=None, no_backup=False, file_list=None):
1295
        from bzrlib.merge import merge
1296
        from bzrlib.commands import parse_spec
1297
1298
        if file_list is not None:
1299
            if len(file_list) == 0:
1300
                raise BzrCommandError("No files specified")
1301
        if revision is None:
1185.5.8 by John Arbash Meinel
Fixed bzr revert with the new RevisionSpec code.
1302
            revno = -1
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
1303
        elif len(revision) != 1:
1304
            raise BzrCommandError('bzr revert --revision takes exactly 1 argument')
1185.5.8 by John Arbash Meinel
Fixed bzr revert with the new RevisionSpec code.
1305
        else:
1306
            b = Branch.open_containing('.')
1307
            revno = revision[0].in_history(b).revno
1308
        merge(('.', revno), parse_spec('.'),
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
1309
              check_clean=False,
1310
              ignore_zero=True,
1311
              backup_files=not no_backup,
1312
              file_list=file_list)
1313
        if not file_list:
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
1314
            Branch.open_containing('.').set_pending_merges([])
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
1315
1316
1317
class cmd_assert_fail(Command):
1318
    """Test reporting of assertion failures"""
1319
    hidden = True
1320
    def run(self):
1321
        assert False, "always fails"
1322
1323
1324
class cmd_help(Command):
1325
    """Show help on a command or other topic.
1326
1327
    For a list of all available commands, say 'bzr help commands'."""
1328
    takes_options = ['long']
1329
    takes_args = ['topic?']
1330
    aliases = ['?']
1331
    
1332
    def run(self, topic=None, long=False):
1333
        import help
1334
        if topic is None and long:
1335
            topic = "commands"
1336
        help.help(topic)
1337
1338
1339
class cmd_shell_complete(Command):
1340
    """Show appropriate completions for context.
1341
1342
    For a list of all available commands, say 'bzr shell-complete'."""
1343
    takes_args = ['context?']
1344
    aliases = ['s-c']
1345
    hidden = True
1346
    
1347
    def run(self, context=None):
1348
        import shellcomplete
1349
        shellcomplete.shellcomplete(context)
1350
1351
1228 by Martin Pool
- add fetch command as builtin
1352
class cmd_fetch(Command):
1353
    """Copy in history from another branch but don't merge it.
1354
1355
    This is an internal method used for pull and merge."""
1356
    hidden = True
1357
    takes_args = ['from_branch', 'to_branch']
1358
    def run(self, from_branch, to_branch):
1359
        from bzrlib.fetch import Fetcher
1360
        from bzrlib.branch import Branch
1361
        from_b = Branch(from_branch)
1362
        to_b = Branch(to_branch)
1363
        Fetcher(to_b, from_b)
1364
        
1365
1366
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
1367
class cmd_missing(Command):
1368
    """What is missing in this branch relative to other branch.
1369
    """
1228 by Martin Pool
- add fetch command as builtin
1370
    # TODO: rewrite this in terms of ancestry so that it shows only
1371
    # unmerged things
1372
    
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
1373
    takes_args = ['remote?']
1374
    aliases = ['mis', 'miss']
1375
    # We don't have to add quiet to the list, because 
1376
    # unknown options are parsed as booleans
1377
    takes_options = ['verbose', 'quiet']
1378
1379
    def run(self, remote=None, verbose=False, quiet=False):
1380
        from bzrlib.errors import BzrCommandError
1149 by Martin Pool
- make get_parent() be a method of Branch; add simple tests for it
1381
        from bzrlib.missing import show_missing
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
1382
1383
        if verbose and quiet:
1384
            raise BzrCommandError('Cannot pass both quiet and verbose')
1385
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
1386
        b = Branch.open_containing('.')
1149 by Martin Pool
- make get_parent() be a method of Branch; add simple tests for it
1387
        parent = b.get_parent()
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
1388
        if remote is None:
1389
            if parent is None:
1390
                raise BzrCommandError("No missing location known or specified.")
1391
            else:
1392
                if not quiet:
1393
                    print "Using last location: %s" % parent
1394
                remote = parent
1395
        elif parent is None:
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
1396
            # We only update parent if it did not exist, missing
1397
            # should not change the parent
974.1.79 by Aaron Bentley
Fixed issues with pull not having a default location after branch
1398
            b.set_parent(remote)
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
1399
        br_remote = Branch.open_containing(remote)
1147 by Martin Pool
- split builtin commands into separate module bzrlib.builtins;
1400
        return show_missing(b, br_remote, verbose=verbose, quiet=quiet)
1401
1402
1403
class cmd_plugins(Command):
1404
    """List plugins"""
1405
    hidden = True
1406
    def run(self):
1407
        import bzrlib.plugin
1408
        from inspect import getdoc
1409
        for plugin in bzrlib.plugin.all_plugins:
1410
            if hasattr(plugin, '__path__'):
1411
                print plugin.__path__[0]
1412
            elif hasattr(plugin, '__file__'):
1413
                print plugin.__file__
1414
            else:
1415
                print `plugin`
1416
                
1417
            d = getdoc(plugin)
1418
            if d:
1419
                print '\t', d.split('\n')[0]
1420
1421