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
26
from bzrlib import BZRDIR
27
from bzrlib.commands import Command, display_command
28
from bzrlib.branch import Branch
29
from bzrlib.errors import BzrError, BzrCheckError, BzrCommandError, NotBranchError
30
from bzrlib.errors import DivergedBranches, NoSuchFile, NoWorkingTree
31
from bzrlib.option import Option
32
from bzrlib.revisionspec import RevisionSpec
22
33
import bzrlib.trace
23
34
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
from bzrlib import BZRDIR
27
from bzrlib.commands import Command
35
from bzrlib.workingtree import WorkingTree
38
def branch_files(file_list, default_branch='.'):
40
Return a branch and list of branch-relative paths.
41
If supplied file_list is empty or None, the branch default will be used,
42
and returned file_list will match the original.
44
if file_list is None or len(file_list) == 0:
45
return Branch.open_containing(default_branch)[0], file_list
46
b = Branch.open_containing(file_list[0])[0]
48
# note that if this is a remote branch, we would want
49
# relpath against the transport. RBC 20051018
50
# Most branch ops can't meaningfully operate on files in remote branches;
51
# the above comment was in cmd_status. ADHB 20051026
52
tree = WorkingTree(b.base, b)
54
for filename in file_list:
56
new_list.append(tree.relpath(filename))
57
except NotBranchError:
58
raise BzrCommandError("%s is not in the same branch as %s" %
59
(filename, file_list[0]))
63
# TODO: Make sure no commands unconditionally use the working directory as a
64
# branch. If a filename argument is used, the first of them should be used to
65
# specify the branch. (Perhaps this can be factored out into some kind of
66
# Argument class, representing a file in a branch, where the first occurrence
30
69
class cmd_status(Command):
31
70
"""Display status summary.
63
102
files or directories is reported. If a directory is given, status
64
103
is reported for everything inside that directory.
66
If a revision is specified, the changes since that revision are shown.
105
If a revision argument is given, the status is calculated against
106
that revision, or between two revisions if two are provided.
109
# XXX: FIXME: bzr status should accept a -r option to show changes
110
# relative to a revision, or between revisions
112
# TODO: --no-recurse, --recurse options
68
114
takes_args = ['file*']
69
takes_options = ['all', 'show-ids', 'revision']
115
takes_options = ['all', 'show-ids']
70
116
aliases = ['st', 'stat']
72
def run(self, all=False, show_ids=False, file_list=None):
74
b = find_branch(file_list[0])
75
file_list = [b.relpath(x) for x in file_list]
76
# special case: only one path was given and it's the root
119
def run(self, all=False, show_ids=False, file_list=None, revision=None):
120
b, file_list = branch_files(file_list)
83
122
from bzrlib.status import show_status
84
123
show_status(b, show_unchanged=all, show_ids=show_ids,
85
specific_files=file_list)
124
specific_files=file_list, revision=revision)
88
127
class cmd_cat_revision(Command):
89
"""Write out metadata for a revision."""
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.
92
takes_args = ['revision_id']
135
takes_args = ['revision_id?']
136
takes_options = ['revision']
94
def run(self, revision_id):
96
sys.stdout.write(b.get_revision_xml_file(revision_id).read())
139
def run(self, revision_id=None, revision=None):
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 = Branch.open_containing('.')[0]
146
if revision_id is not None:
147
sys.stdout.write(b.get_revision_xml_file(revision_id).read())
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_file(rev_id).read())
99
156
class cmd_revno(Command):
100
157
"""Show current revision number.
102
159
This is equal to the number of revisions on this branch."""
104
print find_branch('.').revno()
162
print Branch.open_containing('.')[0].revno()
107
165
class cmd_revision_info(Command):
145
208
Therefore simply saying 'bzr add' will version all files that
146
209
are currently unknown.
148
TODO: Perhaps adding a file whose directly is not versioned should
149
recursively add that parent, rather than giving an error?
211
Adding a file whose parent directory is not versioned will
212
implicitly add the parent, and so on up to the root. This means
213
you should never need to explictly add a directory, they'll just
214
get added when you add a file in the directory.
151
216
takes_args = ['file*']
152
takes_options = ['verbose', 'no-recurse']
217
takes_options = ['no-recurse', 'quiet']
154
def run(self, file_list, verbose=False, no_recurse=False):
155
# verbose currently has no effect
156
from bzrlib.add import smart_add, add_reporter_print
157
smart_add(file_list, not no_recurse, add_reporter_print)
219
def run(self, file_list, no_recurse=False, quiet=False):
220
from bzrlib.add import smart_add, add_reporter_print, add_reporter_null
222
reporter = add_reporter_null
224
reporter = add_reporter_print
225
smart_add(file_list, not no_recurse, reporter)
161
228
class cmd_mkdir(Command):
274
341
if len(names_list) != 2:
275
342
raise BzrCommandError('to mv multiple files the destination '
276
343
'must be a versioned directory')
277
for pair in b.move(rel_names[0], rel_names[1]):
278
print "%s => %s" % pair
344
b.rename_one(rel_names[0], rel_names[1])
345
print "%s => %s" % (rel_names[0], rel_names[1])
283
348
class cmd_pull(Command):
284
349
"""Pull any changes from another branch into the current one.
286
If the location is omitted, the last-used location will be used.
287
Both the revision history and the working directory will be
351
If there is no default location set, the first pull will set it. After
352
that, you can omit the location to use the default. To change the
353
default, use --remember.
290
355
This command only works on branches that have not diverged. Branches are
291
356
considered diverged if both branches have had commits without first
292
357
pulling from the other.
294
359
If branches have diverged, you can use 'bzr merge' to pull the text changes
295
from one into the other.
360
from one into the other. Once one branch has merged, the other should
361
be able to pull it again.
363
If you want to forget your local changes and just update your branch to
364
match the remote one, use --overwrite.
366
takes_options = ['remember', 'overwrite']
297
367
takes_args = ['location?']
299
def run(self, location=None):
369
def run(self, location=None, remember=False, overwrite=False):
300
370
from bzrlib.merge import merge
302
371
from shutil import rmtree
304
from bzrlib.branch import pull_loc
306
br_to = find_branch('.')
309
stored_loc = br_to.controlfile("x-pull", "rb").read().rstrip('\n')
311
if e.errno != errno.ENOENT:
374
br_to = Branch.open_containing('.')[0]
375
stored_loc = br_to.get_parent()
313
376
if location is None:
314
377
if stored_loc is None:
315
378
raise BzrCommandError("No pull location known or specified.")
317
print "Using last location: %s" % stored_loc
318
location = stored_loc
319
cache_root = tempfile.mkdtemp()
320
from bzrlib.branch import DivergedBranches
321
br_from = find_branch(location)
322
location = pull_loc(br_from)
323
old_revno = br_to.revno()
325
from branch import find_cached_branch, DivergedBranches
326
br_from = find_cached_branch(location, cache_root)
327
location = pull_loc(br_from)
328
old_revno = br_to.revno()
330
br_to.update_revisions(br_from)
331
except DivergedBranches:
332
raise BzrCommandError("These branches have diverged."
335
merge(('.', -1), ('.', old_revno), check_clean=False)
336
if location != stored_loc:
337
br_to.controlfile("x-pull", "wb").write(location + "\n")
380
print "Using saved location: %s" % stored_loc
381
location = stored_loc
382
br_from = Branch.open(location)
384
br_to.working_tree().pull(br_from, overwrite)
385
except DivergedBranches:
386
raise BzrCommandError("These branches have diverged."
388
if br_to.get_parent() is None or remember:
389
br_to.set_parent(location)
392
class cmd_push(Command):
393
"""Push this branch into another branch.
395
The remote branch will not have its working tree populated because this
396
is both expensive, and may not be supported on the remote file system.
398
Some smart servers or protocols *may* put the working tree in place.
400
If there is no default push location set, the first push will set it.
401
After that, you can omit the location to use the default. To change the
402
default, use --remember.
404
This command only works on branches that have not diverged. Branches are
405
considered diverged if the branch being pushed to is not an older version
408
If branches have diverged, you can use 'bzr push --overwrite' to replace
409
the other branch completely.
411
If you want to ensure you have the different changes in the other branch,
412
do a merge (see bzr help merge) from the other branch, and commit that
413
before doing a 'push --overwrite'.
415
takes_options = ['remember', 'overwrite',
416
Option('create-prefix',
417
help='Create the path leading up to the branch '
418
'if it does not already exist')]
419
takes_args = ['location?']
421
def run(self, location=None, remember=False, overwrite=False,
422
create_prefix=False):
424
from shutil import rmtree
425
from bzrlib.transport import get_transport
427
br_from = Branch.open_containing('.')[0]
428
stored_loc = br_from.get_push_location()
430
if stored_loc is None:
431
raise BzrCommandError("No push location known or specified.")
433
print "Using saved location: %s" % stored_loc
434
location = stored_loc
436
br_to = Branch.open(location)
437
except NotBranchError:
439
transport = get_transport(location).clone('..')
440
if not create_prefix:
442
transport.mkdir(transport.relpath(location))
444
raise BzrCommandError("Parent directory of %s "
445
"does not exist." % location)
447
current = transport.base
448
needed = [(transport, transport.relpath(location))]
451
transport, relpath = needed[-1]
452
transport.mkdir(relpath)
455
new_transport = transport.clone('..')
456
needed.append((new_transport,
457
new_transport.relpath(transport.base)))
458
if new_transport.base == transport.base:
459
raise BzrCommandError("Could not creeate "
463
br_to = Branch.initialize(location)
465
br_to.pull(br_from, overwrite)
466
except DivergedBranches:
467
raise BzrCommandError("These branches have diverged."
468
" Try a merge then push with overwrite.")
469
if br_from.get_push_location() is None or remember:
470
br_from.set_push_location(location)
343
473
class cmd_branch(Command):
349
479
To retrieve the branch as of a particular revision, supply the --revision
350
480
parameter, as in "branch foo/bar -r 5".
482
--basis is to speed up branching from remote branches. When specified, it
483
copies all the file-contents, inventory and revision data from the basis
484
branch before copying anything from the remote branch.
352
486
takes_args = ['from_location', 'to_location?']
353
takes_options = ['revision']
487
takes_options = ['revision', 'basis']
354
488
aliases = ['get', 'clone']
356
def run(self, from_location, to_location=None, revision=None):
357
from bzrlib.branch import copy_branch, find_cached_branch
490
def run(self, from_location, to_location=None, revision=None, basis=None):
491
from bzrlib.clone import copy_branch
360
493
from shutil import rmtree
361
cache_root = tempfile.mkdtemp()
365
elif len(revision) > 1:
366
raise BzrCommandError(
367
'bzr branch --revision takes exactly 1 revision value')
369
br_from = find_cached_branch(from_location, cache_root)
371
if e.errno == errno.ENOENT:
372
raise BzrCommandError('Source location "%s" does not'
373
' exist.' % to_location)
496
elif len(revision) > 1:
497
raise BzrCommandError(
498
'bzr branch --revision takes exactly 1 revision value')
500
br_from = Branch.open(from_location)
502
if e.errno == errno.ENOENT:
503
raise BzrCommandError('Source location "%s" does not'
504
' exist.' % to_location)
509
if basis is not None:
510
basis_branch = Branch.open_containing(basis)[0]
513
if len(revision) == 1 and revision[0] is not None:
514
revision_id = revision[0].in_history(br_from)[1]
376
517
if to_location is None:
377
518
to_location = os.path.basename(from_location.rstrip("/\\"))
521
name = os.path.basename(to_location) + '\n'
379
523
os.mkdir(to_location)
380
524
except OSError, e:
390
copy_branch(br_from, to_location, revision[0])
534
copy_branch(br_from, to_location, revision_id, basis_branch)
391
535
except bzrlib.errors.NoSuchRevision:
392
536
rmtree(to_location)
393
msg = "The branch %s has no revision %d." % (from_location, revision[0])
394
raise BzrCommandError(msg)
537
msg = "The branch %s has no revision %s." % (from_location, revision[0])
538
raise BzrCommandError(msg)
539
except bzrlib.errors.UnlistableBranch:
541
msg = "The branch %s cannot be used as a --basis"
542
raise BzrCommandError(msg)
544
branch = Branch.open(to_location)
545
name = StringIO(name)
546
branch.put_controlfile('branch-name', name)
399
551
class cmd_renames(Command):
400
552
"""Show list of renamed files.
402
TODO: Option to show renames between two historical versions.
404
TODO: Only show renames under dir, rather than in the whole branch.
554
# TODO: Option to show renames between two historical versions.
556
# TODO: Only show renames under dir, rather than in the whole branch.
406
557
takes_args = ['dir?']
408
560
def run(self, dir='.'):
561
b = Branch.open_containing(dir)[0]
410
562
old_inv = b.basis_tree().inventory
411
new_inv = b.read_working_inventory()
563
new_inv = b.working_tree().read_working_inventory()
413
565
renames = list(bzrlib.tree.find_renames(old_inv, new_inv))
518
698
If files are listed, only the changes in those files are listed.
519
699
Otherwise, all changes for the tree are listed.
521
TODO: Allow diff across branches.
523
TODO: Option to use external diff command; could be GNU diff, wdiff,
526
TODO: Python difflib is not exactly the same as unidiff; should
527
either fix it up or prefer to use an external diff.
529
TODO: If a directory is given, diff everything under that.
531
TODO: Selected-file diff is inefficient and doesn't show you
534
TODO: This probably handles non-Unix newlines poorly.
706
# TODO: Allow diff across branches.
707
# TODO: Option to use external diff command; could be GNU diff, wdiff,
708
# or a graphical diff.
710
# TODO: Python difflib is not exactly the same as unidiff; should
711
# either fix it up or prefer to use an external diff.
713
# TODO: If a directory is given, diff everything under that.
715
# TODO: Selected-file diff is inefficient and doesn't show you
718
# TODO: This probably handles non-Unix newlines poorly.
542
720
takes_args = ['file*']
543
721
takes_options = ['revision', 'diff-options']
544
722
aliases = ['di', 'dif']
546
725
def run(self, revision=None, file_list=None, diff_options=None):
547
726
from bzrlib.diff import show_diff
550
b = find_branch(file_list[0])
551
file_list = [b.relpath(f) for f in file_list]
552
if file_list == ['']:
553
# just pointing to top-of-tree
728
b, file_list = branch_files(file_list)
558
729
if revision is not None:
559
730
if len(revision) == 1:
560
show_diff(b, revision[0], specific_files=file_list,
561
external_diff_options=diff_options)
731
return show_diff(b, revision[0], specific_files=file_list,
732
external_diff_options=diff_options)
562
733
elif len(revision) == 2:
563
show_diff(b, revision[0], specific_files=file_list,
564
external_diff_options=diff_options,
565
revision2=revision[1])
734
return show_diff(b, revision[0], specific_files=file_list,
735
external_diff_options=diff_options,
736
revision2=revision[1])
567
738
raise BzrCommandError('bzr diff --revision takes exactly one or two revision identifiers')
569
show_diff(b, None, specific_files=file_list,
570
external_diff_options=diff_options)
740
return show_diff(b, None, specific_files=file_list,
741
external_diff_options=diff_options)
575
744
class cmd_deleted(Command):
576
745
"""List files deleted in the working tree.
578
TODO: Show files deleted since a previous revision, or between two revisions.
747
# TODO: Show files deleted since a previous revision, or
748
# between two revisions.
749
# TODO: Much more efficient way to do this: read in new
750
# directories with readdir, rather than stating each one. Same
751
# level of effort but possibly much less IO. (Or possibly not,
752
# if the directories are very large...)
580
754
def run(self, show_ids=False):
755
b = Branch.open_containing('.')[0]
582
756
old = b.basis_tree()
583
757
new = b.working_tree()
585
## TODO: Much more efficient way to do this: read in new
586
## directories with readdir, rather than stating each one. Same
587
## level of effort but possibly much less IO. (Or possibly not,
588
## if the directories are very large...)
590
758
for path, ie in old.inventory.iter_entries():
591
759
if not new.has_id(ie.file_id):
645
816
To request a range of logs, you can use the command -r begin:end
646
817
-r revision requests a specific revision, -r :end or -r begin: are
649
--message allows you to give a regular expression, which will be evaluated
650
so that only matching entries will be displayed.
652
TODO: Make --revision support uuid: and hash: [future tag:] notation.
821
# TODO: Make --revision support uuid: and hash: [future tag:] notation.
656
823
takes_args = ['filename?']
657
takes_options = ['forward', 'timezone', 'verbose', 'show-ids', 'revision',
658
'long', 'message', 'short',]
824
takes_options = [Option('forward',
825
help='show from oldest to newest'),
826
'timezone', 'verbose',
827
'show-ids', 'revision',
828
Option('line', help='format with one line per revision'),
831
help='show revisions whose message matches this regexp',
833
Option('short', help='use moderately short format'),
660
836
def run(self, filename=None, timezone='original',
668
845
from bzrlib.log import log_formatter, show_log
847
assert message is None or isinstance(message, basestring), \
848
"invalid message argument %r" % message
671
849
direction = (forward and 'forward') or 'reverse'
674
b = find_branch(filename)
675
fp = b.relpath(filename)
677
file_id = b.read_working_inventory().path2id(fp)
852
b, fp = Branch.open_containing(filename)
855
inv = b.working_tree().read_working_inventory()
856
except NoWorkingTree:
857
inv = b.get_inventory(b.last_revision())
858
file_id = inv.path2id(fp)
679
860
file_id = None # points to branch root
862
b, relpath = Branch.open_containing('.')
684
865
if revision is None:
687
868
elif len(revision) == 1:
688
rev1 = rev2 = b.get_revision_info(revision[0])[0]
869
rev1 = rev2 = revision[0].in_history(b).revno
689
870
elif len(revision) == 2:
690
rev1 = b.get_revision_info(revision[0])[0]
691
rev2 = b.get_revision_info(revision[1])[0]
871
rev1 = revision[0].in_history(b).revno
872
rev2 = revision[1].in_history(b).revno
693
874
raise BzrCommandError('bzr log --revision takes one or two values.')
729
911
A more user-friendly interface is "bzr log FILE"."""
731
913
takes_args = ["filename"]
732
915
def run(self, filename):
733
b = find_branch(filename)
734
inv = b.read_working_inventory()
735
file_id = inv.path2id(b.relpath(filename))
916
b, relpath = Branch.open_containing(filename)[0]
917
inv = b.working_tree().read_working_inventory()
918
file_id = inv.path2id(relpath)
736
919
for revno, revision_id, what in bzrlib.log.find_touching_revisions(b, file_id):
737
920
print "%6d %s" % (revno, what)
740
923
class cmd_ls(Command):
741
924
"""List files in a tree.
743
TODO: Take a revision or remote path and list that tree instead.
926
# TODO: Take a revision or remote path and list that tree instead.
746
def run(self, revision=None, verbose=False):
928
takes_options = ['verbose', 'revision',
929
Option('non-recursive',
930
help='don\'t recurse into sub-directories'),
932
help='Print all paths from the root of the branch.'),
933
Option('unknown', help='Print unknown files'),
934
Option('versioned', help='Print versioned files'),
935
Option('ignored', help='Print ignored files'),
937
Option('null', help='Null separate the files'),
940
def run(self, revision=None, verbose=False,
941
non_recursive=False, from_root=False,
942
unknown=False, versioned=False, ignored=False,
946
raise BzrCommandError('Cannot set both --verbose and --null')
947
all = not (unknown or versioned or ignored)
949
selection = {'I':ignored, '?':unknown, 'V':versioned}
951
b, relpath = Branch.open_containing('.')
748
956
if revision == None:
749
957
tree = b.working_tree()
751
tree = b.revision_tree(b.lookup_revision(revision))
753
for fp, fc, kind, fid in tree.list_files():
755
if kind == 'directory':
959
tree = b.revision_tree(revision[0].in_history(b).rev_id)
960
for fp, fc, kind, fid, entry in tree.list_files():
961
if fp.startswith(relpath):
962
fp = fp[len(relpath):]
963
if non_recursive and '/' in fp:
965
if not all and not selection[fc]:
968
kindch = entry.kind_character()
969
print '%-8s %s%s' % (fc, fp, kindch)
972
sys.stdout.write('\0')
762
print '%-8s %s%s' % (fc, fp, kindch)
768
979
class cmd_unknowns(Command):
769
980
"""List unknown files."""
771
983
from bzrlib.osutils import quotefn
772
for f in find_branch('.').unknowns():
984
for f in Branch.open_containing('.')[0].unknowns():
880
1096
takes_options = ['revision', 'format', 'root']
881
1097
def run(self, dest, revision=None, format=None, root=None):
1099
b = Branch.open_containing('.')[0]
884
1100
if revision is None:
885
rev_id = b.last_patch()
1101
rev_id = b.last_revision()
887
1103
if len(revision) != 1:
888
1104
raise BzrError('bzr export --revision takes exactly 1 argument')
889
revno, rev_id = b.get_revision_info(revision[0])
1105
rev_id = revision[0].in_history(b).rev_id
890
1106
t = b.revision_tree(rev_id)
891
root, ext = os.path.splitext(dest)
1107
arg_root, ext = os.path.splitext(os.path.basename(dest))
1108
if ext in ('.gz', '.bz2'):
1109
new_root, new_ext = os.path.splitext(arg_root)
1110
if new_ext == '.tar':
893
1116
if ext in (".tar",):
895
elif ext in (".gz", ".tgz"):
1118
elif ext in (".tar.gz", ".tgz"):
897
elif ext in (".bz2", ".tbz2"):
1120
elif ext in (".tar.bz2", ".tbz2"):
936
1161
A selected-file commit may fail in some cases where the committed
937
1162
tree would be invalid, such as trying to commit a file in a
938
1163
newly-added directory that is not itself committed.
940
TODO: Run hooks on tree to-be-committed, and after commit.
942
TODO: Strict commit that fails if there are unknown or deleted files.
1165
# TODO: Run hooks on tree to-be-committed, and after commit.
1167
# TODO: Strict commit that fails if there are deleted files.
1168
# (what does "deleted files" mean ??)
1170
# TODO: Give better message for -s, --summary, used by tla people
1172
# XXX: verbose currently does nothing
944
1174
takes_args = ['selected*']
945
takes_options = ['message', 'file', 'verbose', 'unchanged']
1175
takes_options = ['message', 'verbose',
1177
help='commit even if nothing has changed'),
1178
Option('file', type=str,
1180
help='file containing commit message'),
1182
help="refuse to commit if there are unknown "
1183
"files in the working tree."),
946
1185
aliases = ['ci', 'checkin']
948
# TODO: Give better message for -s, --summary, used by tla people
950
# XXX: verbose currently does nothing
952
1187
def run(self, message=None, file=None, verbose=True, selected_list=None,
954
from bzrlib.errors import PointlessCommit
1188
unchanged=False, strict=False):
1189
from bzrlib.errors import (PointlessCommit, ConflictsInTree,
955
1191
from bzrlib.msgeditor import edit_commit_message
956
1192
from bzrlib.status import show_status
957
1193
from cStringIO import StringIO
961
selected_list = [b.relpath(s) for s in selected_list]
963
if not message and not file:
1195
b, selected_list = branch_files(selected_list)
1196
if message is None and not file:
964
1197
catcher = StringIO()
965
1198
show_status(b, specific_files=selected_list,
966
1199
to_file=catcher)
967
1200
message = edit_commit_message(catcher.getvalue())
969
1202
if message is None:
970
1203
raise BzrCommandError("please specify a commit message"
971
1204
" with either --message or --file")
977
1210
message = codecs.open(file, 'rt', bzrlib.user_encoding).read()
1213
raise BzrCommandError("empty commit message specified")
981
specific_files=selected_list,
982
allow_pointless=unchanged)
1216
b.commit(message, specific_files=selected_list,
1217
allow_pointless=unchanged, strict=strict)
983
1218
except PointlessCommit:
984
1219
# FIXME: This should really happen before the file is read in;
985
1220
# perhaps prepare the commit; get the message; then actually commit
986
1221
raise BzrCommandError("no changes to commit",
987
1222
["use --unchanged to commit anyhow"])
1223
except ConflictsInTree:
1224
raise BzrCommandError("Conflicts detected in working tree. "
1225
'Use "bzr conflicts" to list, "bzr resolve FILE" to resolve.')
1226
except StrictCommitFailed:
1227
raise BzrCommandError("Commit refused because there are unknown "
1228
"files in the working tree.")
990
1231
class cmd_check(Command):
1030
1268
The check command or bzr developers may sometimes advise you to run
1271
This version of this command upgrades from the full-text storage
1272
used by bzr 0.0.8 and earlier to the weave format (v5).
1033
1274
takes_args = ['dir?']
1035
1276
def run(self, dir='.'):
1036
1277
from bzrlib.upgrade import upgrade
1037
upgrade(find_branch(dir))
1041
1281
class cmd_whoami(Command):
1042
1282
"""Show bzr user id."""
1043
1283
takes_options = ['email']
1045
1286
def run(self, email=False):
1047
b = bzrlib.branch.find_branch('.')
1288
b = bzrlib.branch.Branch.open_containing('.')[0]
1289
config = bzrlib.config.BranchConfig(b)
1290
except NotBranchError:
1291
config = bzrlib.config.GlobalConfig()
1052
print bzrlib.osutils.user_email(b)
1294
print config.user_email()
1054
print bzrlib.osutils.username(b)
1296
print config.username()
1057
1299
class cmd_selftest(Command):
1058
"""Run internal test suite"""
1300
"""Run internal test suite.
1302
This creates temporary test directories in the working directory,
1303
but not existing data is affected. These directories are deleted
1304
if the tests pass, or left behind to help in debugging if they
1307
If arguments are given, they are regular expressions that say
1308
which tests should run.
1310
# TODO: --list should give a list of all available tests
1060
takes_options = ['verbose', 'pattern']
1061
def run(self, verbose=False, pattern=".*"):
1312
takes_args = ['testspecs*']
1313
takes_options = ['verbose',
1314
Option('one', help='stop when one test fails'),
1317
def run(self, testspecs_list=None, verbose=False, one=False):
1062
1318
import bzrlib.ui
1063
1319
from bzrlib.selftest import selftest
1064
1320
# we don't want progress meters from the tests to go to the
1095
1357
class cmd_version(Command):
1096
1358
"""Show version of bzr."""
1100
1363
class cmd_rocks(Command):
1101
1364
"""Statement of optimism."""
1104
1368
print "it sure does!"
1107
1371
class cmd_find_merge_base(Command):
1108
1372
"""Find and print a base revision for merging two branches.
1110
TODO: Options to specify revisions on either side, as if
1111
merging only part of the history.
1374
# TODO: Options to specify revisions on either side, as if
1375
# merging only part of the history.
1113
1376
takes_args = ['branch', 'other']
1116
1380
def run(self, branch, other):
1117
1381
from bzrlib.revision import common_ancestor, MultipleRevisionSources
1119
branch1 = find_branch(branch)
1120
branch2 = find_branch(other)
1383
branch1 = Branch.open_containing(branch)[0]
1384
branch2 = Branch.open_containing(other)[0]
1122
1386
history_1 = branch1.revision_history()
1123
1387
history_2 = branch2.revision_history()
1125
last1 = branch1.last_patch()
1126
last2 = branch2.last_patch()
1389
last1 = branch1.last_revision()
1390
last2 = branch2.last_revision()
1128
1392
source = MultipleRevisionSources(branch1, branch2)
1172
1436
--force is given.
1174
1438
takes_args = ['branch?']
1175
takes_options = ['revision', 'force', 'merge-type']
1439
takes_options = ['revision', 'force', 'merge-type', 'reprocess',
1440
Option('show-base', help="Show base revision text in "
1177
def run(self, branch='.', revision=None, force=False,
1443
def run(self, branch=None, revision=None, force=False, merge_type=None,
1444
show_base=False, reprocess=False):
1179
1445
from bzrlib.merge import merge
1180
1446
from bzrlib.merge_core import ApplyMerge3
1181
1447
if merge_type is None:
1182
1448
merge_type = ApplyMerge3
1450
branch = Branch.open_containing('.')[0].get_parent()
1452
raise BzrCommandError("No merge location known or specified.")
1454
print "Using saved location: %s" % branch
1184
1455
if revision is None or len(revision) < 1:
1185
1456
base = [None, None]
1186
1457
other = [branch, -1]
1188
1459
if len(revision) == 1:
1189
other = [branch, revision[0]]
1190
1460
base = [None, None]
1461
other_branch = Branch.open_containing(branch)[0]
1462
revno = revision[0].in_history(other_branch).revno
1463
other = [branch, revno]
1192
1465
assert len(revision) == 2
1193
1466
if None in revision:
1194
1467
raise BzrCommandError(
1195
1468
"Merge doesn't permit that revision specifier.")
1196
base = [branch, revision[0]]
1197
other = [branch, revision[1]]
1469
b = Branch.open_containing(branch)[0]
1471
base = [branch, revision[0].in_history(b).revno]
1472
other = [branch, revision[1].in_history(b).revno]
1200
merge(other, base, check_clean=(not force), merge_type=merge_type)
1475
conflict_count = merge(other, base, check_clean=(not force),
1476
merge_type=merge_type, reprocess=reprocess,
1477
show_base=show_base)
1478
if conflict_count != 0:
1201
1482
except bzrlib.errors.AmbiguousBase, e:
1202
1483
m = ("sorry, bzr can't determine the right merge base yet\n"
1203
1484
"candidates are:\n "
1222
1503
def run(self, revision=None, no_backup=False, file_list=None):
1223
1504
from bzrlib.merge import merge
1224
from bzrlib.branch import Branch
1225
1505
from bzrlib.commands import parse_spec
1227
1507
if file_list is not None:
1228
1508
if len(file_list) == 0:
1229
1509
raise BzrCommandError("No files specified")
1230
1510
if revision is None:
1232
1512
elif len(revision) != 1:
1233
1513
raise BzrCommandError('bzr revert --revision takes exactly 1 argument')
1234
merge(('.', revision[0]), parse_spec('.'),
1515
b, file_list = branch_files(file_list)
1516
revno = revision[0].in_history(b).revno
1517
merge(('.', revno), parse_spec('.'),
1235
1518
check_clean=False,
1236
1519
ignore_zero=True,
1237
1520
backup_files=not no_backup,
1238
1521
file_list=file_list)
1239
1522
if not file_list:
1240
Branch('.').set_pending_merges([])
1523
Branch.open_containing('.')[0].set_pending_merges([])
1243
1526
class cmd_assert_fail(Command):
1270
1554
aliases = ['s-c']
1273
1558
def run(self, context=None):
1274
1559
import shellcomplete
1275
1560
shellcomplete.shellcomplete(context)
1563
class cmd_fetch(Command):
1564
"""Copy in history from another branch but don't merge it.
1566
This is an internal method used for pull and merge."""
1568
takes_args = ['from_branch', 'to_branch']
1569
def run(self, from_branch, to_branch):
1570
from bzrlib.fetch import Fetcher
1571
from bzrlib.branch import Branch
1572
from_b = Branch.open(from_branch)
1573
to_b = Branch.open(to_branch)
1578
Fetcher(to_b, from_b)
1278
1585
class cmd_missing(Command):
1279
1586
"""What is missing in this branch relative to other branch.
1588
# TODO: rewrite this in terms of ancestry so that it shows only
1281
1591
takes_args = ['remote?']
1282
1592
aliases = ['mis', 'miss']
1283
1593
# We don't have to add quiet to the list, because
1284
1594
# unknown options are parsed as booleans
1285
1595
takes_options = ['verbose', 'quiet']
1287
1598
def run(self, remote=None, verbose=False, quiet=False):
1288
1599
from bzrlib.errors import BzrCommandError
1289
1600
from bzrlib.missing import show_missing
1328
1639
print '\t', d.split('\n')[0]
1642
class cmd_testament(Command):
1643
"""Show testament (signing-form) of a revision."""
1644
takes_options = ['revision', 'long']
1645
takes_args = ['branch?']
1647
def run(self, branch='.', revision=None, long=False):
1648
from bzrlib.testament import Testament
1649
b = Branch.open_containing(branch)[0]
1652
if revision is None:
1653
rev_id = b.last_revision()
1655
rev_id = revision[0].in_history(b).rev_id
1656
t = Testament.from_revision(b, rev_id)
1658
sys.stdout.writelines(t.as_text_lines())
1660
sys.stdout.write(t.as_short_text())
1665
class cmd_annotate(Command):
1666
"""Show the origin of each line in a file.
1668
This prints out the given file with an annotation on the left side
1669
indicating which revision, author and date introduced the change.
1671
If the origin is the same for a run of consecutive lines, it is
1672
shown only at the top, unless the --all option is given.
1674
# TODO: annotate directories; showing when each file was last changed
1675
# TODO: annotate a previous version of a file
1676
# TODO: if the working copy is modified, show annotations on that
1677
# with new uncommitted lines marked
1678
aliases = ['blame', 'praise']
1679
takes_args = ['filename']
1680
takes_options = [Option('all', help='show annotations on all lines'),
1681
Option('long', help='show date in annotations'),
1685
def run(self, filename, all=False, long=False):
1686
from bzrlib.annotate import annotate_file
1687
b, relpath = Branch.open_containing(filename)
1690
tree = WorkingTree(b.base, b)
1691
tree = b.revision_tree(b.last_revision())
1692
file_id = tree.inventory.path2id(relpath)
1693
file_version = tree.inventory[file_id].revision
1694
annotate_file(b, file_version, file_id, long, all, sys.stdout)
1699
class cmd_re_sign(Command):
1700
"""Create a digital signature for an existing revision."""
1701
# TODO be able to replace existing ones.
1703
hidden = True # is this right ?
1704
takes_args = ['revision_id?']
1705
takes_options = ['revision']
1707
def run(self, revision_id=None, revision=None):
1708
import bzrlib.config as config
1709
import bzrlib.gpg as gpg
1710
if revision_id is not None and revision is not None:
1711
raise BzrCommandError('You can only supply one of revision_id or --revision')
1712
if revision_id is None and revision is None:
1713
raise BzrCommandError('You must supply either --revision or a revision_id')
1714
b = Branch.open_containing('.')[0]
1715
gpg_strategy = gpg.GPGStrategy(config.BranchConfig(b))
1716
if revision_id is not None:
1717
b.sign_revision(revision_id, gpg_strategy)
1718
elif revision is not None:
1719
if len(revision) == 1:
1720
revno, rev_id = revision[0].in_history(b)
1721
b.sign_revision(rev_id, gpg_strategy)
1722
elif len(revision) == 2:
1723
# are they both on rh- if so we can walk between them
1724
# might be nice to have a range helper for arbitrary
1725
# revision paths. hmm.
1726
from_revno, from_revid = revision[0].in_history(b)
1727
to_revno, to_revid = revision[1].in_history(b)
1728
if to_revid is None:
1729
to_revno = b.revno()
1730
if from_revno is None or to_revno is None:
1731
raise BzrCommandError('Cannot sign a range of non-revision-history revisions')
1732
for revno in range(from_revno, to_revno + 1):
1733
b.sign_revision(b.get_rev_id(revno), gpg_strategy)
1735
raise BzrCommandError('Please supply either one revision, or a range.')
1738
# these get imported and then picked up by the scan for cmd_*
1739
# TODO: Some more consistent way to split command definitions across files;
1740
# we do need to load at least some information about them to know of
1742
from bzrlib.conflicts import cmd_resolve, cmd_conflicts