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
"""builtin bzr commands"""
24
from bzrlib import BZRDIR
25
from bzrlib._merge_core import ApplyMerge3
26
from bzrlib.commands import Command, display_command
27
from bzrlib.branch import Branch
28
from bzrlib.revision import common_ancestor
29
import bzrlib.errors as errors
30
from bzrlib.errors import (BzrError, BzrCheckError, BzrCommandError,
31
NotBranchError, DivergedBranches, NotConflicted,
32
NoSuchFile, NoWorkingTree, FileInWrongBranch)
33
from bzrlib.log import show_one_log
34
from bzrlib.option import Option
35
from bzrlib.revisionspec import RevisionSpec
22
36
import bzrlib.trace
23
from bzrlib.trace import mutter, note, log_error, warning
24
from bzrlib.errors import BzrError, BzrCheckError, BzrCommandError, NotBranchError
25
from bzrlib.errors import DivergedBranches
26
from bzrlib.branch import Branch
27
from bzrlib import BZRDIR
28
from bzrlib.commands import Command
37
from bzrlib.trace import mutter, note, log_error, warning, is_quiet
38
from bzrlib.transport.local import LocalTransport
39
from bzrlib.workingtree import WorkingTree
42
def tree_files(file_list, default_branch=u'.'):
44
return internal_tree_files(file_list, default_branch)
45
except FileInWrongBranch, e:
46
raise BzrCommandError("%s is not in the same branch as %s" %
47
(e.path, file_list[0]))
49
def internal_tree_files(file_list, default_branch=u'.'):
51
Return a branch and list of branch-relative paths.
52
If supplied file_list is empty or None, the branch default will be used,
53
and returned file_list will match the original.
55
if file_list is None or len(file_list) == 0:
56
return WorkingTree.open_containing(default_branch)[0], file_list
57
tree = WorkingTree.open_containing(file_list[0])[0]
59
for filename in file_list:
61
new_list.append(tree.relpath(filename))
62
except errors.PathNotChild:
63
raise FileInWrongBranch(tree.branch, filename)
67
# TODO: Make sure no commands unconditionally use the working directory as a
68
# branch. If a filename argument is used, the first of them should be used to
69
# specify the branch. (Perhaps this can be factored out into some kind of
70
# Argument class, representing a file in a branch, where the first occurrence
31
73
class cmd_status(Command):
32
74
"""Display status summary.
177
214
implicitly add the parent, and so on up to the root. This means
178
215
you should never need to explictly add a directory, they'll just
179
216
get added when you add a file in the directory.
218
--dry-run will show which files would be added, but not actually
181
221
takes_args = ['file*']
182
takes_options = ['no-recurse', 'quiet']
184
def run(self, file_list, no_recurse=False, quiet=False):
185
from bzrlib.add import smart_add, add_reporter_print, add_reporter_null
187
reporter = add_reporter_null
222
takes_options = ['no-recurse', 'dry-run', 'verbose']
224
def run(self, file_list, no_recurse=False, dry_run=False, verbose=False):
229
# This is pointless, but I'd rather not raise an error
230
action = bzrlib.add.add_action_null
232
action = bzrlib.add.add_action_print
234
action = bzrlib.add.add_action_add
189
reporter = add_reporter_print
190
smart_add(file_list, not no_recurse, reporter)
236
action = bzrlib.add.add_action_add_and_print
238
added, ignored = bzrlib.add.smart_add(file_list, not no_recurse,
241
for glob in sorted(ignored.keys()):
242
match_len = len(ignored[glob])
244
for path in ignored[glob]:
245
print "ignored %s matching \"%s\"" % (path, glob)
247
print "ignored %d file(s) matching \"%s\"" % (match_len,
249
print "If you wish to add some of these files, please add them"\
193
253
class cmd_mkdir(Command):
213
270
takes_args = ['filename']
216
274
def run(self, filename):
217
print Branch.open_containing(filename).relpath(filename)
275
tree, relpath = WorkingTree.open_containing(filename)
221
279
class cmd_inventory(Command):
222
"""Show inventory of the current working copy or a revision."""
223
takes_options = ['revision', 'show-ids']
280
"""Show inventory of the current working copy or a revision.
282
It is possible to limit the output to a particular entry
283
type using the --kind option. For example; --kind file.
285
takes_options = ['revision', 'show-ids', 'kind']
225
def run(self, revision=None, show_ids=False):
226
b = Branch.open_containing('.')
288
def run(self, revision=None, show_ids=False, kind=None):
289
if kind and kind not in ['file', 'directory', 'symlink']:
290
raise BzrCommandError('invalid kind specified')
291
tree = WorkingTree.open_containing(u'.')[0]
227
292
if revision is None:
228
inv = b.read_working_inventory()
293
inv = tree.read_working_inventory()
230
295
if len(revision) > 1:
231
296
raise BzrCommandError('bzr inventory --revision takes'
232
297
' exactly one revision identifier')
233
inv = b.get_revision_inventory(revision[0].in_history(b).rev_id)
298
inv = tree.branch.repository.get_revision_inventory(
299
revision[0].in_history(tree.branch).rev_id)
235
301
for path, entry in inv.entries():
302
if kind and kind != entry.kind:
237
305
print '%-50s %s' % (path, entry.file_id)
294
360
def run(self, names_list):
295
361
if len(names_list) < 2:
296
362
raise BzrCommandError("missing file argument")
297
b = Branch.open_containing(names_list[0])
299
rel_names = [b.relpath(x) for x in names_list]
363
tree, rel_names = tree_files(names_list)
301
365
if os.path.isdir(names_list[-1]):
302
366
# move into existing directory
303
for pair in b.move(rel_names[:-1], rel_names[-1]):
367
for pair in tree.move(rel_names[:-1], rel_names[-1]):
304
368
print "%s => %s" % pair
306
370
if len(names_list) != 2:
307
371
raise BzrCommandError('to mv multiple files the destination '
308
372
'must be a versioned directory')
309
b.rename_one(rel_names[0], rel_names[1])
373
tree.rename_one(rel_names[0], rel_names[1])
310
374
print "%s => %s" % (rel_names[0], rel_names[1])
315
377
class cmd_pull(Command):
316
378
"""Pull any changes from another branch into the current one.
318
If the location is omitted, the last-used location will be used.
319
Both the revision history and the working directory will be
380
If there is no default location set, the first pull will set it. After
381
that, you can omit the location to use the default. To change the
382
default, use --remember.
322
384
This command only works on branches that have not diverged. Branches are
323
385
considered diverged if both branches have had commits without first
324
386
pulling from the other.
326
388
If branches have diverged, you can use 'bzr merge' to pull the text changes
327
from one into the other.
389
from one into the other. Once one branch has merged, the other should
390
be able to pull it again.
392
If you want to forget your local changes and just update your branch to
393
match the remote one, use --overwrite.
329
takes_options = ['remember']
395
takes_options = ['remember', 'overwrite', 'verbose']
330
396
takes_args = ['location?']
332
def run(self, location=None, remember=False):
333
from bzrlib.merge import merge
398
def run(self, location=None, remember=False, overwrite=False, verbose=False):
335
399
from shutil import rmtree
338
br_to = Branch.open_containing('.')
339
stored_loc = br_to.get_parent()
401
# FIXME: too much stuff is in the command class
402
tree_to = WorkingTree.open_containing(u'.')[0]
403
stored_loc = tree_to.branch.get_parent()
340
404
if location is None:
341
405
if stored_loc is None:
342
406
raise BzrCommandError("No pull location known or specified.")
344
408
print "Using saved location: %s" % stored_loc
345
409
location = stored_loc
346
cache_root = tempfile.mkdtemp()
347
411
br_from = Branch.open(location)
350
br_from.setup_caching(cache_root)
351
location = br_from.base
352
old_revno = br_to.revno()
353
old_revision_history = br_to.revision_history()
412
br_to = tree_to.branch
414
old_rh = br_to.revision_history()
415
count = tree_to.pull(br_from, overwrite)
417
if br_to.get_parent() is None or remember:
418
br_to.set_parent(location)
419
note('%d revision(s) pulled.' % (count,))
422
new_rh = tree_to.branch.revision_history()
425
from bzrlib.log import show_changed_revisions
426
show_changed_revisions(tree_to.branch, old_rh, new_rh)
429
class cmd_push(Command):
430
"""Push this branch into another branch.
432
The remote branch will not have its working tree populated because this
433
is both expensive, and may not be supported on the remote file system.
435
Some smart servers or protocols *may* put the working tree in place.
437
If there is no default push location set, the first push will set it.
438
After that, you can omit the location to use the default. To change the
439
default, use --remember.
441
This command only works on branches that have not diverged. Branches are
442
considered diverged if the branch being pushed to is not an older version
445
If branches have diverged, you can use 'bzr push --overwrite' to replace
446
the other branch completely.
448
If you want to ensure you have the different changes in the other branch,
449
do a merge (see bzr help merge) from the other branch, and commit that
450
before doing a 'push --overwrite'.
452
takes_options = ['remember', 'overwrite',
453
Option('create-prefix',
454
help='Create the path leading up to the branch '
455
'if it does not already exist')]
456
takes_args = ['location?']
458
def run(self, location=None, remember=False, overwrite=False,
459
create_prefix=False, verbose=False):
460
# FIXME: Way too big! Put this into a function called from the
463
from shutil import rmtree
464
from bzrlib.transport import get_transport
466
tree_from = WorkingTree.open_containing(u'.')[0]
467
br_from = tree_from.branch
468
stored_loc = tree_from.branch.get_push_location()
470
if stored_loc is None:
471
raise BzrCommandError("No push location known or specified.")
473
print "Using saved location: %s" % stored_loc
474
location = stored_loc
476
br_to = Branch.open(location)
477
except NotBranchError:
479
transport = get_transport(location).clone('..')
480
if not create_prefix:
482
transport.mkdir(transport.relpath(location))
484
raise BzrCommandError("Parent directory of %s "
485
"does not exist." % location)
487
current = transport.base
488
needed = [(transport, transport.relpath(location))]
491
transport, relpath = needed[-1]
492
transport.mkdir(relpath)
495
new_transport = transport.clone('..')
496
needed.append((new_transport,
497
new_transport.relpath(transport.base)))
498
if new_transport.base == transport.base:
499
raise BzrCommandError("Could not creeate "
501
if isinstance(transport, LocalTransport):
502
br_to = WorkingTree.create_standalone(location).branch
504
br_to = Branch.create(location)
505
old_rh = br_to.revision_history()
355
br_to.update_revisions(br_from)
356
except DivergedBranches:
357
raise BzrCommandError("These branches have diverged."
359
new_revision_history = br_to.revision_history()
360
if new_revision_history != old_revision_history:
361
merge(('.', -1), ('.', old_revno), check_clean=False)
362
if stored_loc is None or remember:
363
br_to.set_parent(location)
508
tree_to = br_to.working_tree()
509
except NoWorkingTree:
510
# TODO: This should be updated for branches which don't have a
511
# working tree, as opposed to ones where we just couldn't
513
warning('Unable to update the working tree of: %s' % (br_to.base,))
514
count = br_to.pull(br_from, overwrite)
516
count = tree_to.pull(br_from, overwrite)
517
except DivergedBranches:
518
raise BzrCommandError("These branches have diverged."
519
" Try a merge then push with overwrite.")
520
if br_from.get_push_location() is None or remember:
521
br_from.set_push_location(location)
522
note('%d revision(s) pushed.' % (count,))
525
new_rh = br_to.revision_history()
528
from bzrlib.log import show_changed_revisions
529
show_changed_revisions(br_to, old_rh, new_rh)
370
532
class cmd_branch(Command):
592
770
takes_options = ['revision', 'diff-options']
593
771
aliases = ['di', 'dif']
595
774
def run(self, revision=None, file_list=None, diff_options=None):
596
775
from bzrlib.diff import show_diff
599
b = Branch.open_containing(file_list[0])
600
file_list = [b.relpath(f) for f in file_list]
601
if file_list == ['']:
602
# just pointing to top-of-tree
605
b = Branch.open_containing('.')
777
tree, file_list = internal_tree_files(file_list)
780
except FileInWrongBranch:
781
if len(file_list) != 2:
782
raise BzrCommandError("Files are in different branches")
784
b, file1 = Branch.open_containing(file_list[0])
785
b2, file2 = Branch.open_containing(file_list[1])
786
if file1 != "" or file2 != "":
787
# FIXME diff those two files. rbc 20051123
788
raise BzrCommandError("Files are in different branches")
607
790
if revision is not None:
608
if len(revision) == 1:
609
show_diff(b, revision[0], specific_files=file_list,
610
external_diff_options=diff_options)
792
raise BzrCommandError("Can't specify -r with two branches")
793
if (len(revision) == 1) or (revision[1].spec is None):
794
return show_diff(tree.branch, revision[0], specific_files=file_list,
795
external_diff_options=diff_options)
611
796
elif len(revision) == 2:
612
show_diff(b, revision[0], specific_files=file_list,
613
external_diff_options=diff_options,
614
revision2=revision[1])
797
return show_diff(tree.branch, revision[0], specific_files=file_list,
798
external_diff_options=diff_options,
799
revision2=revision[1])
616
801
raise BzrCommandError('bzr diff --revision takes exactly one or two revision identifiers')
618
show_diff(b, None, specific_files=file_list,
619
external_diff_options=diff_options)
804
return show_diff(b, None, specific_files=file_list,
805
external_diff_options=diff_options, b2=b2)
807
return show_diff(tree.branch, None, specific_files=file_list,
808
external_diff_options=diff_options)
624
811
class cmd_deleted(Command):
789
1006
# TODO: Take a revision or remote path and list that tree instead.
791
def run(self, revision=None, verbose=False):
792
b = Branch.open_containing('.')
794
tree = b.working_tree()
796
tree = b.revision_tree(revision.in_history(b).rev_id)
1008
takes_options = ['verbose', 'revision',
1009
Option('non-recursive',
1010
help='don\'t recurse into sub-directories'),
1012
help='Print all paths from the root of the branch.'),
1013
Option('unknown', help='Print unknown files'),
1014
Option('versioned', help='Print versioned files'),
1015
Option('ignored', help='Print ignored files'),
1017
Option('null', help='Null separate the files'),
1020
def run(self, revision=None, verbose=False,
1021
non_recursive=False, from_root=False,
1022
unknown=False, versioned=False, ignored=False,
1025
if verbose and null:
1026
raise BzrCommandError('Cannot set both --verbose and --null')
1027
all = not (unknown or versioned or ignored)
1029
selection = {'I':ignored, '?':unknown, 'V':versioned}
1031
tree, relpath = WorkingTree.open_containing(u'.')
1036
if revision is not None:
1037
tree = tree.branch.repository.revision_tree(
1038
revision[0].in_history(tree.branch).rev_id)
797
1039
for fp, fc, kind, fid, entry in tree.list_files():
799
kindch = entry.kind_character()
800
print '%-8s %s%s' % (fc, fp, kindch)
1040
if fp.startswith(relpath):
1041
fp = fp[len(relpath):]
1042
if non_recursive and '/' in fp:
1044
if not all and not selection[fc]:
1047
kindch = entry.kind_character()
1048
print '%-8s %s%s' % (fc, fp, kindch)
1050
sys.stdout.write(fp)
1051
sys.stdout.write('\0')
806
1057
class cmd_unknowns(Command):
807
1058
"""List unknown files."""
809
1061
from bzrlib.osutils import quotefn
810
for f in Branch.open_containing('.').unknowns():
1062
for f in WorkingTree.open_containing(u'.')[0].unknowns():
811
1063
print quotefn(f)
815
1066
class cmd_ignore(Command):
816
1067
"""Ignore a command or pattern.
914
1166
is found exports to a directory (equivalent to --format=dir).
916
1168
Root may be the top directory for tar, tgz and tbz2 formats. If none
917
is given, the top directory will be the root name of the file."""
918
# TODO: list known exporters
1169
is given, the top directory will be the root name of the file.
1171
Note: export of tree with non-ascii filenames to zip is not supported.
1173
Supported formats Autodetected by extension
1174
----------------- -------------------------
1177
tbz2 .tar.bz2, .tbz2
919
1181
takes_args = ['dest']
920
1182
takes_options = ['revision', 'format', 'root']
921
1183
def run(self, dest, revision=None, format=None, root=None):
923
b = Branch.open_containing('.')
1185
from bzrlib.export import export
1186
tree = WorkingTree.open_containing(u'.')[0]
924
1188
if revision is None:
1189
# should be tree.last_revision FIXME
925
1190
rev_id = b.last_revision()
927
1192
if len(revision) != 1:
928
1193
raise BzrError('bzr export --revision takes exactly 1 argument')
929
1194
rev_id = revision[0].in_history(b).rev_id
930
t = b.revision_tree(rev_id)
931
arg_root, ext = os.path.splitext(os.path.basename(dest))
932
if ext in ('.gz', '.bz2'):
933
new_root, new_ext = os.path.splitext(arg_root)
934
if new_ext == '.tar':
942
elif ext in (".tar.gz", ".tgz"):
944
elif ext in (".tar.bz2", ".tbz2"):
948
t.export(dest, format, root)
1195
t = b.repository.revision_tree(rev_id)
1197
export(t, dest, format, root)
1198
except errors.NoSuchExportFormat, e:
1199
raise BzrCommandError('Unsupported export format: %s' % e.format)
951
1202
class cmd_cat(Command):
987
1250
# TODO: Run hooks on tree to-be-committed, and after commit.
989
# TODO: Strict commit that fails if there are unknown or deleted files.
1252
# TODO: Strict commit that fails if there are deleted files.
1253
# (what does "deleted files" mean ??)
990
1255
# TODO: Give better message for -s, --summary, used by tla people
992
1257
# XXX: verbose currently does nothing
994
1259
takes_args = ['selected*']
995
takes_options = ['message', 'file', 'verbose', 'unchanged']
1260
takes_options = ['message', 'verbose',
1262
help='commit even if nothing has changed'),
1263
Option('file', type=str,
1265
help='file containing commit message'),
1267
help="refuse to commit if there are unknown "
1268
"files in the working tree."),
996
1270
aliases = ['ci', 'checkin']
998
1272
def run(self, message=None, file=None, verbose=True, selected_list=None,
1000
from bzrlib.errors import PointlessCommit, ConflictsInTree
1001
from bzrlib.msgeditor import edit_commit_message
1273
unchanged=False, strict=False):
1274
from bzrlib.errors import (PointlessCommit, ConflictsInTree,
1276
from bzrlib.msgeditor import edit_commit_message, \
1277
make_commit_message_template
1002
1278
from bzrlib.status import show_status
1003
from cStringIO import StringIO
1005
b = Branch.open_containing('.')
1007
selected_list = [b.relpath(s) for s in selected_list]
1279
from tempfile import TemporaryFile
1282
# TODO: Need a blackbox test for invoking the external editor; may be
1283
# slightly problematic to run this cross-platform.
1285
# TODO: do more checks that the commit will succeed before
1286
# spending the user's valuable time typing a commit message.
1288
# TODO: if the commit *does* happen to fail, then save the commit
1289
# message to a temporary file where it can be recovered
1290
tree, selected_list = tree_files(selected_list)
1010
1291
if message is None and not file:
1011
catcher = StringIO()
1012
show_status(b, specific_files=selected_list,
1014
message = edit_commit_message(catcher.getvalue())
1292
template = make_commit_message_template(tree, selected_list)
1293
message = edit_commit_message(template)
1016
1294
if message is None:
1017
1295
raise BzrCommandError("please specify a commit message"
1018
1296
" with either --message or --file")
1112
1417
This creates temporary test directories in the working directory,
1113
1418
but not existing data is affected. These directories are deleted
1114
1419
if the tests pass, or left behind to help in debugging if they
1420
fail and --keep-output is specified.
1117
1422
If arguments are given, they are regular expressions that say
1118
which tests should run."""
1423
which tests should run.
1425
If the global option '--no-plugins' is given, plugins are not loaded
1426
before running the selftests. This has two effects: features provided or
1427
modified by plugins will not be tested, and tests provided by plugins will
1432
bzr --no-plugins selftest -v
1119
1434
# TODO: --list should give a list of all available tests
1436
# NB: this is used from the class without creating an instance, which is
1437
# why it does not have a self parameter.
1438
def get_transport_type(typestring):
1439
"""Parse and return a transport specifier."""
1440
if typestring == "sftp":
1441
from bzrlib.transport.sftp import SFTPAbsoluteServer
1442
return SFTPAbsoluteServer
1443
if typestring == "memory":
1444
from bzrlib.transport.memory import MemoryServer
1446
msg = "No known transport type %s. Supported types are: sftp\n" %\
1448
raise BzrCommandError(msg)
1121
1451
takes_args = ['testspecs*']
1122
takes_options = ['verbose']
1123
def run(self, testspecs_list=None, verbose=False):
1452
takes_options = ['verbose',
1453
Option('one', help='stop when one test fails'),
1454
Option('keep-output',
1455
help='keep output directories when tests fail'),
1457
help='Use a different transport by default '
1458
'throughout the test suite.',
1459
type=get_transport_type),
1462
def run(self, testspecs_list=None, verbose=False, one=False,
1463
keep_output=False, transport=None):
1124
1464
import bzrlib.ui
1125
from bzrlib.selftest import selftest
1465
from bzrlib.tests import selftest
1126
1466
# we don't want progress meters from the tests to go to the
1127
1467
# real output; and we don't want log messages cluttering up
1128
1468
# the real logs.
1659
class cmd_remerge(Command):
1662
takes_args = ['file*']
1663
takes_options = ['merge-type', 'reprocess',
1664
Option('show-base', help="Show base revision text in "
1667
def run(self, file_list=None, merge_type=None, show_base=False,
1669
from bzrlib.merge import merge_inner, transform_tree
1670
from bzrlib._merge_core import ApplyMerge3
1671
if merge_type is None:
1672
merge_type = ApplyMerge3
1673
tree, file_list = tree_files(file_list)
1676
pending_merges = tree.pending_merges()
1677
if len(pending_merges) != 1:
1678
raise BzrCommandError("Sorry, remerge only works after normal"
1679
+ " merges. Not cherrypicking or"
1681
repository = tree.branch.repository
1682
base_revision = common_ancestor(tree.branch.last_revision(),
1683
pending_merges[0], repository)
1684
base_tree = repository.revision_tree(base_revision)
1685
other_tree = repository.revision_tree(pending_merges[0])
1686
interesting_ids = None
1687
if file_list is not None:
1688
interesting_ids = set()
1689
for filename in file_list:
1690
file_id = tree.path2id(filename)
1691
interesting_ids.add(file_id)
1692
if tree.kind(file_id) != "directory":
1695
for name, ie in tree.inventory.iter_entries(file_id):
1696
interesting_ids.add(ie.file_id)
1697
transform_tree(tree, tree.branch.basis_tree(), interesting_ids)
1698
if file_list is None:
1699
restore_files = list(tree.iter_conflicts())
1701
restore_files = file_list
1702
for filename in restore_files:
1704
restore(tree.abspath(filename))
1705
except NotConflicted:
1707
conflicts = merge_inner(tree.branch, other_tree, base_tree,
1708
interesting_ids = interesting_ids,
1709
other_rev_id=pending_merges[0],
1710
merge_type=merge_type,
1711
show_base=show_base,
1712
reprocess=reprocess)
1284
1720
class cmd_revert(Command):
1285
1721
"""Reverse all changes since the last commit.
1359
1794
def run(self, from_branch, to_branch):
1360
1795
from bzrlib.fetch import Fetcher
1361
1796
from bzrlib.branch import Branch
1362
from_b = Branch(from_branch)
1363
to_b = Branch(to_branch)
1797
from_b = Branch.open(from_branch)
1798
to_b = Branch.open(to_branch)
1364
1799
Fetcher(to_b, from_b)
1368
1802
class cmd_missing(Command):
1369
"""What is missing in this branch relative to other branch.
1371
# TODO: rewrite this in terms of ancestry so that it shows only
1374
takes_args = ['remote?']
1375
aliases = ['mis', 'miss']
1376
# We don't have to add quiet to the list, because
1377
# unknown options are parsed as booleans
1378
takes_options = ['verbose', 'quiet']
1380
def run(self, remote=None, verbose=False, quiet=False):
1381
from bzrlib.errors import BzrCommandError
1382
from bzrlib.missing import show_missing
1384
if verbose and quiet:
1385
raise BzrCommandError('Cannot pass both quiet and verbose')
1387
b = Branch.open_containing('.')
1388
parent = b.get_parent()
1803
"""Show unmerged/unpulled revisions between two branches.
1805
OTHER_BRANCH may be local or remote."""
1806
takes_args = ['other_branch?']
1807
takes_options = [Option('reverse', 'Reverse the order of revisions'),
1809
'Display changes in the local branch only'),
1810
Option('theirs-only',
1811
'Display changes in the remote branch only'),
1819
def run(self, other_branch=None, reverse=False, mine_only=False,
1820
theirs_only=False, long=True, short=False, line=False,
1821
show_ids=False, verbose=False):
1822
from bzrlib.missing import find_unmerged, iter_log_data
1823
from bzrlib.log import log_formatter
1824
local_branch = bzrlib.branch.Branch.open_containing(u".")[0]
1825
parent = local_branch.get_parent()
1826
if other_branch is None:
1827
other_branch = parent
1828
if other_branch is None:
1391
1829
raise BzrCommandError("No missing location known or specified.")
1394
print "Using last location: %s" % parent
1396
elif parent is None:
1397
# We only update parent if it did not exist, missing
1398
# should not change the parent
1399
b.set_parent(remote)
1400
br_remote = Branch.open_containing(remote)
1401
return show_missing(b, br_remote, verbose=verbose, quiet=quiet)
1830
print "Using last location: " + local_branch.get_parent()
1831
remote_branch = bzrlib.branch.Branch.open(other_branch)
1832
local_extra, remote_extra = find_unmerged(local_branch, remote_branch)
1833
log_format = get_log_format(long=long, short=short, line=line)
1834
lf = log_formatter(log_format, sys.stdout,
1836
show_timezone='original')
1837
if reverse is False:
1838
local_extra.reverse()
1839
remote_extra.reverse()
1840
if local_extra and not theirs_only:
1841
print "You have %d extra revision(s):" % len(local_extra)
1842
for data in iter_log_data(local_extra, local_branch.repository,
1845
printed_local = True
1847
printed_local = False
1848
if remote_extra and not mine_only:
1849
if printed_local is True:
1851
print "You are missing %d revision(s):" % len(remote_extra)
1852
for data in iter_log_data(remote_extra, remote_branch.repository,
1855
if not remote_extra and not local_extra:
1857
print "Branches are up to date."
1860
if parent is None and other_branch is not None:
1861
local_branch.set_parent(other_branch)
1404
1865
class cmd_plugins(Command):
1405
1866
"""List plugins"""
1408
1870
import bzrlib.plugin
1409
1871
from inspect import getdoc
1410
for plugin in bzrlib.plugin.all_plugins:
1872
for name, plugin in bzrlib.plugin.all_plugins().items():
1411
1873
if hasattr(plugin, '__path__'):
1412
1874
print plugin.__path__[0]
1413
1875
elif hasattr(plugin, '__file__'):
1445
1908
class cmd_annotate(Command):
1446
1909
"""Show the origin of each line in a file.
1448
This prints out the given file with an annotation on the
1449
left side indicating which revision, author and date introduced the
1911
This prints out the given file with an annotation on the left side
1912
indicating which revision, author and date introduced the change.
1914
If the origin is the same for a run of consecutive lines, it is
1915
shown only at the top, unless the --all option is given.
1452
1917
# TODO: annotate directories; showing when each file was last changed
1453
1918
# TODO: annotate a previous version of a file
1919
# TODO: if the working copy is modified, show annotations on that
1920
# with new uncommitted lines marked
1454
1921
aliases = ['blame', 'praise']
1455
1922
takes_args = ['filename']
1923
takes_options = [Option('all', help='show annotations on all lines'),
1924
Option('long', help='show date in annotations'),
1457
def run(self, filename):
1928
def run(self, filename, all=False, long=False):
1458
1929
from bzrlib.annotate import annotate_file
1459
b = Branch.open_containing(filename)
1930
tree, relpath = WorkingTree.open_containing(filename)
1931
branch = tree.branch
1462
rp = b.relpath(filename)
1463
tree = b.revision_tree(b.last_revision())
1464
file_id = tree.inventory.path2id(rp)
1934
file_id = tree.inventory.path2id(relpath)
1935
tree = branch.repository.revision_tree(branch.last_revision())
1465
1936
file_version = tree.inventory[file_id].revision
1466
annotate_file(b, file_version, file_id, sys.stdout)
1937
annotate_file(branch, file_version, file_id, long, all, sys.stdout)
1942
class cmd_re_sign(Command):
1943
"""Create a digital signature for an existing revision."""
1944
# TODO be able to replace existing ones.
1946
hidden = True # is this right ?
1947
takes_args = ['revision_id?']
1948
takes_options = ['revision']
1950
def run(self, revision_id=None, revision=None):
1951
import bzrlib.config as config
1952
import bzrlib.gpg as gpg
1953
if revision_id is not None and revision is not None:
1954
raise BzrCommandError('You can only supply one of revision_id or --revision')
1955
if revision_id is None and revision is None:
1956
raise BzrCommandError('You must supply either --revision or a revision_id')
1957
b = WorkingTree.open_containing(u'.')[0].branch
1958
gpg_strategy = gpg.GPGStrategy(config.BranchConfig(b))
1959
if revision_id is not None:
1960
b.repository.sign_revision(revision_id, gpg_strategy)
1961
elif revision is not None:
1962
if len(revision) == 1:
1963
revno, rev_id = revision[0].in_history(b)
1964
b.repository.sign_revision(rev_id, gpg_strategy)
1965
elif len(revision) == 2:
1966
# are they both on rh- if so we can walk between them
1967
# might be nice to have a range helper for arbitrary
1968
# revision paths. hmm.
1969
from_revno, from_revid = revision[0].in_history(b)
1970
to_revno, to_revid = revision[1].in_history(b)
1971
if to_revid is None:
1972
to_revno = b.revno()
1973
if from_revno is None or to_revno is None:
1974
raise BzrCommandError('Cannot sign a range of non-revision-history revisions')
1975
for revno in range(from_revno, to_revno + 1):
1976
b.repository.sign_revision(b.get_rev_id(revno),
1979
raise BzrCommandError('Please supply either one revision, or a range.')
1982
class cmd_uncommit(bzrlib.commands.Command):
1983
"""Remove the last committed revision.
1985
By supplying the --all flag, it will not only remove the entry
1986
from revision_history, but also remove all of the entries in the
1989
--verbose will print out what is being removed.
1990
--dry-run will go through all the motions, but not actually
1993
In the future, uncommit will create a changeset, which can then
1996
TODO: jam 20060108 Add an option to allow uncommit to remove unreferenced
1997
information in 'branch-as-repostory' branches.
1998
TODO: jam 20060108 Add the ability for uncommit to remove unreferenced
1999
information in shared branches as well.
2001
takes_options = ['verbose', 'revision',
2002
Option('dry-run', help='Don\'t actually make changes'),
2003
Option('force', help='Say yes to all questions.')]
2004
takes_args = ['location?']
2007
def run(self, location=None,
2008
dry_run=False, verbose=False,
2009
revision=None, force=False):
2010
from bzrlib.branch import Branch
2011
from bzrlib.log import log_formatter
2013
from bzrlib.uncommit import uncommit
2015
if location is None:
2017
b, relpath = Branch.open_containing(location)
2019
if revision is None:
2021
rev_id = b.last_revision()
2023
revno, rev_id = revision[0].in_history(b)
2025
print 'No revisions to uncommit.'
2027
for r in range(revno, b.revno()+1):
2028
rev_id = b.get_rev_id(r)
2029
lf = log_formatter('short', to_file=sys.stdout,show_timezone='original')
2030
lf.show(r, b.repository.get_revision(rev_id), None)
2033
print 'Dry-run, pretending to remove the above revisions.'
2035
val = raw_input('Press <enter> to continue')
2037
print 'The above revision(s) will be removed.'
2039
val = raw_input('Are you sure [y/N]? ')
2040
if val.lower() not in ('y', 'yes'):
2044
uncommit(b, dry_run=dry_run, verbose=verbose,
2048
def merge(other_revision, base_revision,
2049
check_clean=True, ignore_zero=False,
2050
this_dir=None, backup_files=False, merge_type=ApplyMerge3,
2051
file_list=None, show_base=False, reprocess=False):
2052
"""Merge changes into a tree.
2055
list(path, revno) Base for three-way merge.
2056
If [None, None] then a base will be automatically determined.
2058
list(path, revno) Other revision for three-way merge.
2060
Directory to merge changes into; '.' by default.
2062
If true, this_dir must have no uncommitted changes before the
2064
ignore_zero - If true, suppress the "zero conflicts" message when
2065
there are no conflicts; should be set when doing something we expect
2066
to complete perfectly.
2067
file_list - If supplied, merge only changes to selected files.
2069
All available ancestors of other_revision and base_revision are
2070
automatically pulled into the branch.
2072
The revno may be -1 to indicate the last revision on the branch, which is
2075
This function is intended for use from the command line; programmatic
2076
clients might prefer to call merge.merge_inner(), which has less magic
2079
from bzrlib.merge import Merger, _MergeConflictHandler
2080
if this_dir is None:
2082
this_tree = WorkingTree.open_containing(this_dir)[0]
2083
if show_base and not merge_type is ApplyMerge3:
2084
raise BzrCommandError("Show-base is not supported for this merge"
2085
" type. %s" % merge_type)
2086
if reprocess and not merge_type is ApplyMerge3:
2087
raise BzrCommandError("Reprocess is not supported for this merge"
2088
" type. %s" % merge_type)
2089
if reprocess and show_base:
2090
raise BzrCommandError("Cannot reprocess and show base.")
2091
merger = Merger(this_tree.branch, this_tree=this_tree)
2092
merger.check_basis(check_clean)
2093
merger.set_other(other_revision)
2094
merger.set_base(base_revision)
2095
if merger.base_rev_id == merger.other_rev_id:
2096
note('Nothing to do.')
2098
merger.backup_files = backup_files
2099
merger.merge_type = merge_type
2100
merger.set_interesting_files(file_list)
2101
merger.show_base = show_base
2102
merger.reprocess = reprocess
2103
merger.conflict_handler = _MergeConflictHandler(merger.this_tree,
2106
ignore_zero=ignore_zero)
2107
conflicts = merger.do_merge()
2108
merger.set_pending()
1470
2112
# these get imported and then picked up by the scan for cmd_*
1471
2113
# TODO: Some more consistent way to split command definitions across files;
1472
2114
# we do need to load at least some information about them to know of
1474
from bzrlib.conflicts import cmd_resolve, cmd_conflicts
2116
from bzrlib.conflicts import cmd_resolve, cmd_conflicts, restore