123
122
def _get_one_revision_tree(command_name, revisions, branch=None, tree=None):
123
"""Get a revision tree. Not suitable for commands that change the tree.
125
Specifically, the basis tree in dirstate trees is coupled to the dirstate
126
and doing a commit/uncommit/pull will at best fail due to changing the
129
If tree is passed in, it should be already locked, for lifetime management
130
of the trees internal cached state.
124
132
if branch is None:
125
133
branch = tree.branch
126
134
if revisions is None:
450
458
except errors.NoWorkingTree:
451
459
raise errors.BzrCommandError("No working tree to remove")
452
460
except errors.NotLocalUrl:
453
raise errors.BzrCommandError("You cannot remove the working tree of a "
461
raise errors.BzrCommandError("You cannot remove the working tree"
456
changes = working.changes_from(working.basis_tree())
457
if changes.has_changed():
464
if (working.has_changes()):
458
465
raise errors.UncommittedChanges(working)
460
467
working_path = working.bzrdir.root_transport.base
461
468
branch_path = working.branch.bzrdir.root_transport.base
462
469
if working_path != branch_path:
463
raise errors.BzrCommandError("You cannot remove the working tree from "
464
"a lightweight checkout")
470
raise errors.BzrCommandError("You cannot remove the working tree"
471
" from a lightweight checkout")
466
473
d.destroy_workingtree()
475
482
_see_also = ['info']
476
483
takes_args = ['location?']
485
Option('tree', help='Show revno of working tree'),
479
def run(self, location=u'.'):
480
self.outf.write(str(Branch.open_containing(location)[0].revno()))
481
self.outf.write('\n')
489
def run(self, tree=False, location=u'.'):
492
wt = WorkingTree.open_containing(location)[0]
494
except (errors.NoWorkingTree, errors.NotLocalUrl):
495
raise errors.NoWorkingTree(location)
497
revid = wt.last_revision()
499
revno_t = wt.branch.revision_id_to_dotted_revno(revid)
500
except errors.NoSuchRevision:
502
revno = ".".join(str(n) for n in revno_t)
506
b = Branch.open_containing(location)[0]
513
self.outf.write(str(revno) + '\n')
484
516
class cmd_revision_info(Command):
529
Option('tree', help='Show revno of working tree'),
500
def run(self, revision=None, directory=u'.', revision_info_list=[]):
503
if revision is not None:
504
revs.extend(revision)
505
if revision_info_list is not None:
506
for rev in revision_info_list:
507
revs.append(RevisionSpec.from_string(rev))
509
b = Branch.open_containing(directory)[0]
512
revs.append(RevisionSpec.from_string('-1'))
515
revision_id = rev.as_revision_id(b)
517
revno = '%4d' % (b.revision_id_to_revno(revision_id))
518
except errors.NoSuchRevision:
519
dotted_map = b.get_revision_id_to_revno_map()
520
revno = '.'.join(str(i) for i in dotted_map[revision_id])
521
print '%s %s' % (revno, revision_id)
533
def run(self, revision=None, directory=u'.', tree=False,
534
revision_info_list=[]):
537
wt = WorkingTree.open_containing(directory)[0]
540
except (errors.NoWorkingTree, errors.NotLocalUrl):
542
b = Branch.open_containing(directory)[0]
546
if revision is not None:
547
revision_ids.extend(rev.as_revision_id(b) for rev in revision)
548
if revision_info_list is not None:
549
for rev_str in revision_info_list:
550
rev_spec = RevisionSpec.from_string(rev_str)
551
revision_ids.append(rev_spec.as_revision_id(b))
552
# No arguments supplied, default to the last revision
553
if len(revision_ids) == 0:
556
raise errors.NoWorkingTree(directory)
557
revision_ids.append(wt.last_revision())
559
revision_ids.append(b.last_revision())
563
for revision_id in revision_ids:
565
dotted_revno = b.revision_id_to_dotted_revno(revision_id)
566
revno = '.'.join(str(i) for i in dotted_revno)
567
except errors.NoSuchRevision:
569
maxlen = max(maxlen, len(revno))
570
revinfos.append([revno, revision_id])
578
self.outf.write('%*s %s\n' % (maxlen, ri[0], ri[1]))
524
581
class cmd_add(Command):
567
627
help='Lookup file ids from this tree.'),
569
629
encoding_type = 'replace'
570
_see_also = ['remove']
630
_see_also = ['remove', 'ignore']
572
632
def run(self, file_list, no_recurse=False, dry_run=False, verbose=False,
573
633
file_ids_from=None):
605
665
for path in ignored[glob]:
606
666
self.outf.write("ignored %s matching \"%s\"\n"
610
for glob, paths in ignored.items():
611
match_len += len(paths)
612
self.outf.write("ignored %d file(s).\n" % match_len)
613
self.outf.write("If you wish to add ignored files, "
614
"please add them explicitly by name. "
615
"(\"bzr ignored\" gives a list)\n")
618
670
class cmd_mkdir(Command):
764
816
raise errors.BzrCommandError('--after cannot be specified with'
766
818
work_tree, file_list = tree_files(names_list, default_branch='.')
767
work_tree.lock_write()
819
work_tree.lock_tree_write()
769
821
rename_map.RenameMap.guess_renames(work_tree, dry_run)
1044
1096
if directory is None:
1045
1097
directory = '.'
1046
1098
# Get the source branch
1047
tree, br_from = bzrdir.BzrDir.open_tree_or_branch(directory)
1100
_unused) = bzrdir.BzrDir.open_containing_tree_or_branch(directory)
1048
1101
if strict is None:
1049
strict = br_from.get_config().get_user_option('push_strict')
1050
if strict is not None:
1051
# FIXME: This should be better supported by config
1053
bools = dict(yes=True, no=False, on=True, off=False,
1054
true=True, false=False)
1056
strict = bools[strict.lower()]
1060
changes = tree.changes_from(tree.basis_tree())
1061
if changes.has_changed():
1062
raise errors.UncommittedChanges(tree)
1102
strict = br_from.get_config().get_user_option_as_bool('push_strict')
1103
if strict is None: strict = True # default value
1063
1104
# Get the tip's revision_id
1064
1105
revision = _get_one_revision('push', revision)
1065
1106
if revision is not None:
1066
1107
revision_id = revision.in_history(br_from).rev_id
1068
1109
revision_id = None
1110
if strict and tree is not None and revision_id is None:
1111
if (tree.has_changes()):
1112
raise errors.UncommittedChanges(
1113
tree, more='Use --no-strict to force the push.')
1114
if tree.last_revision() != tree.branch.last_revision():
1115
# The tree has lost sync with its branch, there is little
1116
# chance that the user is aware of it but he can still force
1117
# the push with --no-strict
1118
raise errors.OutOfDateTree(
1119
tree, more='Use --no-strict to force the push.')
1070
1121
# Get the stacked_on branch, if any
1071
1122
if stacked_on is not None:
1123
1174
help='Hard-link working tree files where possible.'),
1124
1175
Option('no-tree',
1125
1176
help="Create a branch without a working-tree."),
1178
help="Switch the checkout in the current directory "
1179
"to the new branch."),
1126
1180
Option('stacked',
1127
1181
help='Create a stacked branch referring to the source branch. '
1128
1182
'The new branch will depend on the availability of the source '
1129
1183
'branch for all operations.'),
1130
1184
Option('standalone',
1131
1185
help='Do not use a shared repository, even if available.'),
1186
Option('use-existing-dir',
1187
help='By default branch will fail if the target'
1188
' directory exists, but does not already'
1189
' have a control directory. This flag will'
1190
' allow branch to proceed.'),
1133
1192
aliases = ['get', 'clone']
1135
1194
def run(self, from_location, to_location=None, revision=None,
1136
hardlink=False, stacked=False, standalone=False, no_tree=False):
1195
hardlink=False, stacked=False, standalone=False, no_tree=False,
1196
use_existing_dir=False, switch=False):
1197
from bzrlib import switch as _mod_switch
1137
1198
from bzrlib.tag import _merge_tags_if_possible
1139
1199
accelerator_tree, br_from = bzrdir.BzrDir.open_tree_or_branch(
1141
1201
if (accelerator_tree is not None and
1158
1218
to_transport.mkdir('.')
1159
1219
except errors.FileExists:
1160
raise errors.BzrCommandError('Target directory "%s" already'
1161
' exists.' % to_location)
1220
if not use_existing_dir:
1221
raise errors.BzrCommandError('Target directory "%s" '
1222
'already exists.' % to_location)
1225
bzrdir.BzrDir.open_from_transport(to_transport)
1226
except errors.NotBranchError:
1229
raise errors.AlreadyBranchError(to_location)
1162
1230
except errors.NoSuchFile:
1163
1231
raise errors.BzrCommandError('Parent of "%s" does not exist.'
1187
1255
except (errors.NotStacked, errors.UnstackableBranchFormat,
1188
1256
errors.UnstackableRepositoryFormat), e:
1189
1257
note('Branched %d revision(s).' % branch.revno())
1259
# Switch to the new branch
1260
wt, _ = WorkingTree.open_containing('.')
1261
_mod_switch.switch(wt.bzrdir, branch)
1262
note('Switched to branch: %s',
1263
urlutils.unescape_for_display(branch.base, 'utf-8'))
1191
1265
br_from.unlock()
1409
1483
title='Deletion Strategy', value_switches=True, enum_switch=False,
1410
1484
safe='Only delete files if they can be'
1411
1485
' safely recovered (default).',
1412
keep="Don't delete any files.",
1486
keep='Delete from bzr but leave the working copy.',
1413
1487
force='Delete all the specified files, even if they can not be '
1414
1488
'recovered and even if they are non-empty directories.')]
1415
1489
aliases = ['rm', 'del']
1597
1671
lazy_registry=('bzrlib.bzrdir', 'format_registry'),
1598
1672
converter=lambda name: bzrdir.format_registry.make_bzrdir(name),
1599
1673
value_switches=True,
1600
title="Branch Format",
1674
title="Branch format",
1602
1676
Option('append-revisions-only',
1603
1677
help='Never change revnos or the existing log.'
1811
1885
@display_command
1812
1886
def run(self, revision=None, file_list=None, diff_options=None,
1813
1887
prefix=None, old=None, new=None, using=None):
1814
from bzrlib.diff import _get_trees_to_diff, show_diff_trees
1888
from bzrlib.diff import get_trees_and_branches_to_diff, show_diff_trees
1816
1890
if (prefix is None) or (prefix == '0'):
1817
1891
# diff -p0 format
1831
1905
raise errors.BzrCommandError('bzr diff --revision takes exactly'
1832
1906
' one or two revision specifiers')
1834
old_tree, new_tree, specific_files, extra_trees = \
1835
_get_trees_to_diff(file_list, revision, old, new,
1908
(old_tree, new_tree,
1909
old_branch, new_branch,
1910
specific_files, extra_trees) = get_trees_and_branches_to_diff(
1911
file_list, revision, old, new, apply_view=True)
1837
1912
return show_diff_trees(old_tree, new_tree, sys.stdout,
1838
1913
specific_files=specific_files,
1839
1914
external_diff_options=diff_options,
2396
2471
if path is None:
2401
2475
raise errors.BzrCommandError('cannot specify both --from-root'
2405
2478
tree, branch, relpath = bzrdir.BzrDir.open_containing_tree_or_branch(
2481
# Calculate the prefix to use
2485
prefix = relpath + '/'
2486
elif fs_path != '.':
2487
prefix = fs_path + '/'
2411
2489
if revision is not None or tree is None:
2412
2490
tree = _get_one_revision_tree('ls', revision, branch=branch)
2422
2500
tree.lock_read()
2424
for fp, fc, fkind, fid, entry in tree.list_files(include_root=False):
2425
if fp.startswith(relpath):
2426
rp = fp[len(relpath):]
2427
fp = osutils.pathjoin(prefix, rp)
2428
if not recursive and '/' in rp:
2430
if not all and not selection[fc]:
2432
if kind is not None and fkind != kind:
2436
views.check_path_in_view(tree, fp)
2437
except errors.FileOutsideView:
2439
kindch = entry.kind_character()
2440
outstring = fp + kindch
2441
ui.ui_factory.clear_term()
2443
outstring = '%-8s %s' % (fc, outstring)
2444
if show_ids and fid is not None:
2445
outstring = "%-50s %s" % (outstring, fid)
2446
self.outf.write(outstring + '\n')
2448
self.outf.write(fp + '\0')
2451
self.outf.write(fid)
2452
self.outf.write('\0')
2502
for fp, fc, fkind, fid, entry in tree.list_files(include_root=False,
2503
from_dir=relpath, recursive=recursive):
2504
# Apply additional masking
2505
if not all and not selection[fc]:
2507
if kind is not None and fkind != kind:
2512
fullpath = osutils.pathjoin(relpath, fp)
2515
views.check_path_in_view(tree, fullpath)
2516
except errors.FileOutsideView:
2521
fp = osutils.pathjoin(prefix, fp)
2522
kindch = entry.kind_character()
2523
outstring = fp + kindch
2524
ui.ui_factory.clear_term()
2526
outstring = '%-8s %s' % (fc, outstring)
2527
if show_ids and fid is not None:
2528
outstring = "%-50s %s" % (outstring, fid)
2529
self.outf.write(outstring + '\n')
2531
self.outf.write(fp + '\0')
2534
self.outf.write(fid)
2535
self.outf.write('\0')
2455
2539
if fid is not None:
2460
self.outf.write('%-50s %s\n' % (outstring, my_id))
2462
self.outf.write(outstring + '\n')
2543
self.outf.write('%-50s %s\n' % (outstring, my_id))
2545
self.outf.write(outstring + '\n')
2954
3037
raise errors.BzrCommandError("empty commit message specified")
2955
3038
return my_message
3040
# The API permits a commit with a filter of [] to mean 'select nothing'
3041
# but the command line should not do that.
3042
if not selected_list:
3043
selected_list = None
2958
3045
tree.commit(message_callback=get_message,
2959
3046
specific_files=selected_list,
2989
3076
The working tree and branch checks will only give output if a problem is
2990
3077
detected. The output fields of the repository check are:
2992
revisions: This is just the number of revisions checked. It doesn't
2994
versionedfiles: This is just the number of versionedfiles checked. It
2995
doesn't indicate a problem.
2996
unreferenced ancestors: Texts that are ancestors of other texts, but
2997
are not properly referenced by the revision ancestry. This is a
2998
subtle problem that Bazaar can work around.
2999
unique file texts: This is the total number of unique file contents
3000
seen in the checked revisions. It does not indicate a problem.
3001
repeated file texts: This is the total number of repeated texts seen
3002
in the checked revisions. Texts can be repeated when their file
3003
entries are modified, but the file contents are not. It does not
3080
This is just the number of revisions checked. It doesn't
3084
This is just the number of versionedfiles checked. It
3085
doesn't indicate a problem.
3087
unreferenced ancestors
3088
Texts that are ancestors of other texts, but
3089
are not properly referenced by the revision ancestry. This is a
3090
subtle problem that Bazaar can work around.
3093
This is the total number of unique file contents
3094
seen in the checked revisions. It does not indicate a problem.
3097
This is the total number of repeated texts seen
3098
in the checked revisions. Texts can be repeated when their file
3099
entries are modified, but the file contents are not. It does not
3006
3102
If no restrictions are specified, all Bazaar data that is found at the given
3007
3103
location will be checked.
3243
3339
Tests that need working space on disk use a common temporary directory,
3244
3340
typically inside $TMPDIR or /tmp.
3342
If you set BZR_TEST_PDB=1 when running selftest, failing tests will drop
3343
into a pdb postmortem session.
3247
3346
Run only tests relating to 'ignore'::
3331
3432
first=False, list_only=False,
3332
3433
randomize=None, exclude=None, strict=False,
3333
3434
load_list=None, debugflag=None, starting_with=None, subunit=False,
3435
parallel=None, lsprof_tests=False):
3335
3436
from bzrlib.tests import selftest
3336
3437
import bzrlib.benchmarks as benchmarks
3337
3438
from bzrlib.benchmarks import tree_creator
3371
3472
"transport": transport,
3372
3473
"test_suite_factory": test_suite_factory,
3373
3474
"lsprof_timed": lsprof_timed,
3475
"lsprof_tests": lsprof_tests,
3374
3476
"bench_history": benchfile,
3375
3477
"matching_tests_first": first,
3376
3478
"list_only": list_only,
3484
3586
merge refuses to run if there are any uncommitted changes, unless
3485
3587
--force is given.
3589
To select only some changes to merge, use "merge -i", which will prompt
3590
you to apply each diff hunk and file change, similar to "shelve".
3488
3593
To merge the latest revision from bzr.dev::
3527
3632
short_name='d',
3530
Option('preview', help='Instead of merging, show a diff of the merge.')
3635
Option('preview', help='Instead of merging, show a diff of the'
3637
Option('interactive', help='Select changes interactively.',
3533
3641
def run(self, location=None, revision=None, force=False,
3546
3655
verified = 'inapplicable'
3547
3656
tree = WorkingTree.open_containing(directory)[0]
3549
# die as quickly as possible if there are uncommitted changes
3551
3659
basis_tree = tree.revision_tree(tree.last_revision())
3552
3660
except errors.NoSuchRevision:
3553
3661
basis_tree = tree.basis_tree()
3663
# die as quickly as possible if there are uncommitted changes
3555
changes = tree.changes_from(basis_tree)
3556
if changes.has_changed():
3665
if tree.has_changes():
3557
3666
raise errors.UncommittedChanges(tree)
3559
3668
view_info = _get_view_info_for_change_reporter(tree)
3586
3695
if revision is not None and len(revision) > 0:
3587
3696
raise errors.BzrCommandError('Cannot use --uncommitted and'
3588
3697
' --revision at the same time.')
3589
location = self._select_branch_location(tree, location)[0]
3590
other_tree, other_path = WorkingTree.open_containing(location)
3591
merger = _mod_merge.Merger.from_uncommitted(tree, other_tree,
3698
merger = self.get_merger_from_uncommitted(tree, location, pb,
3593
3700
allow_pending = False
3594
if other_path != '':
3595
merger.interesting_files = [other_path]
3597
3702
if merger is None:
3598
3703
merger, allow_pending = self._get_merger_from_branch(tree,
3614
3719
merger.other_rev_id)
3615
3720
result.report(self.outf)
3617
merger.check_basis(False)
3722
if merger.this_basis is None:
3723
raise errors.BzrCommandError(
3724
"This branch has no commits."
3725
" (perhaps you would prefer 'bzr pull')")
3619
return self._do_preview(merger)
3727
return self._do_preview(merger, cleanups)
3729
return self._do_interactive(merger, cleanups)
3621
3731
return self._do_merge(merger, change_reporter, allow_pending,
3624
3734
for cleanup in reversed(cleanups):
3627
def _do_preview(self, merger):
3628
from bzrlib.diff import show_diff_trees
3737
def _get_preview(self, merger, cleanups):
3629
3738
tree_merger = merger.make_merger()
3630
3739
tt = tree_merger.make_preview_transform()
3632
result_tree = tt.get_preview_tree()
3633
show_diff_trees(merger.this_tree, result_tree, self.outf,
3634
old_label='', new_label='')
3740
cleanups.append(tt.finalize)
3741
result_tree = tt.get_preview_tree()
3744
def _do_preview(self, merger, cleanups):
3745
from bzrlib.diff import show_diff_trees
3746
result_tree = self._get_preview(merger, cleanups)
3747
show_diff_trees(merger.this_tree, result_tree, self.outf,
3748
old_label='', new_label='')
3638
3750
def _do_merge(self, merger, change_reporter, allow_pending, verified):
3639
3751
merger.change_reporter = change_reporter
3762
def _do_interactive(self, merger, cleanups):
3763
"""Perform an interactive merge.
3765
This works by generating a preview tree of the merge, then using
3766
Shelver to selectively remove the differences between the working tree
3767
and the preview tree.
3769
from bzrlib import shelf_ui
3770
result_tree = self._get_preview(merger, cleanups)
3771
writer = bzrlib.option.diff_writer_registry.get()
3772
shelver = shelf_ui.Shelver(merger.this_tree, result_tree, destroy=True,
3773
reporter=shelf_ui.ApplyReporter(),
3774
diff_writer=writer(sys.stdout))
3650
3777
def sanity_check_merger(self, merger):
3651
3778
if (merger.show_base and
3652
3779
not merger.merge_type is _mod_merge.Merge3Merger):
3687
3814
base_branch, base_path = Branch.open_containing(base_loc,
3688
3815
possible_transports)
3689
3816
# Find the revision ids
3690
if revision is None or len(revision) < 1 or revision[-1] is None:
3817
other_revision_id = None
3818
base_revision_id = None
3819
if revision is not None:
3820
if len(revision) >= 1:
3821
other_revision_id = revision[-1].as_revision_id(other_branch)
3822
if len(revision) == 2:
3823
base_revision_id = revision[0].as_revision_id(base_branch)
3824
if other_revision_id is None:
3691
3825
other_revision_id = _mod_revision.ensure_null(
3692
3826
other_branch.last_revision())
3694
other_revision_id = revision[-1].as_revision_id(other_branch)
3695
if (revision is not None and len(revision) == 2
3696
and revision[0] is not None):
3697
base_revision_id = revision[0].as_revision_id(base_branch)
3699
base_revision_id = None
3700
3827
# Remember where we merge from
3701
3828
if ((remember or tree.branch.get_submit_branch() is None) and
3702
3829
user_location is not None):
3711
3838
allow_pending = True
3712
3839
return merger, allow_pending
3841
def get_merger_from_uncommitted(self, tree, location, pb, cleanups):
3842
"""Get a merger for uncommitted changes.
3844
:param tree: The tree the merger should apply to.
3845
:param location: The location containing uncommitted changes.
3846
:param pb: The progress bar to use for showing progress.
3847
:param cleanups: A list of operations to perform to clean up the
3848
temporary directories, unfinalized objects, etc.
3850
location = self._select_branch_location(tree, location)[0]
3851
other_tree, other_path = WorkingTree.open_containing(location)
3852
merger = _mod_merge.Merger.from_uncommitted(tree, other_tree, pb)
3853
if other_path != '':
3854
merger.interesting_files = [other_path]
3714
3857
def _select_branch_location(self, tree, user_location, revision=None,
3716
3859
"""Select a branch location, according to possible inputs.
4829
4972
To use a specific mail program, set the mail_client configuration option.
4830
4973
(For Thunderbird 1.5, this works around some bugs.) Supported values for
4831
specific clients are "claws", "evolution", "kmail", "mutt", and
4832
"thunderbird"; generic options are "default", "editor", "emacsclient",
4833
"mapi", and "xdg-email". Plugins may also add supported clients.
4974
specific clients are "claws", "evolution", "kmail", "mail.app" (MacOS X's
4975
Mail.app), "mutt", and "thunderbird"; generic options are "default",
4976
"editor", "emacsclient", "mapi", and "xdg-email". Plugins may also add
4835
4979
If mail is being sent, a to address is required. This can be supplied
4836
4980
either on the commandline, by setting the submit_to configuration
4869
5013
help='Write merge directive to this file; '
4870
5014
'use - for stdout.',
5017
help='Refuse to send if there are uncommitted changes in'
5018
' the working tree, --no-strict disables the check.'),
4872
5019
Option('mail-to', help='Mail the request to this address.',
4876
5023
Option('body', help='Body for the email.', type=unicode),
4877
5024
RegistryOption('format',
4878
help='Use the specified output format.',
4879
lazy_registry=('bzrlib.send', 'format_registry'))
5025
help='Use the specified output format.',
5026
lazy_registry=('bzrlib.send', 'format_registry')),
4882
5029
def run(self, submit_branch=None, public_branch=None, no_bundle=False,
4883
5030
no_patch=False, revision=None, remember=False, output=None,
4884
format=None, mail_to=None, message=None, body=None, **kwargs):
5031
format=None, mail_to=None, message=None, body=None,
5032
strict=None, **kwargs):
4885
5033
from bzrlib.send import send
4886
5034
return send(submit_branch, revision, public_branch, remember,
4887
format, no_bundle, no_patch, output,
4888
kwargs.get('from', '.'), mail_to, message, body,
5035
format, no_bundle, no_patch, output,
5036
kwargs.get('from', '.'), mail_to, message, body,
4892
5041
class cmd_bundle_revisions(cmd_send):
4937
5086
Option('output', short_name='o', help='Write directive to this file.',
5089
help='Refuse to bundle revisions if there are uncommitted'
5090
' changes in the working tree, --no-strict disables the check.'),
4940
5092
RegistryOption('format',
4941
5093
help='Use the specified output format.',
4950
5102
def run(self, submit_branch=None, public_branch=None, no_bundle=False,
4951
5103
no_patch=False, revision=None, remember=False, output=None,
4952
format=None, **kwargs):
5104
format=None, strict=None, **kwargs):
4953
5105
if output is None:
4955
5107
from bzrlib.send import send
4956
5108
return send(submit_branch, revision, public_branch, remember,
4957
5109
format, no_bundle, no_patch, output,
4958
5110
kwargs.get('from', '.'), None, None, None,
5111
self.outf, strict=strict)
4962
5114
class cmd_tag(Command):
5135
5287
Option('bind-to', help='Branch to bind checkout to.', type=str),
5136
5288
Option('force',
5137
help='Perform reconfiguration even if local changes'
5289
help='Perform reconfiguration even if local changes'
5291
Option('stacked-on',
5292
help='Reconfigure a branch to be stacked on another branch.',
5296
help='Reconfigure a branch to be unstacked. This '
5297
'may require copying substantial data into it.',
5141
def run(self, location=None, target_type=None, bind_to=None, force=False):
5301
def run(self, location=None, target_type=None, bind_to=None, force=False,
5142
5304
directory = bzrdir.BzrDir.open(location)
5305
if stacked_on and unstacked:
5306
raise BzrCommandError("Can't use both --stacked-on and --unstacked")
5307
elif stacked_on is not None:
5308
reconfigure.ReconfigureStackedOn().apply(directory, stacked_on)
5310
reconfigure.ReconfigureUnstacked().apply(directory)
5311
# At the moment you can use --stacked-on and a different
5312
# reconfiguration shape at the same time; there seems no good reason
5143
5314
if target_type is None:
5144
raise errors.BzrCommandError('No target configuration specified')
5315
if stacked_on or unstacked:
5318
raise errors.BzrCommandError('No target configuration '
5145
5320
elif target_type == 'branch':
5146
5321
reconfiguration = reconfigure.Reconfigure.to_branch(directory)
5147
5322
elif target_type == 'tree':
5191
5366
takes_args = ['to_location']
5192
5367
takes_options = [Option('force',
5193
help='Switch even if local commits will be lost.')
5368
help='Switch even if local commits will be lost.'),
5369
Option('create-branch', short_name='b',
5370
help='Create the target branch from this one before'
5371
' switching to it.'),
5196
def run(self, to_location, force=False):
5374
def run(self, to_location, force=False, create_branch=False):
5197
5375
from bzrlib import switch
5198
5376
tree_location = '.'
5199
5377
control_dir = bzrdir.BzrDir.open_containing(tree_location)[0]
5201
5379
branch = control_dir.open_branch()
5202
5380
had_explicit_nick = branch.get_config().has_explicit_nickname()
5203
5381
except errors.NotBranchError:
5204
5383
had_explicit_nick = False
5206
to_branch = Branch.open(to_location)
5207
except errors.NotBranchError:
5208
this_url = self._get_branch_location(control_dir)
5209
to_branch = Branch.open(
5210
urlutils.join(this_url, '..', to_location))
5386
raise errors.BzrCommandError('cannot create branch without'
5388
if '/' not in to_location and '\\' not in to_location:
5389
# This path is meant to be relative to the existing branch
5390
this_url = self._get_branch_location(control_dir)
5391
to_location = urlutils.join(this_url, '..', to_location)
5392
to_branch = branch.bzrdir.sprout(to_location,
5393
possible_transports=[branch.bzrdir.root_transport],
5394
source_branch=branch).open_branch()
5396
# from_branch = control_dir.open_branch()
5397
# except errors.NotBranchError:
5398
# raise BzrCommandError('Cannot create a branch from this'
5399
# ' location when we cannot open this branch')
5400
# from_branch.bzrdir.sprout(
5404
to_branch = Branch.open(to_location)
5405
except errors.NotBranchError:
5406
this_url = self._get_branch_location(control_dir)
5407
to_branch = Branch.open(
5408
urlutils.join(this_url, '..', to_location))
5211
5409
switch.switch(control_dir, to_branch, force)
5212
5410
if had_explicit_nick:
5213
5411
branch = control_dir.open_branch() #get the new branch!
5456
5654
if writer is None:
5457
5655
writer = bzrlib.option.diff_writer_registry.get()
5459
Shelver.from_args(writer(sys.stdout), revision, all, file_list,
5460
message, destroy=destroy).run()
5657
shelver = Shelver.from_args(writer(sys.stdout), revision, all,
5658
file_list, message, destroy=destroy)
5662
shelver.work_tree.unlock()
5461
5663
except errors.UserAbort:
5503
5705
def run(self, shelf_id=None, action='apply'):
5504
5706
from bzrlib.shelf_ui import Unshelver
5505
Unshelver.from_args(shelf_id, action).run()
5707
unshelver = Unshelver.from_args(shelf_id, action)
5711
unshelver.tree.unlock()
5508
5714
class cmd_clean_tree(Command):