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 to_location is None:
399
to_location = os.path.basename(from_location.rstrip("/\\"))
401
os.mkdir(to_location)
403
if e.errno == errno.EEXIST:
404
raise BzrCommandError('Target directory "%s" already'
405
' exists.' % to_location)
406
if e.errno == errno.ENOENT:
407
raise BzrCommandError('Parent of "%s" does not exist.' %
412
copy_branch(br_from, to_location, revision[0])
413
except bzrlib.errors.NoSuchRevision:
415
msg = "The branch %s has no revision %d." % (from_location, revision[0])
416
raise BzrCommandError(msg)
421
class cmd_renames(Command):
422
"""Show list of renamed files.
424
TODO: Option to show renames between two historical versions.
426
TODO: Only show renames under dir, rather than in the whole branch.
428
takes_args = ['dir?']
430
def run(self, dir='.'):
431
b = Branch.open_containing(dir)
432
old_inv = b.basis_tree().inventory
433
new_inv = b.read_working_inventory()
435
renames = list(bzrlib.tree.find_renames(old_inv, new_inv))
437
for old_name, new_name in renames:
438
print "%s => %s" % (old_name, new_name)
441
class cmd_info(Command):
442
"""Show statistical information about a branch."""
443
takes_args = ['branch?']
445
def run(self, branch=None):
448
b = Branch.open_containing(branch)
452
class cmd_remove(Command):
453
"""Make a file unversioned.
455
This makes bzr stop tracking changes to a versioned file. It does
456
not delete the working copy.
458
takes_args = ['file+']
459
takes_options = ['verbose']
461
def run(self, file_list, verbose=False):
462
b = Branch.open_containing(file_list[0])
463
b.remove([b.relpath(f) for f in file_list], verbose=verbose)
466
class cmd_file_id(Command):
467
"""Print file_id of a particular file or directory.
469
The file_id is assigned when the file is first added and remains the
470
same through all revisions where the file exists, even when it is
474
takes_args = ['filename']
475
def run(self, filename):
476
b = Branch.open_containing(filename)
477
i = b.inventory.path2id(b.relpath(filename))
479
raise BzrError("%r is not a versioned file" % filename)
484
class cmd_file_path(Command):
485
"""Print path of file_ids to a file or directory.
487
This prints one line for each directory down to the target,
488
starting at the branch root."""
490
takes_args = ['filename']
491
def run(self, filename):
492
b = Branch.open_containing(filename)
494
fid = inv.path2id(b.relpath(filename))
496
raise BzrError("%r is not a versioned file" % filename)
497
for fip in inv.get_idpath(fid):
501
class cmd_revision_history(Command):
502
"""Display list of revision ids on this branch."""
505
for patchid in Branch.open_containing('.').revision_history():
509
class cmd_directories(Command):
510
"""Display list of versioned directories in this branch."""
512
for name, ie in Branch.open_containing('.').read_working_inventory().directories():
519
class cmd_init(Command):
520
"""Make a directory into a versioned branch.
522
Use this to create an empty branch, or before importing an
525
Recipe for importing a tree of files:
530
bzr commit -m 'imported project'
533
from bzrlib.branch import Branch
534
Branch.initialize('.')
537
class cmd_diff(Command):
538
"""Show differences in working tree.
540
If files are listed, only the changes in those files are listed.
541
Otherwise, all changes for the tree are listed.
543
TODO: Allow diff across branches.
545
TODO: Option to use external diff command; could be GNU diff, wdiff,
548
TODO: Python difflib is not exactly the same as unidiff; should
549
either fix it up or prefer to use an external diff.
551
TODO: If a directory is given, diff everything under that.
553
TODO: Selected-file diff is inefficient and doesn't show you
556
TODO: This probably handles non-Unix newlines poorly.
564
takes_args = ['file*']
565
takes_options = ['revision', 'diff-options']
566
aliases = ['di', 'dif']
568
def run(self, revision=None, file_list=None, diff_options=None):
569
from bzrlib.diff import show_diff
572
b = Branch.open_containing(file_list[0])
573
file_list = [b.relpath(f) for f in file_list]
574
if file_list == ['']:
575
# just pointing to top-of-tree
578
b = Branch.open_containing('.')
580
if revision is not None:
581
if len(revision) == 1:
582
show_diff(b, revision[0], specific_files=file_list,
583
external_diff_options=diff_options)
584
elif len(revision) == 2:
585
show_diff(b, revision[0], specific_files=file_list,
586
external_diff_options=diff_options,
587
revision2=revision[1])
589
raise BzrCommandError('bzr diff --revision takes exactly one or two revision identifiers')
591
show_diff(b, None, specific_files=file_list,
592
external_diff_options=diff_options)
597
class cmd_deleted(Command):
598
"""List files deleted in the working tree.
600
TODO: Show files deleted since a previous revision, or between two revisions.
602
def run(self, show_ids=False):
603
b = Branch.open_containing('.')
605
new = b.working_tree()
607
## TODO: Much more efficient way to do this: read in new
608
## directories with readdir, rather than stating each one. Same
609
## level of effort but possibly much less IO. (Or possibly not,
610
## if the directories are very large...)
612
for path, ie in old.inventory.iter_entries():
613
if not new.has_id(ie.file_id):
615
print '%-50s %s' % (path, ie.file_id)
620
class cmd_modified(Command):
621
"""List files modified in working tree."""
624
from bzrlib.delta import compare_trees
626
b = Branch.open_containing('.')
627
td = compare_trees(b.basis_tree(), b.working_tree())
629
for path, id, kind in td.modified:
634
class cmd_added(Command):
635
"""List files added in working tree."""
638
b = Branch.open_containing('.')
639
wt = b.working_tree()
640
basis_inv = b.basis_tree().inventory
643
if file_id in basis_inv:
645
path = inv.id2path(file_id)
646
if not os.access(b.abspath(path), os.F_OK):
652
class cmd_root(Command):
653
"""Show the tree root directory.
655
The root is the nearest enclosing directory with a .bzr control
657
takes_args = ['filename?']
658
def run(self, filename=None):
659
"""Print the branch root."""
660
b = Branch.open_containing(filename)
664
class cmd_log(Command):
665
"""Show log of this branch.
667
To request a range of logs, you can use the command -r begin:end
668
-r revision requests a specific revision, -r :end or -r begin: are
671
--message allows you to give a regular expression, which will be evaluated
672
so that only matching entries will be displayed.
674
TODO: Make --revision support uuid: and hash: [future tag:] notation.
678
takes_args = ['filename?']
679
takes_options = ['forward', 'timezone', 'verbose', 'show-ids', 'revision',
680
'long', 'message', 'short',]
682
def run(self, filename=None, timezone='original',
690
from bzrlib.log import log_formatter, show_log
693
direction = (forward and 'forward') or 'reverse'
696
b = Branch.open_containing(filename)
697
fp = b.relpath(filename)
699
file_id = b.read_working_inventory().path2id(fp)
701
file_id = None # points to branch root
703
b = Branch.open_containing('.')
709
elif len(revision) == 1:
710
rev1 = rev2 = revision[0].in_history(b).revno
711
elif len(revision) == 2:
712
rev1 = revision[0].in_history(b).revno
713
rev2 = revision[1].in_history(b).revno
715
raise BzrCommandError('bzr log --revision takes one or two values.')
722
mutter('encoding log as %r' % bzrlib.user_encoding)
724
# use 'replace' so that we don't abort if trying to write out
725
# in e.g. the default C locale.
726
outf = codecs.getwriter(bzrlib.user_encoding)(sys.stdout, errors='replace')
732
lf = log_formatter(log_format,
735
show_timezone=timezone)
748
class cmd_touching_revisions(Command):
749
"""Return revision-ids which affected a particular file.
751
A more user-friendly interface is "bzr log FILE"."""
753
takes_args = ["filename"]
754
def run(self, filename):
755
b = Branch.open_containing(filename)
756
inv = b.read_working_inventory()
757
file_id = inv.path2id(b.relpath(filename))
758
for revno, revision_id, what in bzrlib.log.find_touching_revisions(b, file_id):
759
print "%6d %s" % (revno, what)
762
class cmd_ls(Command):
763
"""List files in a tree.
765
TODO: Take a revision or remote path and list that tree instead.
768
def run(self, revision=None, verbose=False):
769
b = Branch.open_containing('.')
771
tree = b.working_tree()
773
tree = b.revision_tree(revision.in_history(b).rev_id)
775
for fp, fc, kind, fid in tree.list_files():
777
if kind == 'directory':
784
print '%-8s %s%s' % (fc, fp, kindch)
790
class cmd_unknowns(Command):
791
"""List unknown files."""
793
from bzrlib.osutils import quotefn
794
for f in Branch.open_containing('.').unknowns():
799
class cmd_ignore(Command):
800
"""Ignore a command or pattern.
802
To remove patterns from the ignore list, edit the .bzrignore file.
804
If the pattern contains a slash, it is compared to the whole path
805
from the branch root. Otherwise, it is comapred to only the last
806
component of the path.
808
Ignore patterns are case-insensitive on case-insensitive systems.
810
Note: wildcards must be quoted from the shell on Unix.
813
bzr ignore ./Makefile
816
takes_args = ['name_pattern']
818
def run(self, name_pattern):
819
from bzrlib.atomicfile import AtomicFile
822
b = Branch.open_containing('.')
823
ifn = b.abspath('.bzrignore')
825
if os.path.exists(ifn):
828
igns = f.read().decode('utf-8')
834
# TODO: If the file already uses crlf-style termination, maybe
835
# we should use that for the newly added lines?
837
if igns and igns[-1] != '\n':
839
igns += name_pattern + '\n'
842
f = AtomicFile(ifn, 'wt')
843
f.write(igns.encode('utf-8'))
848
inv = b.working_tree().inventory
849
if inv.path2id('.bzrignore'):
850
mutter('.bzrignore is already versioned')
852
mutter('need to make new .bzrignore file versioned')
853
b.add(['.bzrignore'])
857
class cmd_ignored(Command):
858
"""List ignored files and the patterns that matched them.
860
See also: bzr ignore"""
862
tree = Branch.open_containing('.').working_tree()
863
for path, file_class, kind, file_id in tree.list_files():
864
if file_class != 'I':
866
## XXX: Slightly inefficient since this was already calculated
867
pat = tree.is_ignored(path)
868
print '%-50s %s' % (path, pat)
871
class cmd_lookup_revision(Command):
872
"""Lookup the revision-id from a revision-number
875
bzr lookup-revision 33
878
takes_args = ['revno']
880
def run(self, revno):
884
raise BzrCommandError("not a valid revision-number: %r" % revno)
886
print Branch.open_containing('.').get_rev_id(revno)
889
class cmd_export(Command):
890
"""Export past revision to destination directory.
892
If no revision is specified this exports the last committed revision.
894
Format may be an "exporter" name, such as tar, tgz, tbz2. If none is
895
given, try to find the format with the extension. If no extension
896
is found exports to a directory (equivalent to --format=dir).
898
Root may be the top directory for tar, tgz and tbz2 formats. If none
899
is given, the top directory will be the root name of the file."""
900
# TODO: list known exporters
901
takes_args = ['dest']
902
takes_options = ['revision', 'format', 'root']
903
def run(self, dest, revision=None, format=None, root=None):
905
b = Branch.open_containing('.')
907
rev_id = b.last_patch()
909
if len(revision) != 1:
910
raise BzrError('bzr export --revision takes exactly 1 argument')
911
rev_id = revision[0].in_history(b).rev_id
912
t = b.revision_tree(rev_id)
913
root, ext = os.path.splitext(dest)
917
elif ext in (".gz", ".tgz"):
919
elif ext in (".bz2", ".tbz2"):
923
t.export(dest, format, root)
926
class cmd_cat(Command):
927
"""Write a file's text from a previous revision."""
929
takes_options = ['revision']
930
takes_args = ['filename']
932
def run(self, filename, revision=None):
934
raise BzrCommandError("bzr cat requires a revision number")
935
elif len(revision) != 1:
936
raise BzrCommandError("bzr cat --revision takes exactly one number")
937
b = Branch.open_containing('.')
938
b.print_file(b.relpath(filename), revision[0].in_history(b).revno)
941
class cmd_local_time_offset(Command):
942
"""Show the offset in seconds from GMT to local time."""
945
print bzrlib.osutils.local_time_offset()
949
class cmd_commit(Command):
950
"""Commit changes into a new revision.
952
If no arguments are given, the entire tree is committed.
954
If selected files are specified, only changes to those files are
955
committed. If a directory is specified then the directory and everything
956
within it is committed.
958
A selected-file commit may fail in some cases where the committed
959
tree would be invalid, such as trying to commit a file in a
960
newly-added directory that is not itself committed.
962
TODO: Run hooks on tree to-be-committed, and after commit.
964
TODO: Strict commit that fails if there are unknown or deleted files.
966
takes_args = ['selected*']
967
takes_options = ['message', 'file', 'verbose', 'unchanged']
968
aliases = ['ci', 'checkin']
970
# TODO: Give better message for -s, --summary, used by tla people
972
def run(self, message=None, file=None, verbose=True, selected_list=None,
974
from bzrlib.errors import PointlessCommit
975
from bzrlib.msgeditor import edit_commit_message
976
from bzrlib.status import show_status
977
from cStringIO import StringIO
979
b = Branch.open_containing('.')
981
selected_list = [b.relpath(s) for s in selected_list]
983
if not message and not file:
985
show_status(b, specific_files=selected_list,
987
message = edit_commit_message(catcher.getvalue())
990
raise BzrCommandError("please specify a commit message"
991
" with either --message or --file")
992
elif message and file:
993
raise BzrCommandError("please specify either --message or --file")
997
message = codecs.open(file, 'rt', bzrlib.user_encoding).read()
1000
b.commit(message, verbose=verbose,
1001
specific_files=selected_list,
1002
allow_pointless=unchanged)
1003
except PointlessCommit:
1004
# FIXME: This should really happen before the file is read in;
1005
# perhaps prepare the commit; get the message; then actually commit
1006
raise BzrCommandError("no changes to commit",
1007
["use --unchanged to commit anyhow"])
1010
class cmd_check(Command):
1011
"""Validate consistency of branch history.
1013
This command checks various invariants about the branch storage to
1014
detect data corruption or bzr bugs.
1016
takes_args = ['dir?']
1018
def run(self, dir='.'):
1019
from bzrlib.check import check
1021
check(Branch.open_containing(dir))
1024
class cmd_scan_cache(Command):
1027
from bzrlib.hashcache import HashCache
1033
print '%6d stats' % c.stat_count
1034
print '%6d in hashcache' % len(c._cache)
1035
print '%6d files removed from cache' % c.removed_count
1036
print '%6d hashes updated' % c.update_count
1037
print '%6d files changed too recently to cache' % c.danger_count
1044
class cmd_upgrade(Command):
1045
"""Upgrade branch storage to current format.
1047
The check command or bzr developers may sometimes advise you to run
1050
takes_args = ['dir?']
1052
def run(self, dir='.'):
1053
from bzrlib.upgrade import upgrade
1054
upgrade(Branch.open_containing(dir))
1058
class cmd_whoami(Command):
1059
"""Show bzr user id."""
1060
takes_options = ['email']
1062
def run(self, email=False):
1064
b = bzrlib.branch.Branch.open_containing('.')
1069
print bzrlib.osutils.user_email(b)
1071
print bzrlib.osutils.username(b)
1074
class cmd_selftest(Command):
1075
"""Run internal test suite"""
1077
takes_options = ['verbose', 'pattern']
1078
def run(self, verbose=False, pattern=".*"):
1080
from bzrlib.selftest import selftest
1081
# we don't want progress meters from the tests to go to the
1082
# real output; and we don't want log messages cluttering up
1084
save_ui = bzrlib.ui.ui_factory
1085
bzrlib.trace.info('running tests...')
1087
bzrlib.ui.ui_factory = bzrlib.ui.SilentUIFactory()
1088
result = selftest(verbose=verbose, pattern=pattern)
1090
bzrlib.trace.info('tests passed')
1092
bzrlib.trace.info('tests failed')
1093
return int(not result)
1095
bzrlib.ui.ui_factory = save_ui
1099
print "bzr (bazaar-ng) %s" % bzrlib.__version__
1100
# is bzrlib itself in a branch?
1101
bzrrev = bzrlib.get_bzr_revision()
1103
print " (bzr checkout, revision %d {%s})" % bzrrev
1104
print bzrlib.__copyright__
1105
print "http://bazaar-ng.org/"
1107
print "bzr comes with ABSOLUTELY NO WARRANTY. bzr is free software, and"
1108
print "you may use, modify and redistribute it under the terms of the GNU"
1109
print "General Public License version 2 or later."
1112
class cmd_version(Command):
1113
"""Show version of bzr."""
1117
class cmd_rocks(Command):
1118
"""Statement of optimism."""
1121
print "it sure does!"
1124
class cmd_find_merge_base(Command):
1125
"""Find and print a base revision for merging two branches.
1127
TODO: Options to specify revisions on either side, as if
1128
merging only part of the history.
1130
takes_args = ['branch', 'other']
1133
def run(self, branch, other):
1134
from bzrlib.revision import common_ancestor, MultipleRevisionSources
1136
branch1 = Branch.open_containing(branch)
1137
branch2 = Branch.open_containing(other)
1139
history_1 = branch1.revision_history()
1140
history_2 = branch2.revision_history()
1142
last1 = branch1.last_patch()
1143
last2 = branch2.last_patch()
1145
source = MultipleRevisionSources(branch1, branch2)
1147
base_rev_id = common_ancestor(last1, last2, source)
1149
print 'merge base is revision %s' % base_rev_id
1153
if base_revno is None:
1154
raise bzrlib.errors.UnrelatedBranches()
1156
print ' r%-6d in %s' % (base_revno, branch)
1158
other_revno = branch2.revision_id_to_revno(base_revid)
1160
print ' r%-6d in %s' % (other_revno, other)
1164
class cmd_merge(Command):
1165
"""Perform a three-way merge.
1167
The branch is the branch you will merge from. By default, it will
1168
merge the latest revision. If you specify a revision, that
1169
revision will be merged. If you specify two revisions, the first
1170
will be used as a BASE, and the second one as OTHER. Revision
1171
numbers are always relative to the specified branch.
1173
By default bzr will try to merge in all new work from the other
1174
branch, automatically determining an appropriate base. If this
1175
fails, you may need to give an explicit base.
1179
To merge the latest revision from bzr.dev
1180
bzr merge ../bzr.dev
1182
To merge changes up to and including revision 82 from bzr.dev
1183
bzr merge -r 82 ../bzr.dev
1185
To merge the changes introduced by 82, without previous changes:
1186
bzr merge -r 81..82 ../bzr.dev
1188
merge refuses to run if there are any uncommitted changes, unless
1191
takes_args = ['branch?']
1192
takes_options = ['revision', 'force', 'merge-type']
1194
def run(self, branch='.', revision=None, force=False,
1196
from bzrlib.merge import merge
1197
from bzrlib.merge_core import ApplyMerge3
1198
if merge_type is None:
1199
merge_type = ApplyMerge3
1201
if revision is None or len(revision) < 1:
1203
other = [branch, -1]
1205
if len(revision) == 1:
1207
other = [branch, revision[0].in_history(branch).revno]
1209
assert len(revision) == 2
1210
if None in revision:
1211
raise BzrCommandError(
1212
"Merge doesn't permit that revision specifier.")
1213
from bzrlib.branch import Branch
1214
b = Branch.open(branch)
1216
base = [branch, revision[0].in_history(b).revno]
1217
other = [branch, revision[1].in_history(b).revno]
1220
merge(other, base, check_clean=(not force), merge_type=merge_type)
1221
except bzrlib.errors.AmbiguousBase, e:
1222
m = ("sorry, bzr can't determine the right merge base yet\n"
1223
"candidates are:\n "
1224
+ "\n ".join(e.bases)
1226
"please specify an explicit base with -r,\n"
1227
"and (if you want) report this to the bzr developers\n")
1231
class cmd_revert(Command):
1232
"""Reverse all changes since the last commit.
1234
Only versioned files are affected. Specify filenames to revert only
1235
those files. By default, any files that are changed will be backed up
1236
first. Backup files have a '~' appended to their name.
1238
takes_options = ['revision', 'no-backup']
1239
takes_args = ['file*']
1240
aliases = ['merge-revert']
1242
def run(self, revision=None, no_backup=False, file_list=None):
1243
from bzrlib.merge import merge
1244
from bzrlib.branch import Branch
1245
from bzrlib.commands import parse_spec
1247
if file_list is not None:
1248
if len(file_list) == 0:
1249
raise BzrCommandError("No files specified")
1250
if revision is None:
1252
elif len(revision) != 1:
1253
raise BzrCommandError('bzr revert --revision takes exactly 1 argument')
1255
b = Branch.open_containing('.')
1256
revno = revision[0].in_history(b).revno
1257
merge(('.', revno), parse_spec('.'),
1260
backup_files=not no_backup,
1261
file_list=file_list)
1263
Branch.open_containing('.').set_pending_merges([])
1266
class cmd_assert_fail(Command):
1267
"""Test reporting of assertion failures"""
1270
assert False, "always fails"
1273
class cmd_help(Command):
1274
"""Show help on a command or other topic.
1276
For a list of all available commands, say 'bzr help commands'."""
1277
takes_options = ['long']
1278
takes_args = ['topic?']
1281
def run(self, topic=None, long=False):
1283
if topic is None and long:
1288
class cmd_shell_complete(Command):
1289
"""Show appropriate completions for context.
1291
For a list of all available commands, say 'bzr shell-complete'."""
1292
takes_args = ['context?']
1296
def run(self, context=None):
1297
import shellcomplete
1298
shellcomplete.shellcomplete(context)
1301
class cmd_missing(Command):
1302
"""What is missing in this branch relative to other branch.
1304
takes_args = ['remote?']
1305
aliases = ['mis', 'miss']
1306
# We don't have to add quiet to the list, because
1307
# unknown options are parsed as booleans
1308
takes_options = ['verbose', 'quiet']
1310
def run(self, remote=None, verbose=False, quiet=False):
1311
from bzrlib.errors import BzrCommandError
1312
from bzrlib.missing import show_missing
1314
if verbose and quiet:
1315
raise BzrCommandError('Cannot pass both quiet and verbose')
1317
b = Branch.open_containing('.')
1318
parent = b.get_parent()
1321
raise BzrCommandError("No missing location known or specified.")
1324
print "Using last location: %s" % parent
1326
elif parent is None:
1327
# We only update parent if it did not exist, missing
1328
# should not change the parent
1329
b.set_parent(remote)
1330
br_remote = Branch.open_containing(remote)
1331
return show_missing(b, br_remote, verbose=verbose, quiet=quiet)
1334
class cmd_plugins(Command):
1338
import bzrlib.plugin
1339
from inspect import getdoc
1340
for plugin in bzrlib.plugin.all_plugins:
1341
if hasattr(plugin, '__path__'):
1342
print plugin.__path__[0]
1343
elif hasattr(plugin, '__file__'):
1344
print plugin.__file__
1350
print '\t', d.split('\n')[0]