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)
1010
1024
names_list = []
1011
1025
if len(names_list) < 2:
1012
1026
raise errors.BzrCommandError(gettext("missing file argument"))
1013
tree, rel_names = WorkingTree.open_containing_paths(names_list, canonicalize=False)
1027
tree, rel_names = WorkingTree.open_containing_paths(
1028
names_list, canonicalize=False)
1014
1029
for file_name in rel_names[0:-1]:
1015
1030
if file_name == '':
1016
raise errors.BzrCommandError(gettext("can not move root of branch"))
1031
raise errors.BzrCommandError(
1032
gettext("can not move root of branch"))
1017
1033
self.add_cleanup(tree.lock_tree_write().unlock)
1018
1034
self._run(tree, names_list, rel_names, after)
1020
1036
def run_auto(self, names_list, after, dry_run):
1021
1037
if names_list is not None and len(names_list) > 1:
1022
raise errors.BzrCommandError(gettext('Only one path may be specified to'
1038
raise errors.BzrCommandError(
1039
gettext('Only one path may be specified to --auto.'))
1025
raise errors.BzrCommandError(gettext('--after cannot be specified with'
1041
raise errors.BzrCommandError(
1042
gettext('--after cannot be specified with --auto.'))
1027
1043
work_tree, file_list = WorkingTree.open_containing_paths(
1028
1044
names_list, default_directory='.')
1029
1045
self.add_cleanup(work_tree.lock_tree_write().unlock)
1030
1046
rename_map.RenameMap.guess_renames(
1031
work_tree.basis_tree(), work_tree, dry_run)
1047
work_tree.basis_tree(), work_tree, dry_run)
1033
1049
def _run(self, tree, names_list, rel_names, after):
1034
1050
into_existing = osutils.isdir(names_list[-1])
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):
1329
1347
from .push import _show_push_branch
1413
1431
_see_also = ['checkout']
1414
1432
takes_args = ['from_location', 'to_location?']
1415
1433
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."),
1435
'hardlink', help='Hard-link working tree files where possible.'),
1436
Option('files-from', type=text_type,
1437
help="Get file contents from this tree."),
1439
help="Create a branch without a working-tree."),
1441
help="Switch the checkout in the current directory "
1442
"to the new branch."),
1444
help='Create a stacked branch referring to the source branch. '
1445
'The new branch will depend on the availability of the source '
1446
'branch for all operations.'),
1447
Option('standalone',
1448
help='Do not use a shared repository, even if available.'),
1449
Option('use-existing-dir',
1450
help='By default branch will fail if the target'
1451
' directory exists, but does not already'
1452
' have a control directory. This flag will'
1453
' allow branch to proceed.'),
1455
help="Bind new branch to from location."),
1439
1458
def run(self, from_location, to_location=None, revision=None,
1440
1459
hardlink=False, stacked=False, standalone=False, no_tree=False,
1587
1612
class cmd_checkout(Command):
1588
1613
__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.
1615
If BRANCH_LOCATION is omitted, checkout will reconstitute a working tree
1616
for the branch found in '.'. This is useful if you have removed the working
1617
tree or if it was never created - i.e. if you pushed the branch to its
1618
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
1620
If the TO_LOCATION is omitted, the last component of the BRANCH_LOCATION
1621
will be used. In other words, "checkout ../foo/bar" will attempt to create
1622
./bar. If the BRANCH_LOCATION has no / or path separator embedded, the
1623
TO_LOCATION is derived from the BRANCH_LOCATION by stripping a leading
1624
scheme or drive identifier, if any. For example, "checkout lp:foo-bar" will
1625
attempt to create ./foo-bar.
1602
1627
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
1628
parameter, as in "checkout foo/bar -r 5". Note that this will be
1629
immediately out of date [so you cannot commit] but it may be useful (i.e.
1630
to examine old code.)
1608
1633
_see_also = ['checkouts', 'branch', 'working-trees', 'remove-tree']
1894
1919
file_list = sorted(missing, reverse=True)
1895
1920
file_deletion_strategy = 'keep'
1896
1921
tree.remove(file_list, verbose=verbose, to_file=self.outf,
1897
keep_files=file_deletion_strategy=='keep',
1898
force=(file_deletion_strategy=='no-backup'))
1901
class cmd_file_id(Command):
1902
__doc__ = """Print file_id of a particular file or directory.
1904
The file_id is assigned when the file is first added and remains the
1905
same through all revisions where the file exists, even when it is
1910
_see_also = ['inventory', 'ls']
1911
takes_args = ['filename']
1914
def run(self, filename):
1915
tree, relpath = WorkingTree.open_containing(filename)
1916
file_id = tree.path2id(relpath)
1918
raise errors.NotVersionedError(filename)
1920
self.outf.write(file_id.decode('utf-8') + '\n')
1923
class cmd_file_path(Command):
1924
__doc__ = """Print path of file_ids to a file or directory.
1926
This prints one line for each directory down to the target,
1927
starting at the branch root.
1931
takes_args = ['filename']
1934
def run(self, filename):
1935
tree, relpath = WorkingTree.open_containing(filename)
1936
fid = tree.path2id(relpath)
1938
raise errors.NotVersionedError(filename)
1939
segments = osutils.splitpath(relpath)
1940
for pos in range(1, len(segments) + 1):
1941
path = osutils.joinpath(segments[:pos])
1942
self.outf.write("%s\n" % tree.path2id(path))
1922
keep_files=file_deletion_strategy == 'keep',
1923
force=(file_deletion_strategy == 'no-backup'))
1945
1926
class cmd_reconcile(Command):
2642
2628
takes_args = ['file*']
2643
2629
_see_also = ['log-formats', 'revisionspec']
2644
2630
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',
2632
help='Show from oldest to newest.'),
2634
custom_help('verbose',
2635
help='Show files changed in each revision.'),
2639
type=breezy.option._parse_revision_str,
2641
help='Show just the specified revision.'
2642
' See also "help revisionspec".'),
2644
RegistryOption('authors',
2645
'What names to list as authors - first, all or committer.',
2648
'breezy.log', 'author_list_registry'),
2652
help='Number of levels to display - 0 for all, 1 for flat.',
2654
type=_parse_levels),
2656
help='Show revisions whose message matches this '
2657
'regular expression.',
2662
help='Limit the output to the first N revisions.',
2667
help='Show changes made in each revision as a patch.'),
2668
Option('include-merged',
2669
help='Show merged revisions like --levels 0 does.'),
2670
Option('include-merges', hidden=True,
2671
help='Historical alias for --include-merged.'),
2672
Option('omit-merges',
2673
help='Do not report commits with more than one parent.'),
2674
Option('exclude-common-ancestry',
2675
help='Display only the revisions that are not part'
2676
' of both ancestries (require -rX..Y).'
2678
Option('signatures',
2679
help='Show digital signature validity.'),
2682
help='Show revisions whose properties match this '
2685
ListOption('match-message',
2686
help='Show revisions whose message matches this '
2689
ListOption('match-committer',
2703
2690
help='Show revisions whose committer matches this '
2706
ListOption('match-author',
2693
ListOption('match-author',
2707
2694
help='Show revisions whose authors match this '
2710
ListOption('match-bugs',
2697
ListOption('match-bugs',
2711
2698
help='Show revisions whose bugs match this '
2715
2702
encoding_type = 'replace'
2717
2704
@display_command
2959
2948
_see_also = ['status', 'cat']
2960
2949
takes_args = ['path?']
2961
2950
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, directory, symlink.',
2953
Option('recursive', short_name='R',
2954
help='Recurse into subdirectories.'),
2956
help='Print paths relative to the root of the branch.'),
2957
Option('unknown', short_name='u',
2958
help='Print unknown files.'),
2959
Option('versioned', help='Print versioned files.',
2961
Option('ignored', short_name='i',
2962
help='Print ignored files.'),
2963
Option('kind', short_name='k',
2964
help=('List entries of a particular kind: file, '
2965
'directory, symlink, tree-reference.'),
2981
2972
@display_command
2982
2973
def run(self, revision=None, verbose=False,
2983
2974
recursive=False, from_root=False,
3387
3381
name_from_revision, filters)
3389
3383
def _run(self, tree, b, relpath, filename, revision, name_from_revision,
3392
3386
if tree is None:
3393
3387
tree = b.basis_tree()
3394
3388
rev_tree = _get_one_revision_tree('cat', revision, branch=b)
3395
3389
self.add_cleanup(rev_tree.lock_read().unlock)
3397
old_file_id = rev_tree.path2id(relpath)
3399
# TODO: Split out this code to something that generically finds the
3400
# best id for a path across one or more trees; it's like
3401
# find_ids_across_trees but restricted to find just one. -- mbp
3403
3391
if name_from_revision:
3404
3392
# Try in revision if requested
3405
if old_file_id is None:
3393
if not rev_tree.is_versioned(relpath):
3406
3394
raise errors.BzrCommandError(gettext(
3407
3395
"{0!r} is not present in revision {1}").format(
3408
3396
filename, rev_tree.get_revision_id()))
3410
actual_file_id = old_file_id
3397
rev_tree_path = relpath
3412
cur_file_id = tree.path2id(relpath)
3413
if cur_file_id is not None and rev_tree.has_id(cur_file_id):
3414
actual_file_id = cur_file_id
3415
elif old_file_id is not None:
3416
actual_file_id = old_file_id
3418
raise errors.BzrCommandError(gettext(
3419
"{0!r} is not present in revision {1}").format(
3420
filename, rev_tree.get_revision_id()))
3421
relpath = rev_tree.id2path(actual_file_id)
3400
rev_tree_path = _mod_tree.find_previous_path(
3401
tree, rev_tree, relpath)
3402
except errors.NoSuchFile:
3403
rev_tree_path = None
3405
if rev_tree_path is None:
3406
# Path didn't exist in working tree
3407
if not rev_tree.is_versioned(relpath):
3408
raise errors.BzrCommandError(gettext(
3409
"{0!r} is not present in revision {1}").format(
3410
filename, rev_tree.get_revision_id()))
3412
# Fall back to the same path in the basis tree, if present.
3413
rev_tree_path = relpath
3423
3416
from .filter_tree import ContentFilterTree
3424
filter_tree = ContentFilterTree(rev_tree,
3425
rev_tree._content_filter_stack)
3426
fileobj = filter_tree.get_file(relpath, actual_file_id)
3417
filter_tree = ContentFilterTree(
3418
rev_tree, rev_tree._content_filter_stack)
3419
fileobj = filter_tree.get_file(rev_tree_path)
3428
fileobj = rev_tree.get_file(relpath, actual_file_id)
3421
fileobj = rev_tree.get_file(rev_tree_path)
3429
3422
shutil.copyfileobj(fileobj, self.outf)
3430
3423
self.cleanup_now()
3499
3492
_see_also = ['add', 'bugs', 'hooks', 'uncommit']
3500
3493
takes_args = ['selected*']
3501
3494
takes_options = [
3502
ListOption('exclude', type=text_type, short_name='x',
3503
help="Do not consider changes made to a given path."),
3504
Option('message', type=text_type,
3506
help="Description of the new revision."),
3509
help='Commit even if nothing has changed.'),
3510
Option('file', type=text_type,
3513
help='Take commit message from this file.'),
3515
help="Refuse to commit if there are unknown "
3516
"files in the working tree."),
3517
Option('commit-time', type=text_type,
3518
help="Manually set a commit time using commit date "
3519
"format, e.g. '2009-10-10 08:00:00 +0100'."),
3520
ListOption('fixes', type=text_type,
3521
help="Mark a bug as being fixed by this revision "
3522
"(see \"brz help bugs\")."),
3523
ListOption('author', type=text_type,
3524
help="Set the author's name, if it's different "
3525
"from the committer."),
3527
help="Perform a local commit in a bound "
3528
"branch. Local commits are not pushed to "
3529
"the master branch until a normal commit "
3532
Option('show-diff', short_name='p',
3533
help='When no message is supplied, show the diff along'
3534
' with the status summary in the message editor.'),
3536
help='When committing to a foreign version control '
3537
'system do not push data that can not be natively '
3496
'exclude', type=text_type, short_name='x',
3497
help="Do not consider changes made to a given path."),
3498
Option('message', type=text_type,
3500
help="Description of the new revision."),
3503
help='Commit even if nothing has changed.'),
3504
Option('file', type=text_type,
3507
help='Take commit message from this file.'),
3509
help="Refuse to commit if there are unknown "
3510
"files in the working tree."),
3511
Option('commit-time', type=text_type,
3512
help="Manually set a commit time using commit date "
3513
"format, e.g. '2009-10-10 08:00:00 +0100'."),
3515
'bugs', type=text_type,
3516
help="Link to a related bug. (see \"brz help bugs\")."),
3518
'fixes', type=text_type,
3519
help="Mark a bug as being fixed by this revision "
3520
"(see \"brz help bugs\")."),
3522
'author', type=text_type,
3523
help="Set the author's name, if it's different "
3524
"from the committer."),
3526
help="Perform a local commit in a bound "
3527
"branch. Local commits are not pushed to "
3528
"the master branch until a normal commit "
3531
Option('show-diff', short_name='p',
3532
help='When no message is supplied, show the diff along'
3533
' with the status summary in the message editor.'),
3535
help='When committing to a foreign version control '
3536
'system do not push data that can not be natively '
3540
3538
aliases = ['ci', 'checkin']
3542
def _iter_bug_fix_urls(self, fixes, branch):
3543
default_bugtracker = None
3540
def _iter_bug_urls(self, bugs, branch, status):
3541
default_bugtracker = None
3544
3542
# Configure the properties for bug fixing attributes.
3545
for fixed_bug in fixes:
3546
tokens = fixed_bug.split(':')
3544
tokens = bug.split(':')
3547
3545
if len(tokens) == 1:
3548
3546
if default_bugtracker is None:
3549
3547
branch_config = branch.get_config_stack()
4433
4436
if location is not None:
4435
4438
mergeable = bundle.read_mergeable_from_url(location,
4436
possible_transports=possible_transports)
4439
possible_transports=possible_transports)
4437
4440
except errors.NotABundle:
4438
4441
mergeable = None
4440
4443
if uncommitted:
4441
4444
raise errors.BzrCommandError(gettext('Cannot use --uncommitted'
4442
' with bundles or merge directives.'))
4445
' with bundles or merge directives.'))
4444
4447
if revision is not None:
4445
4448
raise errors.BzrCommandError(gettext(
4446
4449
'Cannot use -r with merge directives or bundles'))
4447
4450
merger, verified = _mod_merge.Merger.from_mergeable(tree,
4450
4453
if merger is None and uncommitted:
4451
4454
if revision is not None and len(revision) > 0:
4452
4455
raise errors.BzrCommandError(gettext('Cannot use --uncommitted and'
4453
' --revision at the same time.'))
4456
' --revision at the same time.'))
4454
4457
merger = self.get_merger_from_uncommitted(tree, location, None)
4455
4458
allow_pending = False
4457
4460
if merger is None:
4458
4461
merger, allow_pending = self._get_merger_from_branch(tree,
4459
location, revision, remember, possible_transports, None)
4462
location, revision, remember, possible_transports, None)
4461
4464
merger.merge_type = merge_type
4462
4465
merger.reprocess = reprocess
4463
4466
merger.show_base = show_base
4464
4467
self.sanity_check_merger(merger)
4465
4468
if (merger.base_rev_id == merger.other_rev_id and
4466
merger.other_rev_id is not None):
4469
merger.other_rev_id is not None):
4467
4470
# check if location is a nonexistent file (and not a branch) to
4468
4471
# disambiguate the 'Nothing to do'
4469
4472
if merger.interesting_files:
4470
4473
if not merger.other_tree.has_filename(
4471
merger.interesting_files[0]):
4474
merger.interesting_files[0]):
4472
4475
note(gettext("merger: ") + str(merger))
4473
4476
raise errors.PathsDoNotExist([location])
4474
4477
note(gettext('Nothing to do.'))
4476
4479
if pull and not preview:
4477
4480
if merger.interesting_files is not None:
4478
raise errors.BzrCommandError(gettext('Cannot pull individual files'))
4481
raise errors.BzrCommandError(
4482
gettext('Cannot pull individual files'))
4479
4483
if (merger.base_rev_id == tree.last_revision()):
4480
4484
result = tree.pull(merger.other_branch, False,
4481
4485
merger.other_rev_id)
5216
5224
tree = _get_one_revision_tree('annotate', revision, branch=branch)
5217
5225
self.add_cleanup(tree.lock_read().unlock)
5218
5226
if wt is not None and revision is None:
5219
file_id = wt.path2id(relpath)
5221
file_id = tree.path2id(relpath)
5223
raise errors.NotVersionedError(filename)
5224
if wt is not None and revision is None:
5227
if not wt.is_versioned(relpath):
5228
raise errors.NotVersionedError(relpath)
5225
5229
# If there is a tree and we're not annotating historical
5226
5230
# versions, annotate the working tree's content.
5227
5231
annotate_file_tree(wt, relpath, self.outf, long, all,
5228
show_ids=show_ids, file_id=file_id)
5234
if not tree.is_versioned(relpath):
5235
raise errors.NotVersionedError(relpath)
5230
5236
annotate_file_tree(tree, relpath, self.outf, long, all,
5231
show_ids=show_ids, branch=branch, file_id=file_id)
5237
show_ids=show_ids, branch=branch)
5234
5240
class cmd_re_sign(Command):
5235
5241
__doc__ = """Create a digital signature for an existing revision."""
5236
5242
# TODO be able to replace existing ones.
5238
hidden = True # is this right ?
5244
hidden = True # is this right ?
5239
5245
takes_args = ['revision_id*']
5240
5246
takes_options = ['directory', 'revision']
5242
5248
def run(self, revision_id_list=None, revision=None, directory=u'.'):
5243
5249
if revision_id_list is not None and revision is not None:
5244
raise errors.BzrCommandError(gettext('You can only supply one of revision_id or --revision'))
5250
raise errors.BzrCommandError(
5251
gettext('You can only supply one of revision_id or --revision'))
5245
5252
if revision_id_list is None and revision is None:
5246
raise errors.BzrCommandError(gettext('You must supply either --revision or a revision_id'))
5253
raise errors.BzrCommandError(
5254
gettext('You must supply either --revision or a revision_id'))
5247
5255
b = WorkingTree.open_containing(directory)[0].branch
5248
5256
self.add_cleanup(b.lock_write().unlock)
5249
5257
return self._run(b, revision_id_list, revision)
6279
6287
if branch is None:
6280
6288
raise errors.BzrCommandError(
6281
6289
gettext('cannot create branch without source branch'))
6282
to_location = lookup_new_sibling_branch(control_dir, to_location,
6283
possible_transports=possible_transports)
6284
to_branch = branch.controldir.sprout(to_location,
6285
possible_transports=possible_transports,
6286
source_branch=branch).open_branch()
6290
to_location = lookup_new_sibling_branch(
6291
control_dir, to_location,
6292
possible_transports=possible_transports)
6293
if revision is not None:
6294
revision = revision.as_revision_id(branch)
6295
to_branch = branch.controldir.sprout(
6297
possible_transports=possible_transports,
6298
revision_id=revision,
6299
source_branch=branch).open_branch()
6289
6302
to_branch = Branch.open(to_location,
6290
possible_transports=possible_transports)
6303
possible_transports=possible_transports)
6291
6304
except errors.NotBranchError:
6292
to_branch = open_sibling_branch(control_dir, to_location,
6305
to_branch = open_sibling_branch(
6306
control_dir, to_location,
6293
6307
possible_transports=possible_transports)
6294
if revision is not None:
6295
revision = revision.as_revision_id(to_branch)
6308
if revision is not None:
6309
revision = revision.as_revision_id(to_branch)
6297
6311
switch.switch(control_dir, to_branch, force, revision_id=revision,
6298
6312
store_uncommitted=store)
6299
6313
except controldir.BranchReferenceLoop:
6300
6314
raise errors.BzrCommandError(
6301
gettext('switching would create a branch reference loop. '
6302
'Use the "bzr up" command to switch to a '
6303
'different revision.'))
6315
gettext('switching would create a branch reference loop. '
6316
'Use the "bzr up" command to switch to a '
6317
'different revision.'))
6304
6318
if had_explicit_nick:
6305
branch = control_dir.open_branch() #get the new branch!
6319
branch = control_dir.open_branch() # get the new branch!
6306
6320
branch.nick = to_branch.nick
6307
note(gettext('Switched to branch: %s'),
6308
urlutils.unescape_for_display(to_branch.base, 'utf-8'))
6322
if to_branch.controldir.control_url != control_dir.control_url:
6323
note(gettext('Switched to branch %s at %s'),
6324
to_branch.name, urlutils.unescape_for_display(to_branch.base, 'utf-8'))
6326
note(gettext('Switched to branch %s'), to_branch.name)
6328
note(gettext('Switched to branch at %s'),
6329
urlutils.unescape_for_display(to_branch.base, 'utf-8'))
6312
6332
class cmd_view(Command):
6800
6831
cmd_reconcile().run(".")
6834
class cmd_grep(Command):
6835
"""Print lines matching PATTERN for specified files and revisions.
6837
This command searches the specified files and revisions for a given
6838
pattern. The pattern is specified as a Python regular expressions[1].
6840
If the file name is not specified, the revisions starting with the
6841
current directory are searched recursively. If the revision number is
6842
not specified, the working copy is searched. To search the last committed
6843
revision, use the '-r -1' or '-r last:1' option.
6845
Unversioned files are not searched unless explicitly specified on the
6846
command line. Unversioned directores are not searched.
6848
When searching a pattern, the output is shown in the 'filepath:string'
6849
format. If a revision is explicitly searched, the output is shown as
6850
'filepath~N:string', where N is the revision number.
6852
--include and --exclude options can be used to search only (or exclude
6853
from search) files with base name matches the specified Unix style GLOB
6854
pattern. The GLOB pattern an use *, ?, and [...] as wildcards, and \\
6855
to quote wildcard or backslash character literally. Note that the glob
6856
pattern is not a regular expression.
6858
[1] http://docs.python.org/library/re.html#regular-expression-syntax
6861
encoding_type = 'replace'
6862
takes_args = ['pattern', 'path*']
6866
Option('color', type=text_type, argname='when',
6867
help='Show match in color. WHEN is never, always or auto.'),
6868
Option('diff', short_name='p',
6869
help='Grep for pattern in changeset for each revision.'),
6870
ListOption('exclude', type=text_type, argname='glob', short_name='X',
6871
help="Skip files whose base name matches GLOB."),
6872
ListOption('include', type=text_type, argname='glob', short_name='I',
6873
help="Search only files whose base name matches GLOB."),
6874
Option('files-with-matches', short_name='l',
6875
help='Print only the name of each input file in '
6876
'which PATTERN is found.'),
6877
Option('files-without-match', short_name='L',
6878
help='Print only the name of each input file in '
6879
'which PATTERN is not found.'),
6880
Option('fixed-string', short_name='F',
6881
help='Interpret PATTERN is a single fixed string (not regex).'),
6883
help='Search for pattern starting from the root of the branch. '
6884
'(implies --recursive)'),
6885
Option('ignore-case', short_name='i',
6886
help='Ignore case distinctions while matching.'),
6888
help='Number of levels to display - 0 for all, 1 for collapsed '
6891
type=_parse_levels),
6892
Option('line-number', short_name='n',
6893
help='Show 1-based line number.'),
6894
Option('no-recursive',
6895
help="Don't recurse into subdirectories. (default is --recursive)"),
6896
Option('null', short_name='Z',
6897
help='Write an ASCII NUL (\\0) separator '
6898
'between output lines rather than a newline.'),
6902
def run(self, verbose=False, ignore_case=False, no_recursive=False,
6903
from_root=False, null=False, levels=None, line_number=False,
6904
path_list=None, revision=None, pattern=None, include=None,
6905
exclude=None, fixed_string=False, files_with_matches=False,
6906
files_without_match=False, color=None, diff=False):
6907
from breezy import _termcolor
6910
if path_list is None:
6914
raise errors.BzrCommandError(
6915
'cannot specify both --from-root and PATH.')
6917
if files_with_matches and files_without_match:
6918
raise errors.BzrCommandError(
6919
'cannot specify both '
6920
'-l/--files-with-matches and -L/--files-without-matches.')
6922
global_config = _mod_config.GlobalConfig()
6925
color = global_config.get_user_option('grep_color')
6930
if color not in ['always', 'never', 'auto']:
6931
raise errors.BzrCommandError('Valid values for --color are '
6932
'"always", "never" or "auto".')
6938
if revision is not None or levels == 0:
6939
# print revision numbers as we may be showing multiple revisions
6946
if not ignore_case and grep.is_fixed_string(pattern):
6947
# if the pattern isalnum, implicitly use to -F for faster grep
6949
elif ignore_case and fixed_string:
6950
# GZ 2010-06-02: Fall back to regexp rather than lowercasing
6951
# pattern and text which will cause pain later
6952
fixed_string = False
6953
pattern = re.escape(pattern)
6956
re_flags = re.MULTILINE
6958
re_flags |= re.IGNORECASE
6960
if not fixed_string:
6961
patternc = grep.compile_pattern(
6962
pattern.encode(grep._user_encoding), re_flags)
6964
if color == 'always':
6966
elif color == 'never':
6968
elif color == 'auto':
6969
show_color = _termcolor.allow_color()
6971
opts = grep.GrepOptions()
6973
opts.verbose = verbose
6974
opts.ignore_case = ignore_case
6975
opts.no_recursive = no_recursive
6976
opts.from_root = from_root
6978
opts.levels = levels
6979
opts.line_number = line_number
6980
opts.path_list = path_list
6981
opts.revision = revision
6982
opts.pattern = pattern
6983
opts.include = include
6984
opts.exclude = exclude
6985
opts.fixed_string = fixed_string
6986
opts.files_with_matches = files_with_matches
6987
opts.files_without_match = files_without_match
6991
opts.eol_marker = eol_marker
6992
opts.print_revno = print_revno
6993
opts.patternc = patternc
6994
opts.recursive = not no_recursive
6995
opts.fixed_string = fixed_string
6996
opts.outf = self.outf
6997
opts.show_color = show_color
7001
# files_with_matches, files_without_match
7002
# levels(?), line_number, from_root
7004
# These are silently ignored.
7005
grep.grep_diff(opts)
7006
elif revision is None:
7007
grep.workingtree_grep(opts)
7009
grep.versioned_grep(opts)
6803
7012
def _register_lazy_builtins():
6804
7013
# register lazy builtins from other modules; called at startup and should
6805
7014
# be only called once.
6806
7015
for (name, aliases, module_name) in [
6807
('cmd_bisect', [], 'breezy.bisect'),
6808
('cmd_bundle_info', [], 'breezy.bundle.commands'),
6809
('cmd_config', [], 'breezy.config'),
6810
('cmd_dump_btree', [], 'breezy.bzr.debug_commands'),
6811
('cmd_version_info', [], 'breezy.cmd_version_info'),
6812
('cmd_resolve', ['resolved'], 'breezy.conflicts'),
6813
('cmd_conflicts', [], 'breezy.conflicts'),
6814
('cmd_ping', [], 'breezy.bzr.smart.ping'),
6815
('cmd_sign_my_commits', [], 'breezy.commit_signature_commands'),
6816
('cmd_verify_signatures', [], 'breezy.commit_signature_commands'),
6817
('cmd_test_script', [], 'breezy.cmd_test_script'),
7016
('cmd_bisect', [], 'breezy.bisect'),
7017
('cmd_bundle_info', [], 'breezy.bundle.commands'),
7018
('cmd_config', [], 'breezy.config'),
7019
('cmd_dump_btree', [], 'breezy.bzr.debug_commands'),
7020
('cmd_file_id', [], 'breezy.bzr.debug_commands'),
7021
('cmd_file_path', [], 'breezy.bzr.debug_commands'),
7022
('cmd_version_info', [], 'breezy.cmd_version_info'),
7023
('cmd_resolve', ['resolved'], 'breezy.conflicts'),
7024
('cmd_conflicts', [], 'breezy.conflicts'),
7025
('cmd_ping', [], 'breezy.bzr.smart.ping'),
7026
('cmd_sign_my_commits', [], 'breezy.commit_signature_commands'),
7027
('cmd_verify_signatures', [], 'breezy.commit_signature_commands'),
7028
('cmd_test_script', [], 'breezy.cmd_test_script'),
6819
7030
builtin_command_registry.register_lazy(name, aliases, module_name)