14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
# DO NOT change this to cStringIO - it results in control files
19
# FIXIT! (Only deal with byte streams OR unicode at any one layer.)
21
from StringIO import StringIO
23
from bzrlib.trace import mutter, note, log_error, warning
24
from bzrlib.errors import BzrError, BzrCheckError, BzrCommandError
25
from bzrlib.branch import find_branch
26
26
from bzrlib import BZRDIR
27
from bzrlib.commands import Command, display_command
28
from bzrlib.branch import Branch
29
from bzrlib.revision import common_ancestor
30
import bzrlib.errors as errors
31
from bzrlib.errors import (BzrError, BzrCheckError, BzrCommandError,
32
NotBranchError, DivergedBranches, NotConflicted,
33
NoSuchFile, NoWorkingTree, FileInWrongBranch)
34
from bzrlib.option import Option
35
from bzrlib.revisionspec import RevisionSpec
37
from bzrlib.trace import mutter, note, log_error, warning, is_quiet
38
from bzrlib.workingtree import WorkingTree
41
def tree_files(file_list, default_branch=u'.'):
43
return internal_tree_files(file_list, default_branch)
44
except FileInWrongBranch, e:
45
raise BzrCommandError("%s is not in the same branch as %s" %
46
(e.path, file_list[0]))
48
def internal_tree_files(file_list, default_branch=u'.'):
50
Return a branch and list of branch-relative paths.
51
If supplied file_list is empty or None, the branch default will be used,
52
and returned file_list will match the original.
54
if file_list is None or len(file_list) == 0:
55
return WorkingTree.open_containing(default_branch)[0], file_list
56
tree = WorkingTree.open_containing(file_list[0])[0]
58
for filename in file_list:
60
new_list.append(tree.relpath(filename))
61
except NotBranchError:
62
raise FileInWrongBranch(tree.branch, filename)
66
# TODO: Make sure no commands unconditionally use the working directory as a
67
# branch. If a filename argument is used, the first of them should be used to
68
# specify the branch. (Perhaps this can be factored out into some kind of
69
# Argument class, representing a file in a branch, where the first occurrence
27
from bzrlib.commands import Command
72
30
class cmd_status(Command):
73
31
"""Display status summary.
104
62
directory is shown. Otherwise, only the status of the specified
105
63
files or directories is reported. If a directory is given, status
106
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
108
If a revision argument is given, the status is calculated against
109
that revision, or between two revisions if two are provided.
112
# TODO: --no-recurse, --recurse options
114
69
takes_args = ['file*']
115
takes_options = ['all', 'show-ids', 'revision']
70
takes_options = ['all', 'show-ids']
116
71
aliases = ['st', 'stat']
119
def run(self, all=False, show_ids=False, file_list=None, revision=None):
120
tree, file_list = tree_files(file_list)
73
def run(self, all=False, show_ids=False, file_list=None):
75
b = find_branch(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
122
84
from bzrlib.status import show_status
123
show_status(tree.branch, show_unchanged=all, show_ids=show_ids,
124
specific_files=file_list, revision=revision)
85
show_status(b, show_unchanged=all, show_ids=show_ids,
86
specific_files=file_list)
127
89
class cmd_cat_revision(Command):
128
"""Write out metadata for a revision.
130
The revision to print can either be specified by a specific
131
revision identifier, or you can use --revision.
90
"""Write out metadata for a revision."""
135
takes_args = ['revision_id?']
136
takes_options = ['revision']
93
takes_args = ['revision_id']
139
def run(self, revision_id=None, revision=None):
95
def run(self, revision_id):
97
sys.stdout.write(b.get_revision_xml_file(revision_id).read())
141
if revision_id is not None and revision is not None:
142
raise BzrCommandError('You can only supply one of revision_id or --revision')
143
if revision_id is None and revision is None:
144
raise BzrCommandError('You must supply either --revision or a revision_id')
145
b = WorkingTree.open_containing(u'.')[0].branch
146
if revision_id is not None:
147
sys.stdout.write(b.get_revision_xml(revision_id))
148
elif revision is not None:
151
raise BzrCommandError('You cannot specify a NULL revision.')
152
revno, rev_id = rev.in_history(b)
153
sys.stdout.write(b.get_revision_xml(rev_id))
156
100
class cmd_revno(Command):
157
101
"""Show current revision number.
159
103
This is equal to the number of revisions on this branch."""
162
print Branch.open_containing(u'.')[0].revno()
105
print find_branch('.').revno()
165
108
class cmd_revision_info(Command):
245
184
takes_args = ['filename']
249
187
def run(self, filename):
250
tree, relpath = WorkingTree.open_containing(filename)
188
print find_branch(filename).relpath(filename)
254
192
class cmd_inventory(Command):
255
"""Show inventory of the current working copy or a revision.
257
It is possible to limit the output to a particular entry
258
type using the --kind option. For example; --kind file.
260
takes_options = ['revision', 'show-ids', 'kind']
193
"""Show inventory of the current working copy or a revision."""
194
takes_options = ['revision', 'show-ids']
263
def run(self, revision=None, show_ids=False, kind=None):
264
if kind and kind not in ['file', 'directory', 'symlink']:
265
raise BzrCommandError('invalid kind specified')
266
tree = WorkingTree.open_containing(u'.')[0]
268
inv = tree.read_working_inventory()
196
def run(self, revision=None, show_ids=False):
199
inv = b.read_working_inventory()
270
201
if len(revision) > 1:
271
202
raise BzrCommandError('bzr inventory --revision takes'
272
203
' exactly one revision identifier')
273
inv = tree.branch.get_revision_inventory(
274
revision[0].in_history(tree.branch).rev_id)
204
inv = b.get_revision_inventory(b.lookup_revision(revision[0]))
276
206
for path, entry in inv.entries():
277
if kind and kind != entry.kind:
280
208
print '%-50s %s' % (path, entry.file_id)
335
265
def run(self, names_list):
336
266
if len(names_list) < 2:
337
267
raise BzrCommandError("missing file argument")
338
tree, rel_names = tree_files(names_list)
268
b = find_branch(names_list[0])
270
rel_names = [b.relpath(x) for x in names_list]
340
272
if os.path.isdir(names_list[-1]):
341
273
# move into existing directory
342
for pair in tree.move(rel_names[:-1], rel_names[-1]):
274
for pair in b.move(rel_names[:-1], rel_names[-1]):
343
275
print "%s => %s" % pair
345
277
if len(names_list) != 2:
346
278
raise BzrCommandError('to mv multiple files the destination '
347
279
'must be a versioned directory')
348
tree.rename_one(rel_names[0], rel_names[1])
280
b.rename_one(rel_names[0], rel_names[1])
349
281
print "%s => %s" % (rel_names[0], rel_names[1])
352
286
class cmd_pull(Command):
353
287
"""Pull any changes from another branch into the current one.
355
If there is no default location set, the first pull will set it. After
356
that, you can omit the location to use the default. To change the
357
default, use --remember.
289
If the location is omitted, the last-used location will be used.
290
Both the revision history and the working directory will be
359
293
This command only works on branches that have not diverged. Branches are
360
294
considered diverged if both branches have had commits without first
361
295
pulling from the other.
363
297
If branches have diverged, you can use 'bzr merge' to pull the text changes
364
from one into the other. Once one branch has merged, the other should
365
be able to pull it again.
367
If you want to forget your local changes and just update your branch to
368
match the remote one, use --overwrite.
298
from one into the other.
370
takes_options = ['remember', 'overwrite', 'verbose']
371
300
takes_args = ['location?']
373
def run(self, location=None, remember=False, overwrite=False, verbose=False):
302
def run(self, location=None):
374
303
from bzrlib.merge import merge
375
305
from shutil import rmtree
377
# FIXME: too much stuff is in the command class
378
tree_to = WorkingTree.open_containing(u'.')[0]
379
stored_loc = tree_to.branch.get_parent()
308
br_to = find_branch('.')
309
stored_loc = br_to.get_parent()
380
310
if location is None:
381
311
if stored_loc is None:
382
312
raise BzrCommandError("No pull location known or specified.")
384
print "Using saved location: %s" % stored_loc
385
location = stored_loc
386
br_from = Branch.open(location)
387
br_to = tree_to.branch
389
old_rh = br_to.revision_history()
390
count = tree_to.pull(br_from, overwrite)
391
except DivergedBranches:
392
# FIXME: Just make DivergedBranches display the right message
394
raise BzrCommandError("These branches have diverged."
396
if br_to.get_parent() is None or remember:
397
br_to.set_parent(location)
398
note('%d revision(s) pulled.' % (count,))
401
new_rh = tree_to.branch.revision_history()
404
from bzrlib.log import show_changed_revisions
405
show_changed_revisions(tree_to.branch, old_rh, new_rh)
408
class cmd_push(Command):
409
"""Push this branch into another branch.
411
The remote branch will not have its working tree populated because this
412
is both expensive, and may not be supported on the remote file system.
414
Some smart servers or protocols *may* put the working tree in place.
416
If there is no default push location set, the first push will set it.
417
After that, you can omit the location to use the default. To change the
418
default, use --remember.
420
This command only works on branches that have not diverged. Branches are
421
considered diverged if the branch being pushed to is not an older version
424
If branches have diverged, you can use 'bzr push --overwrite' to replace
425
the other branch completely.
427
If you want to ensure you have the different changes in the other branch,
428
do a merge (see bzr help merge) from the other branch, and commit that
429
before doing a 'push --overwrite'.
431
takes_options = ['remember', 'overwrite',
432
Option('create-prefix',
433
help='Create the path leading up to the branch '
434
'if it does not already exist')]
435
takes_args = ['location?']
437
def run(self, location=None, remember=False, overwrite=False,
438
create_prefix=False, verbose=False):
439
# FIXME: Way too big! Put this into a function called from the
442
from shutil import rmtree
443
from bzrlib.transport import get_transport
445
tree_from = WorkingTree.open_containing(u'.')[0]
446
br_from = tree_from.branch
447
stored_loc = tree_from.branch.get_push_location()
449
if stored_loc is None:
450
raise BzrCommandError("No push location known or specified.")
452
print "Using saved location: %s" % stored_loc
453
location = stored_loc
455
br_to = Branch.open(location)
456
except NotBranchError:
458
transport = get_transport(location).clone('..')
459
if not create_prefix:
461
transport.mkdir(transport.relpath(location))
463
raise BzrCommandError("Parent directory of %s "
464
"does not exist." % location)
466
current = transport.base
467
needed = [(transport, transport.relpath(location))]
470
transport, relpath = needed[-1]
471
transport.mkdir(relpath)
474
new_transport = transport.clone('..')
475
needed.append((new_transport,
476
new_transport.relpath(transport.base)))
477
if new_transport.base == transport.base:
478
raise BzrCommandError("Could not creeate "
480
br_to = Branch.initialize(location)
482
old_rh = br_to.revision_history()
483
count = br_to.pull(br_from, overwrite)
484
except DivergedBranches:
485
raise BzrCommandError("These branches have diverged."
486
" Try a merge then push with overwrite.")
487
if br_from.get_push_location() is None or remember:
488
br_from.set_push_location(location)
489
note('%d revision(s) pushed.' % (count,))
492
new_rh = br_to.revision_history()
495
from bzrlib.log import show_changed_revisions
496
show_changed_revisions(br_to, old_rh, new_rh)
314
print "Using last location: %s" % stored_loc
315
location = stored_loc
316
cache_root = tempfile.mkdtemp()
317
from bzrlib.branch import DivergedBranches
318
br_from = find_branch(location)
319
location = br_from.base
320
old_revno = br_to.revno()
322
from branch import find_cached_branch, DivergedBranches
323
br_from = find_cached_branch(location, cache_root)
324
location = br_from.base
325
old_revno = br_to.revno()
327
br_to.update_revisions(br_from)
328
except DivergedBranches:
329
raise BzrCommandError("These branches have diverged."
332
merge(('.', -1), ('.', old_revno), check_clean=False)
333
if location != stored_loc:
334
br_to.set_parent(location)
499
340
class cmd_branch(Command):
505
346
To retrieve the branch as of a particular revision, supply the --revision
506
347
parameter, as in "branch foo/bar -r 5".
508
--basis is to speed up branching from remote branches. When specified, it
509
copies all the file-contents, inventory and revision data from the basis
510
branch before copying anything from the remote branch.
512
349
takes_args = ['from_location', 'to_location?']
513
takes_options = ['revision', 'basis']
350
takes_options = ['revision']
514
351
aliases = ['get', 'clone']
516
def run(self, from_location, to_location=None, revision=None, basis=None):
517
from bzrlib.clone import copy_branch
353
def run(self, from_location, to_location=None, revision=None):
354
from bzrlib.branch import copy_branch, find_cached_branch
519
357
from shutil import rmtree
522
elif len(revision) > 1:
523
raise BzrCommandError(
524
'bzr branch --revision takes exactly 1 revision value')
526
br_from = Branch.open(from_location)
528
if e.errno == errno.ENOENT:
529
raise BzrCommandError('Source location "%s" does not'
530
' exist.' % to_location)
535
if basis is not None:
536
basis_branch = WorkingTree.open_containing(basis)[0].branch
539
if len(revision) == 1 and revision[0] is not None:
540
revision_id = revision[0].in_history(br_from)[1]
358
cache_root = tempfile.mkdtemp()
362
elif len(revision) > 1:
363
raise BzrCommandError(
364
'bzr branch --revision takes exactly 1 revision value')
366
br_from = find_cached_branch(from_location, cache_root)
368
if e.errno == errno.ENOENT:
369
raise BzrCommandError('Source location "%s" does not'
370
' exist.' % to_location)
543
373
if to_location is None:
544
374
to_location = os.path.basename(from_location.rstrip("/\\"))
547
name = os.path.basename(to_location) + '\n'
549
376
os.mkdir(to_location)
550
377
except OSError, e:
560
copy_branch(br_from, to_location, revision_id, basis_branch)
387
copy_branch(br_from, to_location, revision[0])
561
388
except bzrlib.errors.NoSuchRevision:
562
389
rmtree(to_location)
563
msg = "The branch %s has no revision %s." % (from_location, revision[0])
564
raise BzrCommandError(msg)
565
except bzrlib.errors.UnlistableBranch:
567
msg = "The branch %s cannot be used as a --basis"
568
raise BzrCommandError(msg)
569
branch = Branch.open(to_location)
571
name = StringIO(name)
572
branch.put_controlfile('branch-name', name)
573
note('Branched %d revision(s).' % branch.revno())
390
msg = "The branch %s has no revision %d." % (from_location, revision[0])
391
raise BzrCommandError(msg)
578
396
class cmd_renames(Command):
579
397
"""Show list of renamed files.
399
TODO: Option to show renames between two historical versions.
401
TODO: Only show renames under dir, rather than in the whole branch.
581
# TODO: Option to show renames between two historical versions.
583
# TODO: Only show renames under dir, rather than in the whole branch.
584
403
takes_args = ['dir?']
587
def run(self, dir=u'.'):
588
tree = WorkingTree.open_containing(dir)[0]
589
old_inv = tree.branch.basis_tree().inventory
590
new_inv = tree.read_working_inventory()
405
def run(self, dir='.'):
407
old_inv = b.basis_tree().inventory
408
new_inv = b.read_working_inventory()
592
410
renames = list(bzrlib.tree.find_renames(old_inv, new_inv))
715
515
If files are listed, only the changes in those files are listed.
716
516
Otherwise, all changes for the tree are listed.
518
TODO: Allow diff across branches.
520
TODO: Option to use external diff command; could be GNU diff, wdiff,
523
TODO: Python difflib is not exactly the same as unidiff; should
524
either fix it up or prefer to use an external diff.
526
TODO: If a directory is given, diff everything under that.
528
TODO: Selected-file diff is inefficient and doesn't show you
531
TODO: This probably handles non-Unix newlines poorly.
723
# TODO: Allow diff across branches.
724
# TODO: Option to use external diff command; could be GNU diff, wdiff,
725
# or a graphical diff.
727
# TODO: Python difflib is not exactly the same as unidiff; should
728
# either fix it up or prefer to use an external diff.
730
# TODO: If a directory is given, diff everything under that.
732
# TODO: Selected-file diff is inefficient and doesn't show you
735
# TODO: This probably handles non-Unix newlines poorly.
737
539
takes_args = ['file*']
738
540
takes_options = ['revision', 'diff-options']
739
541
aliases = ['di', 'dif']
742
543
def run(self, revision=None, file_list=None, diff_options=None):
743
544
from bzrlib.diff import show_diff
745
tree, file_list = internal_tree_files(file_list)
748
except FileInWrongBranch:
749
if len(file_list) != 2:
750
raise BzrCommandError("Files are in different branches")
752
b, file1 = Branch.open_containing(file_list[0])
753
b2, file2 = Branch.open_containing(file_list[1])
754
if file1 != "" or file2 != "":
755
# FIXME diff those two files. rbc 20051123
756
raise BzrCommandError("Files are in different branches")
547
b = find_branch(file_list[0])
548
file_list = [b.relpath(f) for f in file_list]
549
if file_list == ['']:
550
# just pointing to top-of-tree
758
555
if revision is not None:
760
raise BzrCommandError("Can't specify -r with two branches")
761
556
if len(revision) == 1:
762
return show_diff(tree.branch, revision[0], specific_files=file_list,
763
external_diff_options=diff_options)
557
show_diff(b, revision[0], specific_files=file_list,
558
external_diff_options=diff_options)
764
559
elif len(revision) == 2:
765
return show_diff(tree.branch, revision[0], specific_files=file_list,
766
external_diff_options=diff_options,
767
revision2=revision[1])
560
show_diff(b, revision[0], specific_files=file_list,
561
external_diff_options=diff_options,
562
revision2=revision[1])
769
564
raise BzrCommandError('bzr diff --revision takes exactly one or two revision identifiers')
772
return show_diff(b, None, specific_files=file_list,
773
external_diff_options=diff_options, b2=b2)
775
return show_diff(tree.branch, None, specific_files=file_list,
776
external_diff_options=diff_options)
566
show_diff(b, None, specific_files=file_list,
567
external_diff_options=diff_options)
779
572
class cmd_deleted(Command):
780
573
"""List files deleted in the working tree.
575
TODO: Show files deleted since a previous revision, or between two revisions.
782
# TODO: Show files deleted since a previous revision, or
783
# between two revisions.
784
# TODO: Much more efficient way to do this: read in new
785
# directories with readdir, rather than stating each one. Same
786
# level of effort but possibly much less IO. (Or possibly not,
787
# if the directories are very large...)
789
577
def run(self, show_ids=False):
790
tree = WorkingTree.open_containing(u'.')[0]
791
old = tree.branch.basis_tree()
580
new = b.working_tree()
582
## TODO: Much more efficient way to do this: read in new
583
## directories with readdir, rather than stating each one. Same
584
## level of effort but possibly much less IO. (Or possibly not,
585
## if the directories are very large...)
792
587
for path, ie in old.inventory.iter_entries():
793
if not tree.has_id(ie.file_id):
588
if not new.has_id(ie.file_id):
795
590
print '%-50s %s' % (path, ie.file_id)
836
630
The root is the nearest enclosing directory with a .bzr control
838
632
takes_args = ['filename?']
840
633
def run(self, filename=None):
841
634
"""Print the branch root."""
842
tree = WorkingTree.open_containing(filename)[0]
635
b = find_branch(filename)
846
639
class cmd_log(Command):
847
640
"""Show log of this branch.
849
To request a range of logs, you can use the command -r begin..end
850
-r revision requests a specific revision, -r ..end or -r begin.. are
642
To request a range of logs, you can use the command -r begin:end
643
-r revision requests a specific revision, -r :end or -r begin: are
646
--message allows you to give a regular expression, which will be evaluated
647
so that only matching entries will be displayed.
649
TODO: Make --revision support uuid: and hash: [future tag:] notation.
854
# TODO: Make --revision support uuid: and hash: [future tag:] notation.
856
653
takes_args = ['filename?']
857
takes_options = [Option('forward',
858
help='show from oldest to newest'),
859
'timezone', 'verbose',
860
'show-ids', 'revision',
861
Option('line', help='format with one line per revision'),
864
help='show revisions whose message matches this regexp',
866
Option('short', help='use moderately short format'),
654
takes_options = ['forward', 'timezone', 'verbose', 'show-ids', 'revision',
655
'long', 'message', 'short',]
869
657
def run(self, filename=None, timezone='original',
878
665
from bzrlib.log import log_formatter, show_log
880
assert message is None or isinstance(message, basestring), \
881
"invalid message argument %r" % message
882
668
direction = (forward and 'forward') or 'reverse'
888
tree, fp = WorkingTree.open_containing(filename)
891
inv = tree.read_working_inventory()
892
except NotBranchError:
895
b, fp = Branch.open_containing(filename)
897
inv = b.get_inventory(b.last_revision())
899
file_id = inv.path2id(fp)
671
b = find_branch(filename)
672
fp = b.relpath(filename)
674
file_id = b.read_working_inventory().path2id(fp)
901
676
file_id = None # points to branch root
903
tree, relpath = WorkingTree.open_containing(u'.')
907
681
if revision is None:
910
684
elif len(revision) == 1:
911
rev1 = rev2 = revision[0].in_history(b).revno
685
rev1 = rev2 = b.get_revision_info(revision[0])[0]
912
686
elif len(revision) == 2:
913
rev1 = revision[0].in_history(b).revno
914
rev2 = revision[1].in_history(b).revno
687
rev1 = b.get_revision_info(revision[0])[0]
688
rev2 = b.get_revision_info(revision[1])[0]
916
690
raise BzrCommandError('bzr log --revision takes one or two values.')
918
# By this point, the revision numbers are converted to the +ve
919
# form if they were supplied in the -ve form, so we can do
920
# this comparison in relative safety
922
(rev2, rev1) = (rev1, rev2)
924
mutter('encoding log as %r', bzrlib.user_encoding)
697
mutter('encoding log as %r' % bzrlib.user_encoding)
926
699
# use 'replace' so that we don't abort if trying to write out
927
700
# in e.g. the default C locale.
928
701
outf = codecs.getwriter(bzrlib.user_encoding)(sys.stdout, errors='replace')
932
706
log_format = 'short'
935
707
lf = log_formatter(log_format,
936
708
show_ids=show_ids,
954
726
A more user-friendly interface is "bzr log FILE"."""
956
728
takes_args = ["filename"]
958
729
def run(self, filename):
959
tree, relpath = WorkingTree.open_containing(filename)
961
inv = tree.read_working_inventory()
962
file_id = inv.path2id(relpath)
730
b = find_branch(filename)
731
inv = b.read_working_inventory()
732
file_id = inv.path2id(b.relpath(filename))
963
733
for revno, revision_id, what in bzrlib.log.find_touching_revisions(b, file_id):
964
734
print "%6d %s" % (revno, what)
967
737
class cmd_ls(Command):
968
738
"""List files in a tree.
740
TODO: Take a revision or remote path and list that tree instead.
970
# TODO: Take a revision or remote path and list that tree instead.
972
takes_options = ['verbose', 'revision',
973
Option('non-recursive',
974
help='don\'t recurse into sub-directories'),
976
help='Print all paths from the root of the branch.'),
977
Option('unknown', help='Print unknown files'),
978
Option('versioned', help='Print versioned files'),
979
Option('ignored', help='Print ignored files'),
981
Option('null', help='Null separate the files'),
984
def run(self, revision=None, verbose=False,
985
non_recursive=False, from_root=False,
986
unknown=False, versioned=False, ignored=False,
990
raise BzrCommandError('Cannot set both --verbose and --null')
991
all = not (unknown or versioned or ignored)
993
selection = {'I':ignored, '?':unknown, 'V':versioned}
995
tree, relpath = WorkingTree.open_containing(u'.')
1000
if revision is not None:
1001
tree = tree.branch.revision_tree(
1002
revision[0].in_history(tree.branch).rev_id)
1003
for fp, fc, kind, fid, entry in tree.list_files():
1004
if fp.startswith(relpath):
1005
fp = fp[len(relpath):]
1006
if non_recursive and '/' in fp:
1008
if not all and not selection[fc]:
1011
kindch = entry.kind_character()
1012
print '%-8s %s%s' % (fc, fp, kindch)
1014
sys.stdout.write(fp)
1015
sys.stdout.write('\0')
743
def run(self, revision=None, verbose=False):
746
tree = b.working_tree()
748
tree = b.revision_tree(b.lookup_revision(revision))
750
for fp, fc, kind, fid in tree.list_files():
752
if kind == 'directory':
759
print '%-8s %s%s' % (fc, fp, kindch)
1021
765
class cmd_unknowns(Command):
1022
766
"""List unknown files."""
1025
768
from bzrlib.osutils import quotefn
1026
for f in WorkingTree.open_containing(u'.')[0].unknowns():
769
for f in find_branch('.').unknowns():
1027
770
print quotefn(f)
1030
774
class cmd_ignore(Command):
1031
775
"""Ignore a command or pattern.
1033
777
To remove patterns from the ignore list, edit the .bzrignore file.
1035
779
If the pattern contains a slash, it is compared to the whole path
1036
from the branch root. Otherwise, it is compared to only the last
1037
component of the path. To match a file only in the root directory,
780
from the branch root. Otherwise, it is comapred to only the last
781
component of the path.
1040
783
Ignore patterns are case-insensitive on case-insensitive systems.
1130
871
is found exports to a directory (equivalent to --format=dir).
1132
873
Root may be the top directory for tar, tgz and tbz2 formats. If none
1133
is given, the top directory will be the root name of the file.
1135
Note: export of tree with non-ascii filenames to zip is not supported.
1137
Supported formats Autodetected by extension
1138
----------------- -------------------------
1141
tbz2 .tar.bz2, .tbz2
874
is given, the top directory will be the root name of the file."""
875
# TODO: list known exporters
1145
876
takes_args = ['dest']
1146
877
takes_options = ['revision', 'format', 'root']
1147
878
def run(self, dest, revision=None, format=None, root=None):
1149
from bzrlib.export import export
1150
tree = WorkingTree.open_containing(u'.')[0]
1152
881
if revision is None:
1153
# should be tree.last_revision FIXME
1154
rev_id = b.last_revision()
882
rev_id = b.last_patch()
1156
884
if len(revision) != 1:
1157
885
raise BzrError('bzr export --revision takes exactly 1 argument')
1158
rev_id = revision[0].in_history(b).rev_id
886
revno, rev_id = b.get_revision_info(revision[0])
1159
887
t = b.revision_tree(rev_id)
1161
export(t, dest, format, root)
1162
except errors.NoSuchExportFormat, e:
1163
raise BzrCommandError('Unsupported export format: %s' % e.format)
888
root, ext = os.path.splitext(dest)
892
elif ext in (".gz", ".tgz"):
894
elif ext in (".bz2", ".tbz2"):
898
t.export(dest, format, root)
1166
901
class cmd_cat(Command):
1207
933
A selected-file commit may fail in some cases where the committed
1208
934
tree would be invalid, such as trying to commit a file in a
1209
935
newly-added directory that is not itself committed.
937
TODO: Run hooks on tree to-be-committed, and after commit.
939
TODO: Strict commit that fails if there are unknown or deleted files.
1211
# TODO: Run hooks on tree to-be-committed, and after commit.
1213
# TODO: Strict commit that fails if there are deleted files.
1214
# (what does "deleted files" mean ??)
1216
# TODO: Give better message for -s, --summary, used by tla people
1218
# XXX: verbose currently does nothing
1220
941
takes_args = ['selected*']
1221
takes_options = ['message', 'verbose',
1223
help='commit even if nothing has changed'),
1224
Option('file', type=str,
1226
help='file containing commit message'),
1228
help="refuse to commit if there are unknown "
1229
"files in the working tree."),
942
takes_options = ['message', 'file', 'verbose', 'unchanged']
1231
943
aliases = ['ci', 'checkin']
945
# TODO: Give better message for -s, --summary, used by tla people
1233
947
def run(self, message=None, file=None, verbose=True, selected_list=None,
1234
unchanged=False, strict=False):
1235
from bzrlib.errors import (PointlessCommit, ConflictsInTree,
949
from bzrlib.errors import PointlessCommit
1237
950
from bzrlib.msgeditor import edit_commit_message
1238
951
from bzrlib.status import show_status
1239
from tempfile import TemporaryFile
952
from cStringIO import StringIO
1242
# TODO: do more checks that the commit will succeed before
1243
# spending the user's valuable time typing a commit message.
1245
# TODO: if the commit *does* happen to fail, then save the commit
1246
# message to a temporary file where it can be recovered
1247
tree, selected_list = tree_files(selected_list)
1248
if message is None and not file:
1249
template = make_commit_message_template(tree)
1250
message = edit_commit_message(template)
956
selected_list = [b.relpath(s) for s in selected_list]
958
if not message and not file:
960
show_status(b, specific_files=selected_list,
962
message = edit_commit_message(catcher.getvalue())
1251
964
if message is None:
1252
965
raise BzrCommandError("please specify a commit message"
1253
966
" with either --message or --file")
1323
1022
The check command or bzr developers may sometimes advise you to run
1326
This version of this command upgrades from the full-text storage
1327
used by bzr 0.0.8 and earlier to the weave format (v5).
1329
1025
takes_args = ['dir?']
1331
def run(self, dir=u'.'):
1027
def run(self, dir='.'):
1332
1028
from bzrlib.upgrade import upgrade
1029
upgrade(find_branch(dir))
1336
1033
class cmd_whoami(Command):
1337
1034
"""Show bzr user id."""
1338
1035
takes_options = ['email']
1341
1037
def run(self, email=False):
1343
b = WorkingTree.open_containing(u'.')[0].branch
1344
config = bzrlib.config.BranchConfig(b)
1345
except NotBranchError:
1346
config = bzrlib.config.GlobalConfig()
1039
b = bzrlib.branch.find_branch('.')
1349
print config.user_email()
1351
print config.username()
1353
class cmd_nick(Command):
1355
Print or set the branch nickname.
1356
If unset, the tree root directory name is used as the nickname
1357
To print the current nickname, execute with no argument.
1359
takes_args = ['nickname?']
1360
def run(self, nickname=None):
1361
branch = Branch.open_containing(u'.')[0]
1362
if nickname is None:
1363
self.printme(branch)
1365
branch.nick = nickname
1368
def printme(self, branch):
1044
print bzrlib.osutils.user_email(b)
1046
print bzrlib.osutils.username(b)
1371
1049
class cmd_selftest(Command):
1372
"""Run internal test suite.
1374
This creates temporary test directories in the working directory,
1375
but not existing data is affected. These directories are deleted
1376
if the tests pass, or left behind to help in debugging if they
1377
fail and --keep-output is specified.
1379
If arguments are given, they are regular expressions that say
1380
which tests should run.
1382
# TODO: --list should give a list of all available tests
1050
"""Run internal test suite"""
1384
takes_args = ['testspecs*']
1385
takes_options = ['verbose',
1386
Option('one', help='stop when one test fails'),
1387
Option('keep-output',
1388
help='keep output directories when tests fail')
1391
def run(self, testspecs_list=None, verbose=False, one=False,
1052
takes_options = ['verbose', 'pattern']
1053
def run(self, verbose=False, pattern=".*"):
1393
1054
import bzrlib.ui
1394
from bzrlib.tests import selftest
1055
from bzrlib.selftest import selftest
1395
1056
# we don't want progress meters from the tests to go to the
1396
1057
# real output; and we don't want log messages cluttering up
1397
1058
# the real logs.
1433
1087
class cmd_version(Command):
1434
1088
"""Show version of bzr."""
1439
1092
class cmd_rocks(Command):
1440
1093
"""Statement of optimism."""
1444
1096
print "it sure does!"
1447
1099
class cmd_find_merge_base(Command):
1448
1100
"""Find and print a base revision for merging two branches.
1102
TODO: Options to specify revisions on either side, as if
1103
merging only part of the history.
1450
# TODO: Options to specify revisions on either side, as if
1451
# merging only part of the history.
1452
1105
takes_args = ['branch', 'other']
1456
1108
def run(self, branch, other):
1457
1109
from bzrlib.revision import common_ancestor, MultipleRevisionSources
1459
branch1 = Branch.open_containing(branch)[0]
1460
branch2 = Branch.open_containing(other)[0]
1111
branch1 = find_branch(branch)
1112
branch2 = find_branch(other)
1462
1114
history_1 = branch1.revision_history()
1463
1115
history_2 = branch2.revision_history()
1465
last1 = branch1.last_revision()
1466
last2 = branch2.last_revision()
1117
last1 = branch1.last_patch()
1118
last2 = branch2.last_patch()
1468
1120
source = MultipleRevisionSources(branch1, branch2)
1512
1164
--force is given.
1514
1166
takes_args = ['branch?']
1515
takes_options = ['revision', 'force', 'merge-type', 'reprocess',
1516
Option('show-base', help="Show base revision text in "
1167
takes_options = ['revision', 'force', 'merge-type']
1519
def run(self, branch=None, revision=None, force=False, merge_type=None,
1520
show_base=False, reprocess=False):
1169
def run(self, branch='.', revision=None, force=False,
1521
1171
from bzrlib.merge import merge
1522
1172
from bzrlib.merge_core import ApplyMerge3
1523
1173
if merge_type is None:
1524
1174
merge_type = ApplyMerge3
1526
branch = WorkingTree.open_containing(u'.')[0].branch.get_parent()
1528
raise BzrCommandError("No merge location known or specified.")
1530
print "Using saved location: %s" % branch
1531
1176
if revision is None or len(revision) < 1:
1532
1177
base = [None, None]
1533
1178
other = [branch, -1]
1535
1180
if len(revision) == 1:
1181
other = [branch, revision[0]]
1536
1182
base = [None, None]
1537
other_branch = Branch.open_containing(branch)[0]
1538
revno = revision[0].in_history(other_branch).revno
1539
other = [branch, revno]
1541
1184
assert len(revision) == 2
1542
1185
if None in revision:
1543
1186
raise BzrCommandError(
1544
1187
"Merge doesn't permit that revision specifier.")
1545
b = Branch.open_containing(branch)[0]
1547
base = [branch, revision[0].in_history(b).revno]
1548
other = [branch, revision[1].in_history(b).revno]
1188
base = [branch, revision[0]]
1189
other = [branch, revision[1]]
1551
conflict_count = merge(other, base, check_clean=(not force),
1552
merge_type=merge_type, reprocess=reprocess,
1553
show_base=show_base)
1554
if conflict_count != 0:
1192
merge(other, base, check_clean=(not force), merge_type=merge_type)
1558
1193
except bzrlib.errors.AmbiguousBase, e:
1559
1194
m = ("sorry, bzr can't determine the right merge base yet\n"
1560
1195
"candidates are:\n "
1568
class cmd_remerge(Command):
1571
takes_args = ['file*']
1572
takes_options = ['merge-type', 'reprocess',
1573
Option('show-base', help="Show base revision text in "
1576
def run(self, file_list=None, merge_type=None, show_base=False,
1578
from bzrlib.merge import merge_inner, transform_tree
1579
from bzrlib.merge_core import ApplyMerge3
1580
if merge_type is None:
1581
merge_type = ApplyMerge3
1582
tree, file_list = tree_files(file_list)
1585
pending_merges = tree.pending_merges()
1586
if len(pending_merges) != 1:
1587
raise BzrCommandError("Sorry, remerge only works after normal"
1588
+ " merges. Not cherrypicking or"
1590
base_revision = common_ancestor(tree.branch.last_revision(),
1591
pending_merges[0], tree.branch)
1592
base_tree = tree.branch.revision_tree(base_revision)
1593
other_tree = tree.branch.revision_tree(pending_merges[0])
1594
interesting_ids = None
1595
if file_list is not None:
1596
interesting_ids = set()
1597
for filename in file_list:
1598
file_id = tree.path2id(filename)
1599
interesting_ids.add(file_id)
1600
if tree.kind(file_id) != "directory":
1603
for name, ie in tree.inventory.iter_entries(file_id):
1604
interesting_ids.add(ie.file_id)
1605
transform_tree(tree, tree.branch.basis_tree(), interesting_ids)
1606
if file_list is None:
1607
restore_files = list(tree.iter_conflicts())
1609
restore_files = file_list
1610
for filename in restore_files:
1612
restore(tree.abspath(filename))
1613
except NotConflicted:
1615
conflicts = merge_inner(tree.branch, other_tree, base_tree,
1616
interesting_ids = interesting_ids,
1617
other_rev_id=pending_merges[0],
1618
merge_type=merge_type,
1619
show_base=show_base,
1620
reprocess=reprocess)
1628
1203
class cmd_revert(Command):
1629
1204
"""Reverse all changes since the last commit.
1689
1262
aliases = ['s-c']
1693
1265
def run(self, context=None):
1694
1266
import shellcomplete
1695
1267
shellcomplete.shellcomplete(context)
1698
class cmd_fetch(Command):
1699
"""Copy in history from another branch but don't merge it.
1701
This is an internal method used for pull and merge."""
1703
takes_args = ['from_branch', 'to_branch']
1704
def run(self, from_branch, to_branch):
1705
from bzrlib.fetch import Fetcher
1706
from bzrlib.branch import Branch
1707
from_b = Branch.open(from_branch)
1708
to_b = Branch.open(to_branch)
1713
Fetcher(to_b, from_b)
1720
1270
class cmd_missing(Command):
1721
1271
"""What is missing in this branch relative to other branch.
1723
# TODO: rewrite this in terms of ancestry so that it shows only
1726
1273
takes_args = ['remote?']
1727
1274
aliases = ['mis', 'miss']
1728
takes_options = ['verbose']
1275
# We don't have to add quiet to the list, because
1276
# unknown options are parsed as booleans
1277
takes_options = ['verbose', 'quiet']
1731
def run(self, remote=None, verbose=False):
1279
def run(self, remote=None, verbose=False, quiet=False):
1732
1280
from bzrlib.errors import BzrCommandError
1733
1281
from bzrlib.missing import show_missing
1735
if verbose and is_quiet():
1283
if verbose and quiet:
1736
1284
raise BzrCommandError('Cannot pass both quiet and verbose')
1738
tree = WorkingTree.open_containing(u'.')[0]
1739
parent = tree.branch.get_parent()
1286
b = find_branch('.')
1287
parent = b.get_parent()
1740
1288
if remote is None:
1741
1289
if parent is None:
1742
1290
raise BzrCommandError("No missing location known or specified.")
1745
1293
print "Using last location: %s" % parent
1746
1294
remote = parent
1747
1295
elif parent is None:
1748
# We only update parent if it did not exist, missing
1749
# should not change the parent
1750
tree.branch.set_parent(remote)
1751
br_remote = Branch.open_containing(remote)[0]
1752
return show_missing(tree.branch, br_remote, verbose=verbose,
1296
# We only update parent if it did not exist, missing should not change the parent
1297
b.set_parent(remote)
1298
br_remote = find_branch(remote)
1300
return show_missing(b, br_remote, verbose=verbose, quiet=quiet)
1756
1304
class cmd_plugins(Command):
1757
1305
"""List plugins"""
1761
1308
import bzrlib.plugin
1762
1309
from inspect import getdoc
1773
1320
print '\t', d.split('\n')[0]
1776
class cmd_testament(Command):
1777
"""Show testament (signing-form) of a revision."""
1778
takes_options = ['revision', 'long']
1779
takes_args = ['branch?']
1781
def run(self, branch=u'.', revision=None, long=False):
1782
from bzrlib.testament import Testament
1783
b = WorkingTree.open_containing(branch)[0].branch
1786
if revision is None:
1787
rev_id = b.last_revision()
1789
rev_id = revision[0].in_history(b).rev_id
1790
t = Testament.from_revision(b, rev_id)
1792
sys.stdout.writelines(t.as_text_lines())
1794
sys.stdout.write(t.as_short_text())
1799
class cmd_annotate(Command):
1800
"""Show the origin of each line in a file.
1802
This prints out the given file with an annotation on the left side
1803
indicating which revision, author and date introduced the change.
1805
If the origin is the same for a run of consecutive lines, it is
1806
shown only at the top, unless the --all option is given.
1808
# TODO: annotate directories; showing when each file was last changed
1809
# TODO: annotate a previous version of a file
1810
# TODO: if the working copy is modified, show annotations on that
1811
# with new uncommitted lines marked
1812
aliases = ['blame', 'praise']
1813
takes_args = ['filename']
1814
takes_options = [Option('all', help='show annotations on all lines'),
1815
Option('long', help='show date in annotations'),
1819
def run(self, filename, all=False, long=False):
1820
from bzrlib.annotate import annotate_file
1821
tree, relpath = WorkingTree.open_containing(filename)
1822
branch = tree.branch
1825
file_id = tree.inventory.path2id(relpath)
1826
tree = branch.revision_tree(branch.last_revision())
1827
file_version = tree.inventory[file_id].revision
1828
annotate_file(branch, file_version, file_id, long, all, sys.stdout)
1833
class cmd_re_sign(Command):
1834
"""Create a digital signature for an existing revision."""
1835
# TODO be able to replace existing ones.
1837
hidden = True # is this right ?
1838
takes_args = ['revision_id?']
1839
takes_options = ['revision']
1841
def run(self, revision_id=None, revision=None):
1842
import bzrlib.config as config
1843
import bzrlib.gpg as gpg
1844
if revision_id is not None and revision is not None:
1845
raise BzrCommandError('You can only supply one of revision_id or --revision')
1846
if revision_id is None and revision is None:
1847
raise BzrCommandError('You must supply either --revision or a revision_id')
1848
b = WorkingTree.open_containing(u'.')[0].branch
1849
gpg_strategy = gpg.GPGStrategy(config.BranchConfig(b))
1850
if revision_id is not None:
1851
b.sign_revision(revision_id, gpg_strategy)
1852
elif revision is not None:
1853
if len(revision) == 1:
1854
revno, rev_id = revision[0].in_history(b)
1855
b.sign_revision(rev_id, gpg_strategy)
1856
elif len(revision) == 2:
1857
# are they both on rh- if so we can walk between them
1858
# might be nice to have a range helper for arbitrary
1859
# revision paths. hmm.
1860
from_revno, from_revid = revision[0].in_history(b)
1861
to_revno, to_revid = revision[1].in_history(b)
1862
if to_revid is None:
1863
to_revno = b.revno()
1864
if from_revno is None or to_revno is None:
1865
raise BzrCommandError('Cannot sign a range of non-revision-history revisions')
1866
for revno in range(from_revno, to_revno + 1):
1867
b.sign_revision(b.get_rev_id(revno), gpg_strategy)
1869
raise BzrCommandError('Please supply either one revision, or a range.')
1872
class cmd_uncommit(bzrlib.commands.Command):
1873
"""Remove the last committed revision.
1875
By supplying the --all flag, it will not only remove the entry
1876
from revision_history, but also remove all of the entries in the
1879
--verbose will print out what is being removed.
1880
--dry-run will go through all the motions, but not actually
1883
In the future, uncommit will create a changeset, which can then
1886
takes_options = ['all', 'verbose', 'revision',
1887
Option('dry-run', help='Don\'t actually make changes'),
1888
Option('force', help='Say yes to all questions.')]
1889
takes_args = ['location?']
1892
def run(self, location=None, all=False,
1893
dry_run=False, verbose=False,
1894
revision=None, force=False):
1895
from bzrlib.branch import Branch
1896
from bzrlib.log import log_formatter
1898
from bzrlib.uncommit import uncommit
1900
if location is None:
1902
b, relpath = Branch.open_containing(location)
1904
if revision is None:
1906
rev_id = b.last_revision()
1908
revno, rev_id = revision[0].in_history(b)
1910
print 'No revisions to uncommit.'
1912
for r in range(revno, b.revno()+1):
1913
rev_id = b.get_rev_id(r)
1914
lf = log_formatter('short', to_file=sys.stdout,show_timezone='original')
1915
lf.show(r, b.get_revision(rev_id), None)
1918
print 'Dry-run, pretending to remove the above revisions.'
1920
val = raw_input('Press <enter> to continue')
1922
print 'The above revision(s) will be removed.'
1924
val = raw_input('Are you sure [y/N]? ')
1925
if val.lower() not in ('y', 'yes'):
1929
uncommit(b, remove_files=all,
1930
dry_run=dry_run, verbose=verbose,
1934
# these get imported and then picked up by the scan for cmd_*
1935
# TODO: Some more consistent way to split command definitions across files;
1936
# we do need to load at least some information about them to know of
1938
from bzrlib.conflicts import cmd_resolve, cmd_conflicts, restore