917
927
encoding_type = 'replace'
919
929
def run(self, names_list):
921
930
if names_list is None:
923
932
if len(names_list) < 2:
924
933
raise errors.BzrCommandError(gettext("missing file argument"))
925
tree, rel_names = WorkingTree.open_containing_paths(names_list, canonicalize=False)
934
tree, rel_names = WorkingTree.open_containing_paths(
935
names_list, canonicalize=False)
926
936
for file_name in rel_names[0:-1]:
927
937
if file_name == '':
928
raise errors.BzrCommandError(gettext("can not copy root of branch"))
938
raise errors.BzrCommandError(
939
gettext("can not copy root of branch"))
929
940
self.add_cleanup(tree.lock_tree_write().unlock)
930
941
into_existing = osutils.isdir(names_list[-1])
931
942
if not into_existing:
933
944
(src, dst) = rel_names
934
945
except IndexError:
935
raise errors.BzrCommandError(gettext('to copy multiple files the'
936
' destination must be a versioned'
946
raise errors.BzrCommandError(
947
gettext('to copy multiple files the'
948
' destination must be a versioned'
938
950
pairs = [(src, dst)]
940
pairs = [(n, osutils.joinpath([rel_names[-1], osutils.basename(n)]))
941
for n in rel_names[:-1]]
953
(n, osutils.joinpath([rel_names[-1], osutils.basename(n)]))
954
for n in rel_names[:-1]]
943
956
for src, dst in pairs:
945
958
src_kind = tree.stored_kind(src)
946
959
except errors.NoSuchFile:
947
960
raise errors.BzrCommandError(
948
gettext('Could not copy %s => %s: %s is not versioned.')
961
gettext('Could not copy %s => %s: %s is not versioned.')
950
963
if src_kind is None:
951
964
raise errors.BzrCommandError(
952
965
gettext('Could not copy %s => %s . %s is not versioned\\.'
954
967
if src_kind == 'directory':
955
968
raise errors.BzrCommandError(
956
969
gettext('Could not copy %s => %s . %s is a directory.'
958
971
dst_parent = osutils.split(dst)[0]
959
972
if dst_parent != '':
961
974
dst_parent_kind = tree.stored_kind(dst_parent)
962
975
except errors.NoSuchFile:
963
976
raise errors.BzrCommandError(
964
gettext('Could not copy %s => %s: %s is not versioned.')
965
% (src, dst, dst_parent))
977
gettext('Could not copy %s => %s: %s is not versioned.')
978
% (src, dst, dst_parent))
966
979
if dst_parent_kind != 'directory':
967
980
raise errors.BzrCommandError(
968
gettext('Could not copy to %s: %s is not a directory.')
969
% (dst_parent, dst_parent))
981
gettext('Could not copy to %s: %s is not a directory.')
982
% (dst_parent, dst_parent))
971
984
tree.copy_one(src, dst)
1289
1307
_see_also = ['pull', 'update', 'working-trees']
1290
1308
takes_options = ['remember', 'overwrite', 'verbose', 'revision',
1291
Option('create-prefix',
1292
help='Create the path leading up to the branch '
1293
'if it does not already exist.'),
1294
custom_help('directory',
1295
help='Branch to push from, '
1296
'rather than the one containing the working directory.'),
1297
Option('use-existing-dir',
1298
help='By default push will fail if the target'
1299
' directory exists, but does not already'
1300
' have a control directory. This flag will'
1301
' allow push to proceed.'),
1303
help='Create a stacked branch that references the public location '
1304
'of the parent branch.'),
1305
Option('stacked-on',
1306
help='Create a stacked branch that refers to another branch '
1307
'for the commit history. Only the work not present in the '
1308
'referenced branch is included in the branch created.',
1311
help='Refuse to push if there are uncommitted changes in'
1312
' the working tree, --no-strict disables the check.'),
1314
help="Don't populate the working tree, even for protocols"
1315
" that support it."),
1316
Option('overwrite-tags',
1317
help="Overwrite tags only."),
1318
Option('lossy', help="Allow lossy push, i.e. dropping metadata "
1319
"that can't be represented in the target.")
1309
Option('create-prefix',
1310
help='Create the path leading up to the branch '
1311
'if it does not already exist.'),
1312
custom_help('directory',
1313
help='Branch to push from, '
1314
'rather than the one containing the working directory.'),
1315
Option('use-existing-dir',
1316
help='By default push will fail if the target'
1317
' directory exists, but does not already'
1318
' have a control directory. This flag will'
1319
' allow push to proceed.'),
1321
help='Create a stacked branch that references the public location '
1322
'of the parent branch.'),
1323
Option('stacked-on',
1324
help='Create a stacked branch that refers to another branch '
1325
'for the commit history. Only the work not present in the '
1326
'referenced branch is included in the branch created.',
1329
help='Refuse to push if there are uncommitted changes in'
1330
' the working tree, --no-strict disables the check.'),
1332
help="Don't populate the working tree, even for protocols"
1333
" that support it."),
1334
Option('overwrite-tags',
1335
help="Overwrite tags only."),
1336
Option('lossy', help="Allow lossy push, i.e. dropping metadata "
1337
"that can't be represented in the target.")
1321
1339
takes_args = ['location?']
1322
1340
encoding_type = 'replace'
1324
1342
def run(self, location=None, remember=None, overwrite=False,
1325
create_prefix=False, verbose=False, revision=None,
1326
use_existing_dir=False, directory=None, stacked_on=None,
1327
stacked=False, strict=None, no_tree=False,
1328
overwrite_tags=False, lossy=False):
1343
create_prefix=False, verbose=False, revision=None,
1344
use_existing_dir=False, directory=None, stacked_on=None,
1345
stacked=False, strict=None, no_tree=False,
1346
overwrite_tags=False, lossy=False):
1347
from .location import location_to_url
1329
1348
from .push import _show_push_branch
1413
1433
_see_also = ['checkout']
1414
1434
takes_args = ['from_location', 'to_location?']
1415
1435
takes_options = ['revision',
1416
Option('hardlink', help='Hard-link working tree files where possible.'),
1417
Option('files-from', type=text_type,
1418
help="Get file contents from this tree."),
1420
help="Create a branch without a working-tree."),
1422
help="Switch the checkout in the current directory "
1423
"to the new branch."),
1425
help='Create a stacked branch referring to the source branch. '
1426
'The new branch will depend on the availability of the source '
1427
'branch for all operations.'),
1428
Option('standalone',
1429
help='Do not use a shared repository, even if available.'),
1430
Option('use-existing-dir',
1431
help='By default branch will fail if the target'
1432
' directory exists, but does not already'
1433
' have a control directory. This flag will'
1434
' allow branch to proceed.'),
1436
help="Bind new branch to from location."),
1437
'hardlink', help='Hard-link working tree files where possible.'),
1438
Option('files-from', type=text_type,
1439
help="Get file contents from this tree."),
1441
help="Create a branch without a working-tree."),
1443
help="Switch the checkout in the current directory "
1444
"to the new branch."),
1446
help='Create a stacked branch referring to the source branch. '
1447
'The new branch will depend on the availability of the source '
1448
'branch for all operations.'),
1449
Option('standalone',
1450
help='Do not use a shared repository, even if available.'),
1451
Option('use-existing-dir',
1452
help='By default branch will fail if the target'
1453
' directory exists, but does not already'
1454
' have a control directory. This flag will'
1455
' allow branch to proceed.'),
1457
help="Bind new branch to from location."),
1439
1460
def run(self, from_location, to_location=None, revision=None,
1440
1461
hardlink=False, stacked=False, standalone=False, no_tree=False,
1587
1614
class cmd_checkout(Command):
1588
1615
__doc__ = """Create a new checkout of an existing branch.
1590
If BRANCH_LOCATION is omitted, checkout will reconstitute a working tree for
1591
the branch found in '.'. This is useful if you have removed the working tree
1592
or if it was never created - i.e. if you pushed the branch to its current
1593
location using SFTP.
1617
If BRANCH_LOCATION is omitted, checkout will reconstitute a working tree
1618
for the branch found in '.'. This is useful if you have removed the working
1619
tree or if it was never created - i.e. if you pushed the branch to its
1620
current location using SFTP.
1595
If the TO_LOCATION is omitted, the last component of the BRANCH_LOCATION will
1596
be used. In other words, "checkout ../foo/bar" will attempt to create ./bar.
1597
If the BRANCH_LOCATION has no / or path separator embedded, the TO_LOCATION
1598
is derived from the BRANCH_LOCATION by stripping a leading scheme or drive
1599
identifier, if any. For example, "checkout lp:foo-bar" will attempt to
1622
If the TO_LOCATION is omitted, the last component of the BRANCH_LOCATION
1623
will be used. In other words, "checkout ../foo/bar" will attempt to create
1624
./bar. If the BRANCH_LOCATION has no / or path separator embedded, the
1625
TO_LOCATION is derived from the BRANCH_LOCATION by stripping a leading
1626
scheme or drive identifier, if any. For example, "checkout lp:foo-bar" will
1627
attempt to create ./foo-bar.
1602
1629
To retrieve the branch as of a particular revision, supply the --revision
1603
parameter, as in "checkout foo/bar -r 5". Note that this will be immediately
1604
out of date [so you cannot commit] but it may be useful (i.e. to examine old
1630
parameter, as in "checkout foo/bar -r 5". Note that this will be
1631
immediately out of date [so you cannot commit] but it may be useful (i.e.
1632
to examine old code.)
1608
1635
_see_also = ['checkouts', 'branch', 'working-trees', 'remove-tree']
1847
1873
class cmd_remove(Command):
1848
1874
__doc__ = """Remove files or directories.
1850
This makes Bazaar stop tracking changes to the specified files. Bazaar will
1876
This makes Breezy stop tracking changes to the specified files. Breezy will
1851
1877
delete them if they can easily be recovered using revert otherwise they
1852
1878
will be backed up (adding an extension of the form .~#~). If no options or
1853
parameters are given Bazaar will scan for files that are being tracked by
1854
Bazaar but missing in your tree and stop tracking them for you.
1879
parameters are given Breezy will scan for files that are being tracked by
1880
Breezy but missing in your tree and stop tracking them for you.
1856
1882
takes_args = ['file*']
1857
1883
takes_options = ['verbose',
1858
Option('new', help='Only remove files that have never been committed.'),
1859
RegistryOption.from_kwargs('file-deletion-strategy',
1860
'The file deletion mode to be used.',
1861
title='Deletion Strategy', value_switches=True, enum_switch=False,
1862
safe='Backup changed files (default).',
1863
keep='Delete from brz but leave the working copy.',
1864
no_backup='Don\'t backup changed files.'),
1885
'new', help='Only remove files that have never been committed.'),
1886
RegistryOption.from_kwargs('file-deletion-strategy',
1887
'The file deletion mode to be used.',
1888
title='Deletion Strategy', value_switches=True, enum_switch=False,
1889
safe='Backup changed files (default).',
1890
keep='Delete from brz but leave the working copy.',
1891
no_backup='Don\'t backup changed files.'),
1866
1893
aliases = ['rm', 'del']
1867
1894
encoding_type = 'replace'
1869
1896
def run(self, file_list, verbose=False, new=False,
1870
file_deletion_strategy='safe'):
1897
file_deletion_strategy='safe'):
1872
1899
tree, file_list = WorkingTree.open_containing_paths(file_list)
2642
2630
takes_args = ['file*']
2643
2631
_see_also = ['log-formats', 'revisionspec']
2644
2632
takes_options = [
2646
help='Show from oldest to newest.'),
2648
custom_help('verbose',
2649
help='Show files changed in each revision.'),
2653
type=breezy.option._parse_revision_str,
2655
help='Show just the specified revision.'
2656
' See also "help revisionspec".'),
2658
RegistryOption('authors',
2659
'What names to list as authors - first, all or committer.',
2661
lazy_registry=('breezy.log', 'author_list_registry'),
2665
help='Number of levels to display - 0 for all, 1 for flat.',
2667
type=_parse_levels),
2669
help='Show revisions whose message matches this '
2670
'regular expression.',
2675
help='Limit the output to the first N revisions.',
2680
help='Show changes made in each revision as a patch.'),
2681
Option('include-merged',
2682
help='Show merged revisions like --levels 0 does.'),
2683
Option('include-merges', hidden=True,
2684
help='Historical alias for --include-merged.'),
2685
Option('omit-merges',
2686
help='Do not report commits with more than one parent.'),
2687
Option('exclude-common-ancestry',
2688
help='Display only the revisions that are not part'
2689
' of both ancestries (require -rX..Y).'
2691
Option('signatures',
2692
help='Show digital signature validity.'),
2695
help='Show revisions whose properties match this '
2698
ListOption('match-message',
2699
help='Show revisions whose message matches this '
2702
ListOption('match-committer',
2634
help='Show from oldest to newest.'),
2636
custom_help('verbose',
2637
help='Show files changed in each revision.'),
2641
type=breezy.option._parse_revision_str,
2643
help='Show just the specified revision.'
2644
' See also "help revisionspec".'),
2646
RegistryOption('authors',
2647
'What names to list as authors - first, all or committer.',
2650
'breezy.log', 'author_list_registry'),
2654
help='Number of levels to display - 0 for all, 1 for flat.',
2656
type=_parse_levels),
2658
help='Show revisions whose message matches this '
2659
'regular expression.',
2664
help='Limit the output to the first N revisions.',
2669
help='Show changes made in each revision as a patch.'),
2670
Option('include-merged',
2671
help='Show merged revisions like --levels 0 does.'),
2672
Option('include-merges', hidden=True,
2673
help='Historical alias for --include-merged.'),
2674
Option('omit-merges',
2675
help='Do not report commits with more than one parent.'),
2676
Option('exclude-common-ancestry',
2677
help='Display only the revisions that are not part'
2678
' of both ancestries (require -rX..Y).'
2680
Option('signatures',
2681
help='Show digital signature validity.'),
2684
help='Show revisions whose properties match this '
2687
ListOption('match-message',
2688
help='Show revisions whose message matches this '
2691
ListOption('match-committer',
2703
2692
help='Show revisions whose committer matches this '
2706
ListOption('match-author',
2695
ListOption('match-author',
2707
2696
help='Show revisions whose authors match this '
2710
ListOption('match-bugs',
2699
ListOption('match-bugs',
2711
2700
help='Show revisions whose bugs match this '
2715
2704
encoding_type = 'replace'
2717
2706
@display_command
2959
2950
_see_also = ['status', 'cat']
2960
2951
takes_args = ['path?']
2961
2952
takes_options = [
2964
Option('recursive', short_name='R',
2965
help='Recurse into subdirectories.'),
2967
help='Print paths relative to the root of the branch.'),
2968
Option('unknown', short_name='u',
2969
help='Print unknown files.'),
2970
Option('versioned', help='Print versioned files.',
2972
Option('ignored', short_name='i',
2973
help='Print ignored files.'),
2974
Option('kind', short_name='k',
2975
help=('List entries of a particular kind: file, '
2976
'directory, symlink, tree-reference.'),
2955
Option('recursive', short_name='R',
2956
help='Recurse into subdirectories.'),
2958
help='Print paths relative to the root of the branch.'),
2959
Option('unknown', short_name='u',
2960
help='Print unknown files.'),
2961
Option('versioned', help='Print versioned files.',
2963
Option('ignored', short_name='i',
2964
help='Print ignored files.'),
2965
Option('kind', short_name='k',
2966
help=('List entries of a particular kind: file, '
2967
'directory, symlink, tree-reference.'),
2982
2974
@display_command
2983
2975
def run(self, revision=None, verbose=False,
2984
2976
recursive=False, from_root=False,
3388
3384
name_from_revision, filters)
3390
3386
def _run(self, tree, b, relpath, filename, revision, name_from_revision,
3393
3389
if tree is None:
3394
3390
tree = b.basis_tree()
3395
3391
rev_tree = _get_one_revision_tree('cat', revision, branch=b)
3396
3392
self.add_cleanup(rev_tree.lock_read().unlock)
3398
old_file_id = rev_tree.path2id(relpath)
3400
# TODO: Split out this code to something that generically finds the
3401
# best id for a path across one or more trees; it's like
3402
# find_ids_across_trees but restricted to find just one. -- mbp
3404
3394
if name_from_revision:
3405
3395
# Try in revision if requested
3406
if old_file_id is None:
3396
if not rev_tree.is_versioned(relpath):
3407
3397
raise errors.BzrCommandError(gettext(
3408
3398
"{0!r} is not present in revision {1}").format(
3409
3399
filename, rev_tree.get_revision_id()))
3411
actual_file_id = old_file_id
3400
rev_tree_path = relpath
3413
cur_file_id = tree.path2id(relpath)
3414
if cur_file_id is not None and rev_tree.has_id(cur_file_id):
3415
actual_file_id = cur_file_id
3416
elif old_file_id is not None:
3417
actual_file_id = old_file_id
3419
raise errors.BzrCommandError(gettext(
3420
"{0!r} is not present in revision {1}").format(
3421
filename, rev_tree.get_revision_id()))
3422
relpath = rev_tree.id2path(actual_file_id)
3403
rev_tree_path = _mod_tree.find_previous_path(
3404
tree, rev_tree, relpath)
3405
except errors.NoSuchFile:
3406
rev_tree_path = None
3408
if rev_tree_path is None:
3409
# Path didn't exist in working tree
3410
if not rev_tree.is_versioned(relpath):
3411
raise errors.BzrCommandError(gettext(
3412
"{0!r} is not present in revision {1}").format(
3413
filename, rev_tree.get_revision_id()))
3415
# Fall back to the same path in the basis tree, if present.
3416
rev_tree_path = relpath
3424
3419
from .filter_tree import ContentFilterTree
3425
filter_tree = ContentFilterTree(rev_tree,
3426
rev_tree._content_filter_stack)
3427
fileobj = filter_tree.get_file(relpath, actual_file_id)
3420
filter_tree = ContentFilterTree(
3421
rev_tree, rev_tree._content_filter_stack)
3422
fileobj = filter_tree.get_file(rev_tree_path)
3429
fileobj = rev_tree.get_file(relpath, actual_file_id)
3424
fileobj = rev_tree.get_file(rev_tree_path)
3430
3425
shutil.copyfileobj(fileobj, self.outf)
3431
3426
self.cleanup_now()
3500
3495
_see_also = ['add', 'bugs', 'hooks', 'uncommit']
3501
3496
takes_args = ['selected*']
3502
3497
takes_options = [
3503
ListOption('exclude', type=text_type, short_name='x',
3504
help="Do not consider changes made to a given path."),
3505
Option('message', type=text_type,
3507
help="Description of the new revision."),
3510
help='Commit even if nothing has changed.'),
3511
Option('file', type=text_type,
3514
help='Take commit message from this file.'),
3516
help="Refuse to commit if there are unknown "
3517
"files in the working tree."),
3518
Option('commit-time', type=text_type,
3519
help="Manually set a commit time using commit date "
3520
"format, e.g. '2009-10-10 08:00:00 +0100'."),
3521
ListOption('fixes', type=text_type,
3522
help="Mark a bug as being fixed by this revision "
3523
"(see \"brz help bugs\")."),
3524
ListOption('author', type=text_type,
3525
help="Set the author's name, if it's different "
3526
"from the committer."),
3528
help="Perform a local commit in a bound "
3529
"branch. Local commits are not pushed to "
3530
"the master branch until a normal commit "
3533
Option('show-diff', short_name='p',
3534
help='When no message is supplied, show the diff along'
3535
' with the status summary in the message editor.'),
3537
help='When committing to a foreign version control '
3538
'system do not push data that can not be natively '
3499
'exclude', type=text_type, short_name='x',
3500
help="Do not consider changes made to a given path."),
3501
Option('message', type=text_type,
3503
help="Description of the new revision."),
3506
help='Commit even if nothing has changed.'),
3507
Option('file', type=text_type,
3510
help='Take commit message from this file.'),
3512
help="Refuse to commit if there are unknown "
3513
"files in the working tree."),
3514
Option('commit-time', type=text_type,
3515
help="Manually set a commit time using commit date "
3516
"format, e.g. '2009-10-10 08:00:00 +0100'."),
3518
'bugs', type=text_type,
3519
help="Link to a related bug. (see \"brz help bugs\")."),
3521
'fixes', type=text_type,
3522
help="Mark a bug as being fixed by this revision "
3523
"(see \"brz help bugs\")."),
3525
'author', type=text_type,
3526
help="Set the author's name, if it's different "
3527
"from the committer."),
3529
help="Perform a local commit in a bound "
3530
"branch. Local commits are not pushed to "
3531
"the master branch until a normal commit "
3534
Option('show-diff', short_name='p',
3535
help='When no message is supplied, show the diff along'
3536
' with the status summary in the message editor.'),
3538
help='When committing to a foreign version control '
3539
'system do not push data that can not be natively '
3541
3541
aliases = ['ci', 'checkin']
3543
def _iter_bug_fix_urls(self, fixes, branch):
3544
default_bugtracker = None
3543
def _iter_bug_urls(self, bugs, branch, status):
3544
default_bugtracker = None
3545
3545
# Configure the properties for bug fixing attributes.
3546
for fixed_bug in fixes:
3547
tokens = fixed_bug.split(':')
3547
tokens = bug.split(':')
3548
3548
if len(tokens) == 1:
3549
3549
if default_bugtracker is None:
3550
3550
branch_config = branch.get_config_stack()
4429
4439
if location is not None:
4431
4441
mergeable = bundle.read_mergeable_from_url(location,
4432
possible_transports=possible_transports)
4442
possible_transports=possible_transports)
4433
4443
except errors.NotABundle:
4434
4444
mergeable = None
4436
4446
if uncommitted:
4437
4447
raise errors.BzrCommandError(gettext('Cannot use --uncommitted'
4438
' with bundles or merge directives.'))
4448
' with bundles or merge directives.'))
4440
4450
if revision is not None:
4441
4451
raise errors.BzrCommandError(gettext(
4442
4452
'Cannot use -r with merge directives or bundles'))
4443
4453
merger, verified = _mod_merge.Merger.from_mergeable(tree,
4446
4456
if merger is None and uncommitted:
4447
4457
if revision is not None and len(revision) > 0:
4448
4458
raise errors.BzrCommandError(gettext('Cannot use --uncommitted and'
4449
' --revision at the same time.'))
4459
' --revision at the same time.'))
4450
4460
merger = self.get_merger_from_uncommitted(tree, location, None)
4451
4461
allow_pending = False
4453
4463
if merger is None:
4454
4464
merger, allow_pending = self._get_merger_from_branch(tree,
4455
location, revision, remember, possible_transports, None)
4465
location, revision, remember, possible_transports, None)
4457
4467
merger.merge_type = merge_type
4458
4468
merger.reprocess = reprocess
4459
4469
merger.show_base = show_base
4460
4470
self.sanity_check_merger(merger)
4461
4471
if (merger.base_rev_id == merger.other_rev_id and
4462
merger.other_rev_id is not None):
4472
merger.other_rev_id is not None):
4463
4473
# check if location is a nonexistent file (and not a branch) to
4464
4474
# disambiguate the 'Nothing to do'
4465
4475
if merger.interesting_files:
4466
4476
if not merger.other_tree.has_filename(
4467
merger.interesting_files[0]):
4477
merger.interesting_files[0]):
4468
4478
note(gettext("merger: ") + str(merger))
4469
4479
raise errors.PathsDoNotExist([location])
4470
4480
note(gettext('Nothing to do.'))
4472
4482
if pull and not preview:
4473
4483
if merger.interesting_files is not None:
4474
raise errors.BzrCommandError(gettext('Cannot pull individual files'))
4484
raise errors.BzrCommandError(
4485
gettext('Cannot pull individual files'))
4475
4486
if (merger.base_rev_id == tree.last_revision()):
4476
4487
result = tree.pull(merger.other_branch, False,
4477
4488
merger.other_rev_id)
5212
5227
tree = _get_one_revision_tree('annotate', revision, branch=branch)
5213
5228
self.add_cleanup(tree.lock_read().unlock)
5214
5229
if wt is not None and revision is None:
5215
file_id = wt.path2id(relpath)
5217
file_id = tree.path2id(relpath)
5219
raise errors.NotVersionedError(filename)
5220
if wt is not None and revision is None:
5230
if not wt.is_versioned(relpath):
5231
raise errors.NotVersionedError(relpath)
5221
5232
# If there is a tree and we're not annotating historical
5222
5233
# versions, annotate the working tree's content.
5223
5234
annotate_file_tree(wt, relpath, self.outf, long, all,
5224
show_ids=show_ids, file_id=file_id)
5237
if not tree.is_versioned(relpath):
5238
raise errors.NotVersionedError(relpath)
5226
5239
annotate_file_tree(tree, relpath, self.outf, long, all,
5227
show_ids=show_ids, branch=branch, file_id=file_id)
5240
show_ids=show_ids, branch=branch)
5230
5243
class cmd_re_sign(Command):
5231
5244
__doc__ = """Create a digital signature for an existing revision."""
5232
5245
# TODO be able to replace existing ones.
5234
hidden = True # is this right ?
5247
hidden = True # is this right ?
5235
5248
takes_args = ['revision_id*']
5236
5249
takes_options = ['directory', 'revision']
5238
5251
def run(self, revision_id_list=None, revision=None, directory=u'.'):
5239
5252
if revision_id_list is not None and revision is not None:
5240
raise errors.BzrCommandError(gettext('You can only supply one of revision_id or --revision'))
5253
raise errors.BzrCommandError(
5254
gettext('You can only supply one of revision_id or --revision'))
5241
5255
if revision_id_list is None and revision is None:
5242
raise errors.BzrCommandError(gettext('You must supply either --revision or a revision_id'))
5256
raise errors.BzrCommandError(
5257
gettext('You must supply either --revision or a revision_id'))
5243
5258
b = WorkingTree.open_containing(directory)[0].branch
5244
5259
self.add_cleanup(b.lock_write().unlock)
5245
5260
return self._run(b, revision_id_list, revision)
6258
6279
if branch is None:
6259
6280
raise errors.BzrCommandError(
6260
6281
gettext('cannot create branch without source branch'))
6261
to_location = lookup_new_sibling_branch(control_dir, to_location,
6262
possible_transports=possible_transports)
6263
to_branch = branch.controldir.sprout(to_location,
6264
possible_transports=possible_transports,
6265
source_branch=branch).open_branch()
6282
to_location = lookup_new_sibling_branch(
6283
control_dir, to_location,
6284
possible_transports=possible_transports)
6285
if revision is not None:
6286
revision = revision.as_revision_id(branch)
6287
to_branch = branch.controldir.sprout(
6289
possible_transports=possible_transports,
6290
revision_id=revision,
6291
source_branch=branch).open_branch()
6268
6294
to_branch = Branch.open(to_location,
6269
possible_transports=possible_transports)
6295
possible_transports=possible_transports)
6270
6296
except errors.NotBranchError:
6271
to_branch = open_sibling_branch(control_dir, to_location,
6297
to_branch = open_sibling_branch(
6298
control_dir, to_location,
6272
6299
possible_transports=possible_transports)
6273
if revision is not None:
6274
revision = revision.as_revision_id(to_branch)
6300
if revision is not None:
6301
revision = revision.as_revision_id(to_branch)
6276
6303
switch.switch(control_dir, to_branch, force, revision_id=revision,
6277
6304
store_uncommitted=store)
6278
6305
except controldir.BranchReferenceLoop:
6279
6306
raise errors.BzrCommandError(
6280
gettext('switching would create a branch reference loop. '
6281
'Use the "bzr up" command to switch to a '
6282
'different revision.'))
6307
gettext('switching would create a branch reference loop. '
6308
'Use the "bzr up" command to switch to a '
6309
'different revision.'))
6283
6310
if had_explicit_nick:
6284
branch = control_dir.open_branch() #get the new branch!
6311
branch = control_dir.open_branch() # get the new branch!
6285
6312
branch.nick = to_branch.nick
6286
note(gettext('Switched to branch: %s'),
6287
urlutils.unescape_for_display(to_branch.base, 'utf-8'))
6314
if to_branch.controldir.control_url != control_dir.control_url:
6315
note(gettext('Switched to branch %s at %s'),
6316
to_branch.name, urlutils.unescape_for_display(to_branch.base, 'utf-8'))
6318
note(gettext('Switched to branch %s'), to_branch.name)
6320
note(gettext('Switched to branch at %s'),
6321
urlutils.unescape_for_display(to_branch.base, 'utf-8'))
6291
6324
class cmd_view(Command):
6783
6823
cmd_reconcile().run(".")
6826
class cmd_grep(Command):
6827
"""Print lines matching PATTERN for specified files and revisions.
6829
This command searches the specified files and revisions for a given
6830
pattern. The pattern is specified as a Python regular expressions[1].
6832
If the file name is not specified, the revisions starting with the
6833
current directory are searched recursively. If the revision number is
6834
not specified, the working copy is searched. To search the last committed
6835
revision, use the '-r -1' or '-r last:1' option.
6837
Unversioned files are not searched unless explicitly specified on the
6838
command line. Unversioned directores are not searched.
6840
When searching a pattern, the output is shown in the 'filepath:string'
6841
format. If a revision is explicitly searched, the output is shown as
6842
'filepath~N:string', where N is the revision number.
6844
--include and --exclude options can be used to search only (or exclude
6845
from search) files with base name matches the specified Unix style GLOB
6846
pattern. The GLOB pattern an use *, ?, and [...] as wildcards, and \\
6847
to quote wildcard or backslash character literally. Note that the glob
6848
pattern is not a regular expression.
6850
[1] http://docs.python.org/library/re.html#regular-expression-syntax
6853
encoding_type = 'replace'
6854
takes_args = ['pattern', 'path*']
6858
Option('color', type=text_type, argname='when',
6859
help='Show match in color. WHEN is never, always or auto.'),
6860
Option('diff', short_name='p',
6861
help='Grep for pattern in changeset for each revision.'),
6862
ListOption('exclude', type=text_type, argname='glob', short_name='X',
6863
help="Skip files whose base name matches GLOB."),
6864
ListOption('include', type=text_type, argname='glob', short_name='I',
6865
help="Search only files whose base name matches GLOB."),
6866
Option('files-with-matches', short_name='l',
6867
help='Print only the name of each input file in '
6868
'which PATTERN is found.'),
6869
Option('files-without-match', short_name='L',
6870
help='Print only the name of each input file in '
6871
'which PATTERN is not found.'),
6872
Option('fixed-string', short_name='F',
6873
help='Interpret PATTERN is a single fixed string (not regex).'),
6875
help='Search for pattern starting from the root of the branch. '
6876
'(implies --recursive)'),
6877
Option('ignore-case', short_name='i',
6878
help='Ignore case distinctions while matching.'),
6880
help='Number of levels to display - 0 for all, 1 for collapsed '
6883
type=_parse_levels),
6884
Option('line-number', short_name='n',
6885
help='Show 1-based line number.'),
6886
Option('no-recursive',
6887
help="Don't recurse into subdirectories. (default is --recursive)"),
6888
Option('null', short_name='Z',
6889
help='Write an ASCII NUL (\\0) separator '
6890
'between output lines rather than a newline.'),
6894
def run(self, verbose=False, ignore_case=False, no_recursive=False,
6895
from_root=False, null=False, levels=None, line_number=False,
6896
path_list=None, revision=None, pattern=None, include=None,
6897
exclude=None, fixed_string=False, files_with_matches=False,
6898
files_without_match=False, color=None, diff=False):
6899
from breezy import _termcolor
6902
if path_list is None:
6906
raise errors.BzrCommandError(
6907
'cannot specify both --from-root and PATH.')
6909
if files_with_matches and files_without_match:
6910
raise errors.BzrCommandError(
6911
'cannot specify both '
6912
'-l/--files-with-matches and -L/--files-without-matches.')
6914
global_config = _mod_config.GlobalConfig()
6917
color = global_config.get_user_option('grep_color')
6922
if color not in ['always', 'never', 'auto']:
6923
raise errors.BzrCommandError('Valid values for --color are '
6924
'"always", "never" or "auto".')
6930
if revision is not None or levels == 0:
6931
# print revision numbers as we may be showing multiple revisions
6938
if not ignore_case and grep.is_fixed_string(pattern):
6939
# if the pattern isalnum, implicitly use to -F for faster grep
6941
elif ignore_case and fixed_string:
6942
# GZ 2010-06-02: Fall back to regexp rather than lowercasing
6943
# pattern and text which will cause pain later
6944
fixed_string = False
6945
pattern = re.escape(pattern)
6948
re_flags = re.MULTILINE
6950
re_flags |= re.IGNORECASE
6952
if not fixed_string:
6953
patternc = grep.compile_pattern(
6954
pattern.encode(grep._user_encoding), re_flags)
6956
if color == 'always':
6958
elif color == 'never':
6960
elif color == 'auto':
6961
show_color = _termcolor.allow_color()
6963
opts = grep.GrepOptions()
6965
opts.verbose = verbose
6966
opts.ignore_case = ignore_case
6967
opts.no_recursive = no_recursive
6968
opts.from_root = from_root
6970
opts.levels = levels
6971
opts.line_number = line_number
6972
opts.path_list = path_list
6973
opts.revision = revision
6974
opts.pattern = pattern
6975
opts.include = include
6976
opts.exclude = exclude
6977
opts.fixed_string = fixed_string
6978
opts.files_with_matches = files_with_matches
6979
opts.files_without_match = files_without_match
6983
opts.eol_marker = eol_marker
6984
opts.print_revno = print_revno
6985
opts.patternc = patternc
6986
opts.recursive = not no_recursive
6987
opts.fixed_string = fixed_string
6988
opts.outf = self.outf
6989
opts.show_color = show_color
6993
# files_with_matches, files_without_match
6994
# levels(?), line_number, from_root
6996
# These are silently ignored.
6997
grep.grep_diff(opts)
6998
elif revision is None:
6999
grep.workingtree_grep(opts)
7001
grep.versioned_grep(opts)
7004
class cmd_resolve_location(Command):
7005
__doc__ = """Expand a location to a full URL.
7008
Look up a Launchpad URL.
7010
brz resolve-location lp:brz
7012
takes_args = ['location']
7015
def run(self, location):
7016
from .location import location_to_url
7017
url = location_to_url(location)
7018
display_url = urlutils.unescape_for_display(url, self.outf.encoding)
7019
self.outf.write('%s\n' % url)
6786
7022
def _register_lazy_builtins():
6787
7023
# register lazy builtins from other modules; called at startup and should
6788
7024
# be only called once.
6789
7025
for (name, aliases, module_name) in [
6790
('cmd_bisect', [], 'breezy.bisect'),
6791
('cmd_bundle_info', [], 'breezy.bundle.commands'),
6792
('cmd_config', [], 'breezy.config'),
6793
('cmd_dump_btree', [], 'breezy.bzr.debug_commands'),
6794
('cmd_version_info', [], 'breezy.cmd_version_info'),
6795
('cmd_resolve', ['resolved'], 'breezy.conflicts'),
6796
('cmd_conflicts', [], 'breezy.conflicts'),
6797
('cmd_ping', [], 'breezy.bzr.smart.ping'),
6798
('cmd_sign_my_commits', [], 'breezy.commit_signature_commands'),
6799
('cmd_verify_signatures', [], 'breezy.commit_signature_commands'),
6800
('cmd_test_script', [], 'breezy.cmd_test_script'),
7026
('cmd_bisect', [], 'breezy.bisect'),
7027
('cmd_bundle_info', [], 'breezy.bundle.commands'),
7028
('cmd_config', [], 'breezy.config'),
7029
('cmd_dump_btree', [], 'breezy.bzr.debug_commands'),
7030
('cmd_file_id', [], 'breezy.bzr.debug_commands'),
7031
('cmd_file_path', [], 'breezy.bzr.debug_commands'),
7032
('cmd_version_info', [], 'breezy.cmd_version_info'),
7033
('cmd_resolve', ['resolved'], 'breezy.conflicts'),
7034
('cmd_conflicts', [], 'breezy.conflicts'),
7035
('cmd_ping', [], 'breezy.bzr.smart.ping'),
7036
('cmd_sign_my_commits', [], 'breezy.commit_signature_commands'),
7037
('cmd_verify_signatures', [], 'breezy.commit_signature_commands'),
7038
('cmd_test_script', [], 'breezy.cmd_test_script'),
6802
7040
builtin_command_registry.register_lazy(name, aliases, module_name)