41
from bzrlib.branch import Branch, BranchReferenceFormat
42
from bzrlib.bundle import read_bundle_from_url
44
from bzrlib.branch import Branch
43
45
from bzrlib.bundle.apply_bundle import install_bundle, merge_bundle
44
46
from bzrlib.conflicts import ConflictList
47
from bzrlib.revision import common_ancestor
48
from bzrlib.revisionspec import RevisionSpec
49
from bzrlib.workingtree import WorkingTree
45
52
from bzrlib.commands import Command, display_command
46
from bzrlib.errors import (BzrError, BzrCheckError, BzrCommandError,
47
NotBranchError, DivergedBranches, NotConflicted,
48
NoSuchFile, NoWorkingTree, FileInWrongBranch,
49
NotVersionedError, NotABundle)
50
from bzrlib.merge import Merge3Merger
51
53
from bzrlib.option import Option
52
54
from bzrlib.progress import DummyProgress, ProgressPhase
53
from bzrlib.revision import common_ancestor
54
from bzrlib.revisionspec import RevisionSpec
55
55
from bzrlib.trace import mutter, note, log_error, warning, is_quiet, info
56
from bzrlib.transport.local import LocalTransport
58
from bzrlib.workingtree import WorkingTree
61
58
def tree_files(file_list, default_branch=u'.'):
63
60
return internal_tree_files(file_list, default_branch)
64
except FileInWrongBranch, e:
65
raise BzrCommandError("%s is not in the same branch as %s" %
66
(e.path, file_list[0]))
61
except errors.FileInWrongBranch, e:
62
raise errors.BzrCommandError("%s is not in the same branch as %s" %
63
(e.path, file_list[0]))
69
66
# XXX: Bad function name; should possibly also be a class method of
91
88
new_list.append(tree.relpath(filename))
92
89
except errors.PathNotChild:
93
raise FileInWrongBranch(tree.branch, filename)
90
raise errors.FileInWrongBranch(tree.branch, filename)
94
91
return tree, new_list
115
112
msg = "Unknown bzr format %s. Current formats are: default, knit,\n" \
116
113
"metaweave and weave" % typestring
117
raise BzrCommandError(msg)
114
raise errors.BzrCommandError(msg)
120
117
# TODO: Make sure no commands unconditionally use the working directory as a
195
192
def run(self, revision_id=None, revision=None):
197
194
if revision_id is not None and revision is not None:
198
raise BzrCommandError('You can only supply one of revision_id or --revision')
195
raise errors.BzrCommandError('You can only supply one of'
196
' revision_id or --revision')
199
197
if revision_id is None and revision is None:
200
raise BzrCommandError('You must supply either --revision or a revision_id')
198
raise errors.BzrCommandError('You must supply either'
199
' --revision or a revision_id')
201
200
b = WorkingTree.open_containing(u'.')[0].branch
203
202
# TODO: jam 20060112 should cat-revision always output utf-8?
206
205
elif revision is not None:
207
206
for rev in revision:
209
raise BzrCommandError('You cannot specify a NULL revision.')
208
raise errors.BzrCommandError('You cannot specify a NULL'
210
210
revno, rev_id = rev.in_history(b)
211
211
self.outf.write(b.repository.get_revision_xml(rev_id).decode('utf-8'))
242
242
for rev in revision_info_list:
243
243
revs.append(RevisionSpec.from_string(rev))
244
244
if len(revs) == 0:
245
raise BzrCommandError('You must supply a revision identifier')
245
raise errors.BzrCommandError('You must supply a revision identifier')
247
247
b = WorkingTree.open_containing(u'.')[0].branch
299
299
base_tree, base_path = WorkingTree.open_containing(
301
301
except errors.NoWorkingTree:
302
base_branch, base_path = branch.Branch.open_containing(
302
base_branch, base_path = Branch.open_containing(
304
304
base_tree = base_branch.basis_tree()
375
375
def run(self, revision=None, show_ids=False, kind=None, file_list=None):
376
376
if kind and kind not in ['file', 'directory', 'symlink']:
377
raise BzrCommandError('invalid kind specified')
377
raise errors.BzrCommandError('invalid kind specified')
379
379
work_tree, file_list = tree_files(file_list)
381
381
if revision is not None:
382
382
if len(revision) > 1:
383
raise BzrCommandError('bzr inventory --revision takes'
384
' exactly one revision identifier')
383
raise errors.BzrCommandError('bzr inventory --revision takes'
384
' exactly one revision identifier')
385
385
revision_id = revision[0].in_history(work_tree.branch).rev_id
386
386
tree = work_tree.branch.repository.revision_tree(revision_id)
397
397
if file_list is not None:
398
file_ids = bzrlib.tree.find_ids_across_trees(file_list, trees,
398
file_ids = _mod_tree.find_ids_across_trees(file_list, trees,
399
399
require_versioned=True)
400
400
# find_ids_across_trees may include some paths that don't
401
401
# exist in 'tree'.
439
439
if len(names_list) < 2:
440
raise BzrCommandError("missing file argument")
440
raise errors.BzrCommandError("missing file argument")
441
441
tree, rel_names = tree_files(names_list)
443
443
if os.path.isdir(names_list[-1]):
446
446
self.outf.write("%s => %s\n" % pair)
448
448
if len(names_list) != 2:
449
raise BzrCommandError('to mv multiple files the destination '
450
'must be a versioned directory')
449
raise errors.BzrCommandError('to mv multiple files the destination '
450
'must be a versioned directory')
451
451
tree.rename_one(rel_names[0], rel_names[1])
452
452
self.outf.write("%s => %s\n" % (rel_names[0], rel_names[1]))
489
489
if location is not None:
491
491
reader = bundle.read_bundle_from_url(location)
492
except errors.NotABundle:
493
493
pass # Continue on considering this url a Branch
495
495
stored_loc = branch_to.get_parent()
496
496
if location is None:
497
497
if stored_loc is None:
498
raise BzrCommandError("No pull location known or specified.")
498
raise errors.BzrCommandError("No pull location known or"
500
501
display_url = urlutils.unescape_for_display(stored_loc,
501
502
self.outf.encoding)
579
580
stored_loc = br_from.get_push_location()
580
581
if location is None:
581
582
if stored_loc is None:
582
raise BzrCommandError("No push location known or specified.")
583
raise errors.BzrCommandError("No push location known or specified.")
584
585
display_url = urlutils.unescape_for_display(stored_loc,
585
586
self.outf.encoding)
601
602
relurl = to_transport.relpath(location_url)
602
603
mutter('creating directory %s => %s', location_url, relurl)
603
604
to_transport.mkdir(relurl)
605
raise BzrCommandError("Parent directory of %s "
606
"does not exist." % location)
605
except errors.NoSuchFile:
606
raise errors.BzrCommandError("Parent directory of %s "
607
"does not exist." % location)
608
609
current = to_transport.base
609
610
needed = [(to_transport, to_transport.relpath(location_url))]
612
613
to_transport, relpath = needed[-1]
613
614
to_transport.mkdir(relpath)
616
except errors.NoSuchFile:
616
617
new_transport = to_transport.clone('..')
617
618
needed.append((new_transport,
618
619
new_transport.relpath(to_transport.base)))
619
620
if new_transport.base == to_transport.base:
620
raise BzrCommandError("Could not create "
621
raise errors.BzrCommandError("Could not create "
622
623
dir_to = br_from.bzrdir.clone(location_url,
623
624
revision_id=br_from.last_revision())
624
625
br_to = dir_to.open_branch()
639
640
warning('This transport does not update the working '
640
641
'tree of: %s' % (br_to.base,))
641
642
count = br_to.pull(br_from, overwrite)
642
except NoWorkingTree:
643
except errors.NoWorkingTree:
643
644
count = br_to.pull(br_from, overwrite)
645
646
count = tree_to.pull(br_from, overwrite)
646
except DivergedBranches:
647
raise BzrCommandError("These branches have diverged."
648
" Try a merge then push with overwrite.")
647
except errors.DivergedBranches:
648
raise errors.BzrCommandError('These branches have diverged.'
649
' Try using "merge" and then "push".')
649
650
note('%d revision(s) pushed.' % (count,))
678
679
if revision is None:
679
680
revision = [None]
680
681
elif len(revision) > 1:
681
raise BzrCommandError(
682
raise errors.BzrCommandError(
682
683
'bzr branch --revision takes exactly 1 revision value')
684
685
br_from = Branch.open(from_location)
685
686
except OSError, e:
686
687
if e.errno == errno.ENOENT:
687
raise BzrCommandError('Source location "%s" does not'
688
' exist.' % to_location)
688
raise errors.BzrCommandError('Source location "%s" does not'
689
' exist.' % to_location)
691
692
br_from.lock_read()
712
713
to_transport.mkdir('.')
713
714
except errors.FileExists:
714
raise BzrCommandError('Target directory "%s" already'
715
' exists.' % to_location)
715
raise errors.BzrCommandError('Target directory "%s" already'
716
' exists.' % to_location)
716
717
except errors.NoSuchFile:
717
raise BzrCommandError('Parent of "%s" does not exist.' %
718
raise errors.BzrCommandError('Parent of "%s" does not exist.'
720
721
# preserve whatever source format we have.
721
722
dir = br_from.bzrdir.sprout(to_transport.base,
724
725
except errors.NoSuchRevision:
725
726
to_transport.delete_tree('.')
726
727
msg = "The branch %s has no revision %s." % (from_location, revision[0])
727
raise BzrCommandError(msg)
728
raise errors.BzrCommandError(msg)
728
729
except errors.UnlistableBranch:
729
730
osutils.rmtree(to_location)
730
731
msg = "The branch %s cannot be used as a --basis" % (basis,)
731
raise BzrCommandError(msg)
732
raise errors.BzrCommandError(msg)
733
734
branch.control_files.put_utf8('branch-name', name)
734
735
note('Branched %d revision(s).' % branch.revno())
799
800
os.mkdir(to_location)
800
801
except OSError, e:
801
802
if e.errno == errno.EEXIST:
802
raise BzrCommandError('Target directory "%s" already'
803
' exists.' % to_location)
803
raise errors.BzrCommandError('Target directory "%s" already'
804
' exists.' % to_location)
804
805
if e.errno == errno.ENOENT:
805
raise BzrCommandError('Parent of "%s" does not exist.' %
806
raise errors.BzrCommandError('Parent of "%s" does not exist.'
809
810
old_format = bzrdir.BzrDirFormat.get_default_format()
826
827
def run(self, dir=u'.'):
827
from bzrlib.tree import find_renames
828
828
tree = WorkingTree.open_containing(dir)[0]
829
829
old_inv = tree.basis_tree().inventory
830
830
new_inv = tree.read_working_inventory()
831
renames = list(find_renames(old_inv, new_inv))
831
renames = list(_mod_tree.find_renames(old_inv, new_inv))
833
833
for old_name, new_name in renames:
834
834
self.outf.write("%s => %s\n" % (old_name, new_name))
913
913
tree, file_list = tree_files(file_list)
915
915
if file_list is None:
916
raise BzrCommandError('Specify one or more files to remove, or'
916
raise errors.BzrCommandError('Specify one or more files to'
917
' remove, or use --new.')
919
919
added = tree.changes_from(tree.basis_tree(),
920
920
specific_files=file_list).added
921
921
file_list = sorted([f[0] for f in added], reverse=True)
922
922
if len(file_list) == 0:
923
raise BzrCommandError('No matching files.')
923
raise errors.BzrCommandError('No matching files.')
924
924
tree.remove(file_list, verbose=verbose, to_file=self.outf)
940
940
tree, relpath = WorkingTree.open_containing(filename)
941
941
i = tree.inventory.path2id(relpath)
943
raise BzrError("%r is not a versioned file" % filename)
943
raise errors.BzrError("%r is not a versioned file" % filename)
945
945
self.outf.write(i + '\n')
961
961
inv = tree.inventory
962
962
fid = inv.path2id(relpath)
964
raise BzrError("%r is not a versioned file" % filename)
964
raise errors.BzrError("%r is not a versioned file" % filename)
965
965
for fip in inv.get_idpath(fid):
966
966
self.outf.write(fip + '\n')
1083
1083
existing_bzrdir = bzrdir.BzrDir.open(location)
1084
except NotBranchError:
1084
except errors.NotBranchError:
1085
1085
# really a NotBzrDir error...
1086
1086
bzrdir.BzrDir.create_branch_convenience(location, format=format)
1088
from bzrlib.transport.local import LocalTransport
1088
1089
if existing_bzrdir.has_branch():
1089
1090
if (isinstance(to_transport, LocalTransport)
1090
1091
and not existing_bzrdir.has_workingtree()):
1202
except FileInWrongBranch:
1204
except errors.FileInWrongBranch:
1203
1205
if len(file_list) != 2:
1204
raise BzrCommandError("Files are in different branches")
1206
raise errors.BzrCommandError("Files are in different branches")
1206
1208
tree1, file1 = WorkingTree.open_containing(file_list[0])
1207
1209
tree2, file2 = WorkingTree.open_containing(file_list[1])
1208
1210
if file1 != "" or file2 != "":
1209
1211
# FIXME diff those two files. rbc 20051123
1210
raise BzrCommandError("Files are in different branches")
1212
raise errors.BzrCommandError("Files are in different branches")
1211
1213
file_list = None
1212
except NotBranchError:
1214
except errors.NotBranchError:
1213
1215
if (revision is not None and len(revision) == 2
1214
1216
and not revision[0].needs_branch()
1215
1217
and not revision[1].needs_branch()):
1221
1223
if revision is not None:
1222
1224
if tree2 is not None:
1223
raise BzrCommandError("Can't specify -r with two branches")
1225
raise errors.BzrCommandError("Can't specify -r with two branches")
1224
1226
if (len(revision) == 1) or (revision[1].spec is None):
1225
1227
return diff_cmd_helper(tree1, file_list, diff_options,
1230
1232
revision[0], revision[1],
1231
1233
old_label=old_label, new_label=new_label)
1233
raise BzrCommandError('bzr diff --revision takes exactly one or two revision identifiers')
1235
raise errors.BzrCommandError('bzr diff --revision takes exactly'
1236
' one or two revision identifiers')
1235
1238
if tree2 is not None:
1236
1239
return show_diff_trees(tree1, tree2, sys.stdout,
1394
1397
# b is taken from revision[0].get_branch(), and
1395
1398
# show_log will use its revision_history. Having
1396
1399
# different branches will lead to weird behaviors.
1397
raise BzrCommandError(
1400
raise errors.BzrCommandError(
1398
1401
"Log doesn't accept two revisions in different branches.")
1399
1402
if revision[0].spec is None:
1400
1403
# missing begin-range means first revision
1409
1412
rev2 = revision[1].in_history(b).revno
1411
raise BzrCommandError('bzr log --revision takes one or two values.')
1414
raise errors.BzrCommandError('bzr log --revision takes one or two values.')
1413
1416
# By this point, the revision numbers are converted to the +ve
1414
1417
# form if they were supplied in the -ve form, so we can do
1490
1493
if verbose and null:
1491
raise BzrCommandError('Cannot set both --verbose and --null')
1494
raise errors.BzrCommandError('Cannot set both --verbose and --null')
1492
1495
all = not (unknown or versioned or ignored)
1494
1497
selection = {'I':ignored, '?':unknown, 'V':versioned}
1562
1565
if name_pattern is None:
1563
raise BzrCommandError("ignore requires a NAME_PATTERN")
1566
raise errors.BzrCommandError("ignore requires a NAME_PATTERN")
1564
1567
tree, relpath = WorkingTree.open_containing(u'.')
1565
1568
ifn = tree.abspath('.bzrignore')
1566
1569
if os.path.exists(ifn):
1661
1664
rev_id = b.last_revision()
1663
1666
if len(revision) != 1:
1664
raise BzrError('bzr export --revision takes exactly 1 argument')
1667
raise errors.BzrError('bzr export --revision takes exactly'
1665
1669
rev_id = revision[0].in_history(b).rev_id
1666
1670
t = b.repository.revision_tree(rev_id)
1668
1672
export(t, dest, format, root)
1669
1673
except errors.NoSuchExportFormat, e:
1670
raise BzrCommandError('Unsupported export format: %s' % e.format)
1674
raise errors.BzrCommandError('Unsupported export format: %s' % e.format)
1673
1677
class cmd_cat(Command):
1679
1683
@display_command
1680
1684
def run(self, filename, revision=None):
1681
1685
if revision is not None and len(revision) != 1:
1682
raise BzrCommandError("bzr cat --revision takes exactly one number")
1686
raise errors.BzrCommandError("bzr cat --revision takes exactly one number")
1685
1689
tree, relpath = WorkingTree.open_containing(filename)
1686
1690
b = tree.branch
1687
except NotBranchError:
1691
except errors.NotBranchError:
1690
1694
if tree is None:
1778
1782
template = make_commit_message_template(tree, selected_list)
1779
1783
message = edit_commit_message(template)
1780
1784
if message is None:
1781
raise BzrCommandError("please specify a commit message"
1782
" with either --message or --file")
1785
raise errors.BzrCommandError("please specify a commit message"
1786
" with either --message or --file")
1783
1787
elif message and file:
1784
raise BzrCommandError("please specify either --message or --file")
1788
raise errors.BzrCommandError("please specify either --message or --file")
1787
1791
message = codecs.open(file, 'rt', bzrlib.user_encoding).read()
1789
1793
if message == "":
1790
raise BzrCommandError("empty commit message specified")
1794
raise errors.BzrCommandError("empty commit message specified")
1793
1797
reporter = ReportCommitToLog()
1801
1805
except PointlessCommit:
1802
1806
# FIXME: This should really happen before the file is read in;
1803
1807
# perhaps prepare the commit; get the message; then actually commit
1804
raise BzrCommandError("no changes to commit."
1805
" use --unchanged to commit anyhow")
1808
raise errors.BzrCommandError("no changes to commit."
1809
" use --unchanged to commit anyhow")
1806
1810
except ConflictsInTree:
1807
raise BzrCommandError("Conflicts detected in working tree. "
1811
raise errors.BzrCommandError("Conflicts detected in working tree. "
1808
1812
'Use "bzr conflicts" to list, "bzr resolve FILE" to resolve.')
1809
1813
except StrictCommitFailed:
1810
raise BzrCommandError("Commit refused because there are unknown "
1811
"files in the working tree.")
1814
raise errors.BzrCommandError("Commit refused because there are unknown "
1815
"files in the working tree.")
1812
1816
except errors.BoundBranchOutOfDate, e:
1813
raise BzrCommandError(str(e) + "\n"
1817
raise errors.BzrCommandError(str(e) + "\n"
1814
1818
'To commit to master branch, run update and then commit.\n'
1815
1819
'You can also pass --local to commit to continue working '
1816
1820
'disconnected.')
1900
1904
# use branch if we're inside one; otherwise global config
1902
1906
c = Branch.open_containing('.')[0].get_config()
1903
except NotBranchError:
1907
except errors.NotBranchError:
1904
1908
c = config.GlobalConfig()
1906
1910
self.outf.write(c.user_email() + '\n')
1911
1915
# display a warning if an email address isn't included in the given name.
1913
1917
config.extract_email_address(name)
1918
except errors.NoEmailInUsername, e:
1915
1919
warning('"%s" does not seem to contain an email address. '
1916
1920
'This is allowed, but not recommended.', name)
2085
2089
@display_command
2086
2090
def run(self, branch, other):
2087
from bzrlib.revision import common_ancestor, MultipleRevisionSources
2091
from bzrlib.revision import MultipleRevisionSources
2089
2093
branch1 = Branch.open_containing(branch)[0]
2090
2094
branch2 = Branch.open_containing(other)[0]
2152
2156
' from a working copy, instead of branch changes')]
2154
2158
def help(self):
2155
from merge import merge_type_help
2156
2159
from inspect import getdoc
2157
return getdoc(self) + '\n' + merge_type_help()
2160
return getdoc(self) + '\n' + _mod_merge.merge_type_help()
2159
2162
def run(self, branch=None, revision=None, force=False, merge_type=None,
2160
2163
show_base=False, reprocess=False, remember=False,
2161
2164
uncommitted=False):
2162
2165
if merge_type is None:
2163
merge_type = Merge3Merger
2166
merge_type = _mod_merge.Merge3Merger
2165
2168
tree = WorkingTree.open_containing(u'.')[0]
2167
2170
if branch is not None:
2169
2172
reader = bundle.read_bundle_from_url(branch)
2173
except errors.NotABundle:
2171
2174
pass # Continue on considering this url a Branch
2173
2176
conflicts = merge_bundle(reader, tree, not force, merge_type,
2191
2194
other_branch, path = Branch.open_containing(branch)
2193
2196
if uncommitted:
2194
raise BzrCommandError('Cannot use --uncommitted and --revision'
2195
' at the same time.')
2197
raise errors.BzrCommandError('Cannot use --uncommitted and'
2198
' --revision at the same time.')
2196
2199
branch = revision[0].get_branch() or branch
2197
2200
if len(revision) == 1:
2198
2201
base = [None, None]
2203
2206
assert len(revision) == 2
2204
2207
if None in revision:
2205
raise BzrCommandError(
2208
raise errors.BzrCommandError(
2206
2209
"Merge doesn't permit empty revision specifier.")
2207
2210
base_branch, path = Branch.open_containing(branch)
2208
2211
branch1 = revision[1].get_branch() or branch
2224
2227
pb = ui.ui_factory.nested_progress_bar()
2227
conflict_count = merge(other, base, check_clean=(not force),
2228
merge_type=merge_type,
2229
reprocess=reprocess,
2230
show_base=show_base,
2231
pb=pb, file_list=interesting_files)
2230
conflict_count = _merge_helper(
2231
other, base, check_clean=(not force),
2232
merge_type=merge_type,
2233
reprocess=reprocess,
2234
show_base=show_base,
2235
pb=pb, file_list=interesting_files)
2234
2238
if conflict_count != 0:
2255
2259
stored_location = tree.branch.get_parent()
2256
2260
mutter("%s", stored_location)
2257
2261
if stored_location is None:
2258
raise BzrCommandError("No location specified or remembered")
2262
raise errors.BzrCommandError("No location specified or remembered")
2259
2263
display_url = urlutils.unescape_for_display(stored_location, self.outf.encoding)
2260
2264
self.outf.write("%s remembered location %s\n" % (verb_string, display_url))
2261
2265
return stored_location
2290
2294
def help(self):
2291
from merge import merge_type_help
2292
2295
from inspect import getdoc
2293
return getdoc(self) + '\n' + merge_type_help()
2296
return getdoc(self) + '\n' + _mod_merge.merge_type_help()
2295
2298
def run(self, file_list=None, merge_type=None, show_base=False,
2296
2299
reprocess=False):
2297
from bzrlib.merge import merge_inner, transform_tree
2298
2300
if merge_type is None:
2299
merge_type = Merge3Merger
2301
merge_type = _mod_merge.Merge3Merger
2300
2302
tree, file_list = tree_files(file_list)
2301
2303
tree.lock_write()
2303
2305
parents = tree.get_parent_ids()
2304
2306
if len(parents) != 2:
2305
raise BzrCommandError("Sorry, remerge only works after normal"
2306
" merges. Not cherrypicking or"
2307
raise errors.BzrCommandError("Sorry, remerge only works after normal"
2308
" merges. Not cherrypicking or"
2308
2310
repository = tree.branch.repository
2309
2311
base_revision = common_ancestor(parents[0],
2310
2312
parents[1], repository)
2318
2320
for filename in file_list:
2319
2321
file_id = tree.path2id(filename)
2320
2322
if file_id is None:
2321
raise NotVersionedError(filename)
2323
raise errors.NotVersionedError(filename)
2322
2324
interesting_ids.add(file_id)
2323
2325
if tree.kind(file_id) != "directory":
2326
2328
for name, ie in tree.inventory.iter_entries(file_id):
2327
2329
interesting_ids.add(ie.file_id)
2328
2330
new_conflicts = conflicts.select_conflicts(tree, file_list)[0]
2329
transform_tree(tree, tree.basis_tree(), interesting_ids)
2331
_mod_merge.transform_tree(tree, tree.basis_tree(), interesting_ids)
2330
2332
tree.set_conflicts(ConflictList(new_conflicts))
2331
2333
if file_list is None:
2332
2334
restore_files = list(tree.iter_conflicts())
2335
2337
for filename in restore_files:
2337
2339
restore(tree.abspath(filename))
2338
except NotConflicted:
2340
except errors.NotConflicted:
2340
conflicts = merge_inner(tree.branch, other_tree, base_tree,
2342
interesting_ids=interesting_ids,
2343
other_rev_id=parents[1],
2344
merge_type=merge_type,
2345
show_base=show_base,
2346
reprocess=reprocess)
2342
conflicts = _mod_merge.merge_inner(
2343
tree.branch, other_tree, base_tree,
2345
interesting_ids=interesting_ids,
2346
other_rev_id=parents[1],
2347
merge_type=merge_type,
2348
show_base=show_base,
2349
reprocess=reprocess)
2349
2352
if conflicts > 0:
2377
2380
aliases = ['merge-revert']
2379
2382
def run(self, revision=None, no_backup=False, file_list=None):
2380
from bzrlib.commands import parse_spec
2381
2383
if file_list is not None:
2382
2384
if len(file_list) == 0:
2383
raise BzrCommandError("No files specified")
2385
raise errors.BzrCommandError("No files specified")
2389
2391
# FIXME should be tree.last_revision
2390
2392
rev_id = tree.last_revision()
2391
2393
elif len(revision) != 1:
2392
raise BzrCommandError('bzr revert --revision takes exactly 1 argument')
2394
raise errors.BzrCommandError('bzr revert --revision takes exactly 1 argument')
2394
2396
rev_id = revision[0].in_history(tree.branch).rev_id
2395
2397
pb = ui.ui_factory.nested_progress_bar()
2481
2483
if other_branch is None:
2482
2484
other_branch = parent
2483
2485
if other_branch is None:
2484
raise BzrCommandError("No peer location known or specified.")
2486
raise errors.BzrCommandError("No peer location known or specified.")
2485
2487
print "Using last location: " + local_branch.get_parent()
2486
2488
remote_branch = Branch.open(other_branch)
2487
2489
if remote_branch.base == local_branch.base:
2616
2618
if revision is None:
2617
2619
revision_id = branch.last_revision()
2618
2620
elif len(revision) != 1:
2619
raise BzrCommandError('bzr annotate --revision takes exactly 1 argument')
2621
raise errors.BzrCommandError('bzr annotate --revision takes exactly 1 argument')
2621
2623
revision_id = revision[0].in_history(branch).rev_id
2622
2624
file_id = tree.inventory.path2id(relpath)
2638
2640
def run(self, revision_id_list=None, revision=None):
2639
2641
import bzrlib.gpg as gpg
2640
2642
if revision_id_list is not None and revision is not None:
2641
raise BzrCommandError('You can only supply one of revision_id or --revision')
2643
raise errors.BzrCommandError('You can only supply one of revision_id or --revision')
2642
2644
if revision_id_list is None and revision is None:
2643
raise BzrCommandError('You must supply either --revision or a revision_id')
2645
raise errors.BzrCommandError('You must supply either --revision or a revision_id')
2644
2646
b = WorkingTree.open_containing(u'.')[0].branch
2645
2647
gpg_strategy = gpg.GPGStrategy(b.get_config())
2646
2648
if revision_id_list is not None:
2659
2661
if to_revid is None:
2660
2662
to_revno = b.revno()
2661
2663
if from_revno is None or to_revno is None:
2662
raise BzrCommandError('Cannot sign a range of non-revision-history revisions')
2664
raise errors.BzrCommandError('Cannot sign a range of non-revision-history revisions')
2663
2665
for revno in range(from_revno, to_revno + 1):
2664
2666
b.repository.sign_revision(b.get_rev_id(revno),
2667
raise BzrCommandError('Please supply either one revision, or a range.')
2669
raise errors.BzrCommandError('Please supply either one revision, or a range.')
2670
2672
class cmd_bind(Command):
2682
2684
b_other = Branch.open(location)
2684
2686
b.bind(b_other)
2685
except DivergedBranches:
2686
raise BzrCommandError('These branches have diverged.'
2687
' Try merging, and then bind again.')
2687
except errors.DivergedBranches:
2688
raise errors.BzrCommandError('These branches have diverged.'
2689
' Try merging, and then bind again.')
2690
2692
class cmd_unbind(Command):
2701
2703
b, relpath = Branch.open_containing(u'.')
2702
2704
if not b.unbind():
2703
raise BzrCommandError('Local branch is not bound')
2705
raise errors.BzrCommandError('Local branch is not bound')
2706
2708
class cmd_uncommit(Command):
2865
2867
print 'listening on port: ', server.port
2866
2868
sys.stdout.flush()
2868
raise BzrCommandError("bzr serve requires one of --inet or --port")
2870
raise errors.BzrCommandError("bzr serve requires one of --inet or --port")
2872
2874
# command-line interpretation helper for merge-related commands
2873
def merge(other_revision, base_revision,
2874
check_clean=True, ignore_zero=False,
2875
this_dir=None, backup_files=False, merge_type=Merge3Merger,
2876
file_list=None, show_base=False, reprocess=False,
2877
pb=DummyProgress()):
2875
def _merge_helper(other_revision, base_revision,
2876
check_clean=True, ignore_zero=False,
2877
this_dir=None, backup_files=False,
2879
file_list=None, show_base=False, reprocess=False,
2880
pb=DummyProgress()):
2878
2881
"""Merge changes into a tree.
2902
2905
clients might prefer to call merge.merge_inner(), which has less magic
2905
from bzrlib.merge import Merger
2908
# Loading it late, so that we don't always have to import bzrlib.merge
2909
if merge_type is None:
2910
merge_type = _mod_merge.Merge3Merger
2906
2911
if this_dir is None:
2907
2912
this_dir = u'.'
2908
2913
this_tree = WorkingTree.open_containing(this_dir)[0]
2909
if show_base and not merge_type is Merge3Merger:
2910
raise BzrCommandError("Show-base is not supported for this merge"
2911
" type. %s" % merge_type)
2914
if show_base and not merge_type is _mod_merge.Merge3Merger:
2915
raise errors.BzrCommandError("Show-base is not supported for this merge"
2916
" type. %s" % merge_type)
2912
2917
if reprocess and not merge_type.supports_reprocess:
2913
raise BzrCommandError("Conflict reduction is not supported for merge"
2914
" type %s." % merge_type)
2918
raise errors.BzrCommandError("Conflict reduction is not supported for merge"
2919
" type %s." % merge_type)
2915
2920
if reprocess and show_base:
2916
raise BzrCommandError("Cannot do conflict reduction and show base.")
2921
raise errors.BzrCommandError("Cannot do conflict reduction and show base.")
2918
merger = Merger(this_tree.branch, this_tree=this_tree, pb=pb)
2923
merger = _mod_merge.Merger(this_tree.branch, this_tree=this_tree,
2919
2925
merger.pp = ProgressPhase("Merge phase", 5, pb)
2920
2926
merger.pp.next_phase()
2921
2927
merger.check_basis(check_clean)