1
# Copyright (C) 2004, 2005 by Canonical Ltd
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.
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.
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
23
from bzrlib.trace import mutter, note, log_error, warning
24
from bzrlib.errors import BzrError, BzrCheckError, BzrCommandError
25
from bzrlib.branch import Branch
26
from bzrlib import BZRDIR
27
from bzrlib.commands import Command
30
class cmd_status(Command):
31
"""Display status summary.
33
This reports on versioned and unknown files, reporting them
34
grouped by state. Possible states are:
37
Versioned in the working copy but not in the previous revision.
40
Versioned in the previous revision but removed or deleted
44
Path of this file changed from the previous revision;
45
the text may also have changed. This includes files whose
46
parent directory was renamed.
49
Text has changed since the previous revision.
52
Nothing about this file has changed since the previous revision.
53
Only shown with --all.
56
Not versioned and not matching an ignore pattern.
58
To see ignored files use 'bzr ignored'. For details in the
59
changes to file texts, use 'bzr diff'.
61
If no arguments are specified, the status of the entire working
62
directory is shown. Otherwise, only the status of the specified
63
files or directories is reported. If a directory is given, status
64
is reported for everything inside that directory.
66
# XXX: FIXME: bzr status should accept a -r option to show changes
67
# relative to a revision, or between revisions
69
takes_args = ['file*']
70
takes_options = ['all', 'show-ids']
71
aliases = ['st', 'stat']
73
def run(self, all=False, show_ids=False, file_list=None):
75
b = Branch.open_containing(file_list[0])
76
file_list = [b.relpath(x) for x in file_list]
77
# special case: only one path was given and it's the root
82
b = Branch.open_containing('.')
84
from bzrlib.status import show_status
85
show_status(b, show_unchanged=all, show_ids=show_ids,
86
specific_files=file_list)
89
class cmd_cat_revision(Command):
90
"""Write out metadata for a revision.
92
The revision to print can either be specified by a specific
93
revision identifier, or you can use --revision.
97
takes_args = ['revision_id?']
98
takes_options = ['revision']
100
def run(self, revision_id=None, revision=None):
101
from bzrlib.revisionspec import RevisionSpec
103
if revision_id is not None and revision is not None:
104
raise BzrCommandError('You can only supply one of revision_id or --revision')
105
if revision_id is None and revision is None:
106
raise BzrCommandError('You must supply either --revision or a revision_id')
107
b = Branch.open_containing('.')
108
if revision_id is not None:
109
sys.stdout.write(b.get_revision_xml_file(revision_id).read())
110
elif revision is not None:
113
raise BzrCommandError('You cannot specify a NULL revision.')
114
revno, rev_id = rev.in_history(b)
115
sys.stdout.write(b.get_revision_xml_file(rev_id).read())
118
class cmd_revno(Command):
119
"""Show current revision number.
121
This is equal to the number of revisions on this branch."""
123
print Branch.open_containing('.').revno()
126
class cmd_revision_info(Command):
127
"""Show revision number and revision id for a given revision identifier.
130
takes_args = ['revision_info*']
131
takes_options = ['revision']
132
def run(self, revision=None, revision_info_list=[]):
133
from bzrlib.revisionspec import RevisionSpec
136
if revision is not None:
137
revs.extend(revision)
138
if revision_info_list is not None:
139
for rev in revision_info_list:
140
revs.append(RevisionSpec(rev))
142
raise BzrCommandError('You must supply a revision identifier')
144
b = Branch.open_containing('.')
147
revinfo = rev.in_history(b)
148
if revinfo.revno is None:
149
print ' %s' % revinfo.rev_id
151
print '%4d %s' % (revinfo.revno, revinfo.rev_id)
154
class cmd_add(Command):
155
"""Add specified files or directories.
157
In non-recursive mode, all the named items are added, regardless
158
of whether they were previously ignored. A warning is given if
159
any of the named files are already versioned.
161
In recursive mode (the default), files are treated the same way
162
but the behaviour for directories is different. Directories that
163
are already versioned do not give a warning. All directories,
164
whether already versioned or not, are searched for files or
165
subdirectories that are neither versioned or ignored, and these
166
are added. This search proceeds recursively into versioned
167
directories. If no names are given '.' is assumed.
169
Therefore simply saying 'bzr add' will version all files that
170
are currently unknown.
172
Adding a file whose parent directory is not versioned will
173
implicitly add the parent, and so on up to the root. This means
174
you should never need to explictly add a directory, they'll just
175
get added when you add a file in the directory.
177
takes_args = ['file*']
178
takes_options = ['verbose', 'no-recurse']
180
def run(self, file_list, verbose=False, no_recurse=False):
181
# verbose currently has no effect
182
from bzrlib.add import smart_add, add_reporter_print
183
smart_add(file_list, not no_recurse, add_reporter_print)
187
class cmd_mkdir(Command):
188
"""Create a new versioned directory.
190
This is equivalent to creating the directory and then adding it.
192
takes_args = ['dir+']
194
def run(self, dir_list):
200
b = Branch.open_containing(d)
205
class cmd_relpath(Command):
206
"""Show path of a file relative to root"""
207
takes_args = ['filename']
210
def run(self, filename):
211
print Branch.open_containing(filename).relpath(filename)
215
class cmd_inventory(Command):
216
"""Show inventory of the current working copy or a revision."""
217
takes_options = ['revision', 'show-ids']
219
def run(self, revision=None, show_ids=False):
220
b = Branch.open_containing('.')
222
inv = b.read_working_inventory()
224
if len(revision) > 1:
225
raise BzrCommandError('bzr inventory --revision takes'
226
' exactly one revision identifier')
227
inv = b.get_revision_inventory(revision[0].in_history(b).rev_id)
229
for path, entry in inv.entries():
231
print '%-50s %s' % (path, entry.file_id)
236
class cmd_move(Command):
237
"""Move files to a different directory.
242
The destination must be a versioned directory in the same branch.
244
takes_args = ['source$', 'dest']
245
def run(self, source_list, dest):
246
b = Branch.open_containing('.')
248
# TODO: glob expansion on windows?
249
b.move([b.relpath(s) for s in source_list], b.relpath(dest))
252
class cmd_rename(Command):
253
"""Change the name of an entry.
256
bzr rename frob.c frobber.c
257
bzr rename src/frob.c lib/frob.c
259
It is an error if the destination name exists.
261
See also the 'move' command, which moves files into a different
262
directory without changing their name.
264
TODO: Some way to rename multiple files without invoking bzr for each
266
takes_args = ['from_name', 'to_name']
268
def run(self, from_name, to_name):
269
b = Branch.open_containing('.')
270
b.rename_one(b.relpath(from_name), b.relpath(to_name))
274
class cmd_mv(Command):
275
"""Move or rename a file.
278
bzr mv OLDNAME NEWNAME
279
bzr mv SOURCE... DESTINATION
281
If the last argument is a versioned directory, all the other names
282
are moved into it. Otherwise, there must be exactly two arguments
283
and the file is changed to a new name, which must not already exist.
285
Files cannot be moved between branches.
287
takes_args = ['names*']
288
def run(self, names_list):
289
if len(names_list) < 2:
290
raise BzrCommandError("missing file argument")
291
b = Branch.open_containing(names_list[0])
293
rel_names = [b.relpath(x) for x in names_list]
295
if os.path.isdir(names_list[-1]):
296
# move into existing directory
297
for pair in b.move(rel_names[:-1], rel_names[-1]):
298
print "%s => %s" % pair
300
if len(names_list) != 2:
301
raise BzrCommandError('to mv multiple files the destination '
302
'must be a versioned directory')
303
b.rename_one(rel_names[0], rel_names[1])
304
print "%s => %s" % (rel_names[0], rel_names[1])
309
class cmd_pull(Command):
310
"""Pull any changes from another branch into the current one.
312
If the location is omitted, the last-used location will be used.
313
Both the revision history and the working directory will be
316
This command only works on branches that have not diverged. Branches are
317
considered diverged if both branches have had commits without first
318
pulling from the other.
320
If branches have diverged, you can use 'bzr merge' to pull the text changes
321
from one into the other.
323
takes_args = ['location?']
325
def run(self, location=None):
326
from bzrlib.merge import merge
328
from shutil import rmtree
331
br_to = Branch.open_containing('.')
332
stored_loc = br_to.get_parent()
334
if stored_loc is None:
335
raise BzrCommandError("No pull location known or specified.")
337
print "Using last location: %s" % stored_loc
338
location = stored_loc
339
cache_root = tempfile.mkdtemp()
340
from bzrlib.errors import DivergedBranches
341
br_from = Branch.open_containing(location)
342
location = br_from.base
343
old_revno = br_to.revno()
345
from bzrlib.errors import DivergedBranches
346
br_from = Branch.open(location)
347
br_from.setup_caching(cache_root)
348
location = br_from.base
349
old_revno = br_to.revno()
351
br_to.update_revisions(br_from)
352
except DivergedBranches:
353
raise BzrCommandError("These branches have diverged."
356
merge(('.', -1), ('.', old_revno), check_clean=False)
357
if location != stored_loc:
358
br_to.set_parent(location)
364
class cmd_branch(Command):
365
"""Create a new copy of a branch.
367
If the TO_LOCATION is omitted, the last component of the FROM_LOCATION will
368
be used. In other words, "branch ../foo/bar" will attempt to create ./bar.
370
To retrieve the branch as of a particular revision, supply the --revision
371
parameter, as in "branch foo/bar -r 5".
373
takes_args = ['from_location', 'to_location?']
374
takes_options = ['revision']
375
aliases = ['get', 'clone']
377
def run(self, from_location, to_location=None, revision=None):
378
from bzrlib.branch import copy_branch
381
from shutil import rmtree
382
cache_root = tempfile.mkdtemp()
386
elif len(revision) > 1:
387
raise BzrCommandError(
388
'bzr branch --revision takes exactly 1 revision value')
390
br_from = Branch.open(from_location)
392
if e.errno == errno.ENOENT:
393
raise BzrCommandError('Source location "%s" does not'
394
' exist.' % to_location)
397
br_from.setup_caching(cache_root)
398
if len(revision) == 1 and revision[0] is not None:
399
revno = revision[0].in_history(br_from)[0]
402
if to_location is None:
403
to_location = os.path.basename(from_location.rstrip("/\\"))
405
os.mkdir(to_location)
407
if e.errno == errno.EEXIST:
408
raise BzrCommandError('Target directory "%s" already'
409
' exists.' % to_location)
410
if e.errno == errno.ENOENT:
411
raise BzrCommandError('Parent of "%s" does not exist.' %
416
copy_branch(br_from, to_location, revno)
417
except bzrlib.errors.NoSuchRevision:
419
msg = "The branch %s has no revision %d." % (from_location, revision[0])
420
raise BzrCommandError(msg)
425
class cmd_renames(Command):
426
"""Show list of renamed files.
428
TODO: Option to show renames between two historical versions.
430
TODO: Only show renames under dir, rather than in the whole branch.
432
takes_args = ['dir?']
434
def run(self, dir='.'):
435
b = Branch.open_containing(dir)
436
old_inv = b.basis_tree().inventory
437
new_inv = b.read_working_inventory()
439
renames = list(bzrlib.tree.find_renames(old_inv, new_inv))
441
for old_name, new_name in renames:
442
print "%s => %s" % (old_name, new_name)
445
class cmd_info(Command):
446
"""Show statistical information about a branch."""
447
takes_args = ['branch?']
449
def run(self, branch=None):
452
b = Branch.open_containing(branch)
456
class cmd_remove(Command):
457
"""Make a file unversioned.
459
This makes bzr stop tracking changes to a versioned file. It does
460
not delete the working copy.
462
takes_args = ['file+']
463
takes_options = ['verbose']
465
def run(self, file_list, verbose=False):
466
b = Branch.open_containing(file_list[0])
467
b.remove([b.relpath(f) for f in file_list], verbose=verbose)
470
class cmd_file_id(Command):
471
"""Print file_id of a particular file or directory.
473
The file_id is assigned when the file is first added and remains the
474
same through all revisions where the file exists, even when it is
478
takes_args = ['filename']
479
def run(self, filename):
480
b = Branch.open_containing(filename)
481
i = b.inventory.path2id(b.relpath(filename))
483
raise BzrError("%r is not a versioned file" % filename)
488
class cmd_file_path(Command):
489
"""Print path of file_ids to a file or directory.
491
This prints one line for each directory down to the target,
492
starting at the branch root."""
494
takes_args = ['filename']
495
def run(self, filename):
496
b = Branch.open_containing(filename)
498
fid = inv.path2id(b.relpath(filename))
500
raise BzrError("%r is not a versioned file" % filename)
501
for fip in inv.get_idpath(fid):
505
class cmd_revision_history(Command):
506
"""Display list of revision ids on this branch."""
509
for patchid in Branch.open_containing('.').revision_history():
513
class cmd_directories(Command):
514
"""Display list of versioned directories in this branch."""
516
for name, ie in Branch.open_containing('.').read_working_inventory().directories():
523
class cmd_init(Command):
524
"""Make a directory into a versioned branch.
526
Use this to create an empty branch, or before importing an
529
Recipe for importing a tree of files:
534
bzr commit -m 'imported project'
537
from bzrlib.branch import Branch
538
Branch.initialize('.')
541
class cmd_diff(Command):
542
"""Show differences in working tree.
544
If files are listed, only the changes in those files are listed.
545
Otherwise, all changes for the tree are listed.
547
TODO: Allow diff across branches.
549
TODO: Option to use external diff command; could be GNU diff, wdiff,
552
TODO: Python difflib is not exactly the same as unidiff; should
553
either fix it up or prefer to use an external diff.
555
TODO: If a directory is given, diff everything under that.
557
TODO: Selected-file diff is inefficient and doesn't show you
560
TODO: This probably handles non-Unix newlines poorly.
568
takes_args = ['file*']
569
takes_options = ['revision', 'diff-options']
570
aliases = ['di', 'dif']
572
def run(self, revision=None, file_list=None, diff_options=None):
573
from bzrlib.diff import show_diff
576
b = Branch.open_containing(file_list[0])
577
file_list = [b.relpath(f) for f in file_list]
578
if file_list == ['']:
579
# just pointing to top-of-tree
582
b = Branch.open_containing('.')
584
if revision is not None:
585
if len(revision) == 1:
586
show_diff(b, revision[0], specific_files=file_list,
587
external_diff_options=diff_options)
588
elif len(revision) == 2:
589
show_diff(b, revision[0], specific_files=file_list,
590
external_diff_options=diff_options,
591
revision2=revision[1])
593
raise BzrCommandError('bzr diff --revision takes exactly one or two revision identifiers')
595
show_diff(b, None, specific_files=file_list,
596
external_diff_options=diff_options)
601
class cmd_deleted(Command):
602
"""List files deleted in the working tree.
604
TODO: Show files deleted since a previous revision, or between two revisions.
606
def run(self, show_ids=False):
607
b = Branch.open_containing('.')
609
new = b.working_tree()
611
## TODO: Much more efficient way to do this: read in new
612
## directories with readdir, rather than stating each one. Same
613
## level of effort but possibly much less IO. (Or possibly not,
614
## if the directories are very large...)
616
for path, ie in old.inventory.iter_entries():
617
if not new.has_id(ie.file_id):
619
print '%-50s %s' % (path, ie.file_id)
624
class cmd_modified(Command):
625
"""List files modified in working tree."""
628
from bzrlib.delta import compare_trees
630
b = Branch.open_containing('.')
631
td = compare_trees(b.basis_tree(), b.working_tree())
633
for path, id, kind in td.modified:
638
class cmd_added(Command):
639
"""List files added in working tree."""
642
b = Branch.open_containing('.')
643
wt = b.working_tree()
644
basis_inv = b.basis_tree().inventory
647
if file_id in basis_inv:
649
path = inv.id2path(file_id)
650
if not os.access(b.abspath(path), os.F_OK):
656
class cmd_root(Command):
657
"""Show the tree root directory.
659
The root is the nearest enclosing directory with a .bzr control
661
takes_args = ['filename?']
662
def run(self, filename=None):
663
"""Print the branch root."""
664
b = Branch.open_containing(filename)
668
class cmd_log(Command):
669
"""Show log of this branch.
671
To request a range of logs, you can use the command -r begin:end
672
-r revision requests a specific revision, -r :end or -r begin: are
675
--message allows you to give a regular expression, which will be evaluated
676
so that only matching entries will be displayed.
678
TODO: Make --revision support uuid: and hash: [future tag:] notation.
682
takes_args = ['filename?']
683
takes_options = ['forward', 'timezone', 'verbose', 'show-ids', 'revision',
684
'long', 'message', 'short',]
686
def run(self, filename=None, timezone='original',
694
from bzrlib.log import log_formatter, show_log
697
direction = (forward and 'forward') or 'reverse'
700
b = Branch.open_containing(filename)
701
fp = b.relpath(filename)
703
file_id = b.read_working_inventory().path2id(fp)
705
file_id = None # points to branch root
707
b = Branch.open_containing('.')
713
elif len(revision) == 1:
714
rev1 = rev2 = revision[0].in_history(b).revno
715
elif len(revision) == 2:
716
rev1 = revision[0].in_history(b).revno
717
rev2 = revision[1].in_history(b).revno
719
raise BzrCommandError('bzr log --revision takes one or two values.')
726
mutter('encoding log as %r' % bzrlib.user_encoding)
728
# use 'replace' so that we don't abort if trying to write out
729
# in e.g. the default C locale.
730
outf = codecs.getwriter(bzrlib.user_encoding)(sys.stdout, errors='replace')
736
lf = log_formatter(log_format,
739
show_timezone=timezone)
752
class cmd_touching_revisions(Command):
753
"""Return revision-ids which affected a particular file.
755
A more user-friendly interface is "bzr log FILE"."""
757
takes_args = ["filename"]
758
def run(self, filename):
759
b = Branch.open_containing(filename)
760
inv = b.read_working_inventory()
761
file_id = inv.path2id(b.relpath(filename))
762
for revno, revision_id, what in bzrlib.log.find_touching_revisions(b, file_id):
763
print "%6d %s" % (revno, what)
766
class cmd_ls(Command):
767
"""List files in a tree.
769
TODO: Take a revision or remote path and list that tree instead.
772
def run(self, revision=None, verbose=False):
773
b = Branch.open_containing('.')
775
tree = b.working_tree()
777
tree = b.revision_tree(revision.in_history(b).rev_id)
779
for fp, fc, kind, fid in tree.list_files():
781
if kind == 'directory':
788
print '%-8s %s%s' % (fc, fp, kindch)
794
class cmd_unknowns(Command):
795
"""List unknown files."""
797
from bzrlib.osutils import quotefn
798
for f in Branch.open_containing('.').unknowns():
803
class cmd_ignore(Command):
804
"""Ignore a command or pattern.
806
To remove patterns from the ignore list, edit the .bzrignore file.
808
If the pattern contains a slash, it is compared to the whole path
809
from the branch root. Otherwise, it is comapred to only the last
810
component of the path.
812
Ignore patterns are case-insensitive on case-insensitive systems.
814
Note: wildcards must be quoted from the shell on Unix.
817
bzr ignore ./Makefile
820
takes_args = ['name_pattern']
822
def run(self, name_pattern):
823
from bzrlib.atomicfile import AtomicFile
826
b = Branch.open_containing('.')
827
ifn = b.abspath('.bzrignore')
829
if os.path.exists(ifn):
832
igns = f.read().decode('utf-8')
838
# TODO: If the file already uses crlf-style termination, maybe
839
# we should use that for the newly added lines?
841
if igns and igns[-1] != '\n':
843
igns += name_pattern + '\n'
846
f = AtomicFile(ifn, 'wt')
847
f.write(igns.encode('utf-8'))
852
inv = b.working_tree().inventory
853
if inv.path2id('.bzrignore'):
854
mutter('.bzrignore is already versioned')
856
mutter('need to make new .bzrignore file versioned')
857
b.add(['.bzrignore'])
861
class cmd_ignored(Command):
862
"""List ignored files and the patterns that matched them.
864
See also: bzr ignore"""
866
tree = Branch.open_containing('.').working_tree()
867
for path, file_class, kind, file_id in tree.list_files():
868
if file_class != 'I':
870
## XXX: Slightly inefficient since this was already calculated
871
pat = tree.is_ignored(path)
872
print '%-50s %s' % (path, pat)
875
class cmd_lookup_revision(Command):
876
"""Lookup the revision-id from a revision-number
879
bzr lookup-revision 33
882
takes_args = ['revno']
884
def run(self, revno):
888
raise BzrCommandError("not a valid revision-number: %r" % revno)
890
print Branch.open_containing('.').get_rev_id(revno)
893
class cmd_export(Command):
894
"""Export past revision to destination directory.
896
If no revision is specified this exports the last committed revision.
898
Format may be an "exporter" name, such as tar, tgz, tbz2. If none is
899
given, try to find the format with the extension. If no extension
900
is found exports to a directory (equivalent to --format=dir).
902
Root may be the top directory for tar, tgz and tbz2 formats. If none
903
is given, the top directory will be the root name of the file."""
904
# TODO: list known exporters
905
takes_args = ['dest']
906
takes_options = ['revision', 'format', 'root']
907
def run(self, dest, revision=None, format=None, root=None):
909
b = Branch.open_containing('.')
911
rev_id = b.last_patch()
913
if len(revision) != 1:
914
raise BzrError('bzr export --revision takes exactly 1 argument')
915
rev_id = revision[0].in_history(b).rev_id
916
t = b.revision_tree(rev_id)
917
root, ext = os.path.splitext(dest)
921
elif ext in (".gz", ".tgz"):
923
elif ext in (".bz2", ".tbz2"):
927
t.export(dest, format, root)
930
class cmd_cat(Command):
931
"""Write a file's text from a previous revision."""
933
takes_options = ['revision']
934
takes_args = ['filename']
936
def run(self, filename, revision=None):
938
raise BzrCommandError("bzr cat requires a revision number")
939
elif len(revision) != 1:
940
raise BzrCommandError("bzr cat --revision takes exactly one number")
941
b = Branch.open_containing('.')
942
b.print_file(b.relpath(filename), revision[0].in_history(b).revno)
945
class cmd_local_time_offset(Command):
946
"""Show the offset in seconds from GMT to local time."""
949
print bzrlib.osutils.local_time_offset()
953
class cmd_commit(Command):
954
"""Commit changes into a new revision.
956
If no arguments are given, the entire tree is committed.
958
If selected files are specified, only changes to those files are
959
committed. If a directory is specified then the directory and everything
960
within it is committed.
962
A selected-file commit may fail in some cases where the committed
963
tree would be invalid, such as trying to commit a file in a
964
newly-added directory that is not itself committed.
966
TODO: Run hooks on tree to-be-committed, and after commit.
968
TODO: Strict commit that fails if there are unknown or deleted files.
970
takes_args = ['selected*']
971
takes_options = ['message', 'file', 'verbose', 'unchanged']
972
aliases = ['ci', 'checkin']
974
# TODO: Give better message for -s, --summary, used by tla people
976
def run(self, message=None, file=None, verbose=True, selected_list=None,
978
from bzrlib.errors import PointlessCommit
979
from bzrlib.msgeditor import edit_commit_message
980
from bzrlib.status import show_status
981
from cStringIO import StringIO
983
b = Branch.open_containing('.')
985
selected_list = [b.relpath(s) for s in selected_list]
987
if not message and not file:
989
show_status(b, specific_files=selected_list,
991
message = edit_commit_message(catcher.getvalue())
994
raise BzrCommandError("please specify a commit message"
995
" with either --message or --file")
996
elif message and file:
997
raise BzrCommandError("please specify either --message or --file")
1001
message = codecs.open(file, 'rt', bzrlib.user_encoding).read()
1004
b.commit(message, verbose=verbose,
1005
specific_files=selected_list,
1006
allow_pointless=unchanged)
1007
except PointlessCommit:
1008
# FIXME: This should really happen before the file is read in;
1009
# perhaps prepare the commit; get the message; then actually commit
1010
raise BzrCommandError("no changes to commit",
1011
["use --unchanged to commit anyhow"])
1014
class cmd_check(Command):
1015
"""Validate consistency of branch history.
1017
This command checks various invariants about the branch storage to
1018
detect data corruption or bzr bugs.
1020
takes_args = ['dir?']
1022
def run(self, dir='.'):
1023
from bzrlib.check import check
1025
check(Branch.open_containing(dir))
1028
class cmd_scan_cache(Command):
1031
from bzrlib.hashcache import HashCache
1037
print '%6d stats' % c.stat_count
1038
print '%6d in hashcache' % len(c._cache)
1039
print '%6d files removed from cache' % c.removed_count
1040
print '%6d hashes updated' % c.update_count
1041
print '%6d files changed too recently to cache' % c.danger_count
1048
class cmd_upgrade(Command):
1049
"""Upgrade branch storage to current format.
1051
The check command or bzr developers may sometimes advise you to run
1054
takes_args = ['dir?']
1056
def run(self, dir='.'):
1057
from bzrlib.upgrade import upgrade
1058
upgrade(Branch.open_containing(dir))
1062
class cmd_whoami(Command):
1063
"""Show bzr user id."""
1064
takes_options = ['email']
1066
def run(self, email=False):
1068
b = bzrlib.branch.Branch.open_containing('.')
1073
print bzrlib.osutils.user_email(b)
1075
print bzrlib.osutils.username(b)
1078
class cmd_selftest(Command):
1079
"""Run internal test suite"""
1081
takes_options = ['verbose', 'pattern']
1082
def run(self, verbose=False, pattern=".*"):
1084
from bzrlib.selftest import selftest
1085
# we don't want progress meters from the tests to go to the
1086
# real output; and we don't want log messages cluttering up
1088
save_ui = bzrlib.ui.ui_factory
1089
bzrlib.trace.info('running tests...')
1091
bzrlib.ui.ui_factory = bzrlib.ui.SilentUIFactory()
1092
result = selftest(verbose=verbose, pattern=pattern)
1094
bzrlib.trace.info('tests passed')
1096
bzrlib.trace.info('tests failed')
1097
return int(not result)
1099
bzrlib.ui.ui_factory = save_ui
1103
print "bzr (bazaar-ng) %s" % bzrlib.__version__
1104
# is bzrlib itself in a branch?
1105
bzrrev = bzrlib.get_bzr_revision()
1107
print " (bzr checkout, revision %d {%s})" % bzrrev
1108
print bzrlib.__copyright__
1109
print "http://bazaar-ng.org/"
1111
print "bzr comes with ABSOLUTELY NO WARRANTY. bzr is free software, and"
1112
print "you may use, modify and redistribute it under the terms of the GNU"
1113
print "General Public License version 2 or later."
1116
class cmd_version(Command):
1117
"""Show version of bzr."""
1121
class cmd_rocks(Command):
1122
"""Statement of optimism."""
1125
print "it sure does!"
1128
class cmd_find_merge_base(Command):
1129
"""Find and print a base revision for merging two branches.
1131
TODO: Options to specify revisions on either side, as if
1132
merging only part of the history.
1134
takes_args = ['branch', 'other']
1137
def run(self, branch, other):
1138
from bzrlib.revision import common_ancestor, MultipleRevisionSources
1140
branch1 = Branch.open_containing(branch)
1141
branch2 = Branch.open_containing(other)
1143
history_1 = branch1.revision_history()
1144
history_2 = branch2.revision_history()
1146
last1 = branch1.last_patch()
1147
last2 = branch2.last_patch()
1149
source = MultipleRevisionSources(branch1, branch2)
1151
base_rev_id = common_ancestor(last1, last2, source)
1153
print 'merge base is revision %s' % base_rev_id
1157
if base_revno is None:
1158
raise bzrlib.errors.UnrelatedBranches()
1160
print ' r%-6d in %s' % (base_revno, branch)
1162
other_revno = branch2.revision_id_to_revno(base_revid)
1164
print ' r%-6d in %s' % (other_revno, other)
1168
class cmd_merge(Command):
1169
"""Perform a three-way merge.
1171
The branch is the branch you will merge from. By default, it will
1172
merge the latest revision. If you specify a revision, that
1173
revision will be merged. If you specify two revisions, the first
1174
will be used as a BASE, and the second one as OTHER. Revision
1175
numbers are always relative to the specified branch.
1177
By default bzr will try to merge in all new work from the other
1178
branch, automatically determining an appropriate base. If this
1179
fails, you may need to give an explicit base.
1183
To merge the latest revision from bzr.dev
1184
bzr merge ../bzr.dev
1186
To merge changes up to and including revision 82 from bzr.dev
1187
bzr merge -r 82 ../bzr.dev
1189
To merge the changes introduced by 82, without previous changes:
1190
bzr merge -r 81..82 ../bzr.dev
1192
merge refuses to run if there are any uncommitted changes, unless
1195
takes_args = ['branch?']
1196
takes_options = ['revision', 'force', 'merge-type']
1198
def run(self, branch='.', revision=None, force=False,
1200
from bzrlib.merge import merge
1201
from bzrlib.merge_core import ApplyMerge3
1202
if merge_type is None:
1203
merge_type = ApplyMerge3
1205
if revision is None or len(revision) < 1:
1207
other = [branch, -1]
1209
if len(revision) == 1:
1211
other = [branch, revision[0].in_history(branch).revno]
1213
assert len(revision) == 2
1214
if None in revision:
1215
raise BzrCommandError(
1216
"Merge doesn't permit that revision specifier.")
1217
from bzrlib.branch import Branch
1218
b = Branch.open(branch)
1220
base = [branch, revision[0].in_history(b).revno]
1221
other = [branch, revision[1].in_history(b).revno]
1224
merge(other, base, check_clean=(not force), merge_type=merge_type)
1225
except bzrlib.errors.AmbiguousBase, e:
1226
m = ("sorry, bzr can't determine the right merge base yet\n"
1227
"candidates are:\n "
1228
+ "\n ".join(e.bases)
1230
"please specify an explicit base with -r,\n"
1231
"and (if you want) report this to the bzr developers\n")
1235
class cmd_revert(Command):
1236
"""Reverse all changes since the last commit.
1238
Only versioned files are affected. Specify filenames to revert only
1239
those files. By default, any files that are changed will be backed up
1240
first. Backup files have a '~' appended to their name.
1242
takes_options = ['revision', 'no-backup']
1243
takes_args = ['file*']
1244
aliases = ['merge-revert']
1246
def run(self, revision=None, no_backup=False, file_list=None):
1247
from bzrlib.merge import merge
1248
from bzrlib.branch import Branch
1249
from bzrlib.commands import parse_spec
1251
if file_list is not None:
1252
if len(file_list) == 0:
1253
raise BzrCommandError("No files specified")
1254
if revision is None:
1256
elif len(revision) != 1:
1257
raise BzrCommandError('bzr revert --revision takes exactly 1 argument')
1259
b = Branch.open_containing('.')
1260
revno = revision[0].in_history(b).revno
1261
merge(('.', revno), parse_spec('.'),
1264
backup_files=not no_backup,
1265
file_list=file_list)
1267
Branch.open_containing('.').set_pending_merges([])
1270
class cmd_assert_fail(Command):
1271
"""Test reporting of assertion failures"""
1274
assert False, "always fails"
1277
class cmd_help(Command):
1278
"""Show help on a command or other topic.
1280
For a list of all available commands, say 'bzr help commands'."""
1281
takes_options = ['long']
1282
takes_args = ['topic?']
1285
def run(self, topic=None, long=False):
1287
if topic is None and long:
1292
class cmd_shell_complete(Command):
1293
"""Show appropriate completions for context.
1295
For a list of all available commands, say 'bzr shell-complete'."""
1296
takes_args = ['context?']
1300
def run(self, context=None):
1301
import shellcomplete
1302
shellcomplete.shellcomplete(context)
1305
class cmd_missing(Command):
1306
"""What is missing in this branch relative to other branch.
1308
takes_args = ['remote?']
1309
aliases = ['mis', 'miss']
1310
# We don't have to add quiet to the list, because
1311
# unknown options are parsed as booleans
1312
takes_options = ['verbose', 'quiet']
1314
def run(self, remote=None, verbose=False, quiet=False):
1315
from bzrlib.errors import BzrCommandError
1316
from bzrlib.missing import show_missing
1318
if verbose and quiet:
1319
raise BzrCommandError('Cannot pass both quiet and verbose')
1321
b = Branch.open_containing('.')
1322
parent = b.get_parent()
1325
raise BzrCommandError("No missing location known or specified.")
1328
print "Using last location: %s" % parent
1330
elif parent is None:
1331
# We only update parent if it did not exist, missing
1332
# should not change the parent
1333
b.set_parent(remote)
1334
br_remote = Branch.open_containing(remote)
1336
return show_missing(b, br_remote, verbose=verbose, quiet=quiet)
1340
class cmd_plugins(Command):
1344
import bzrlib.plugin
1345
from inspect import getdoc
1346
for plugin in bzrlib.plugin.all_plugins:
1347
if hasattr(plugin, '__path__'):
1348
print plugin.__path__[0]
1349
elif hasattr(plugin, '__file__'):
1350
print plugin.__file__
1356
print '\t', d.split('\n')[0]