23
from shutil import rmtree
28
from bzrlib.branch import Branch
29
import bzrlib.bzrdir as bzrdir
26
from bzrlib.branch import Branch, BranchReferenceFormat
27
from bzrlib import (bundle, branch, bzrdir, errors, osutils, ui, config,
30
29
from bzrlib.bundle import read_bundle_from_url
31
30
from bzrlib.bundle.apply_bundle import install_bundle, merge_bundle
32
31
from bzrlib.commands import Command, display_command
33
import bzrlib.errors as errors
34
32
from bzrlib.errors import (BzrError, BzrCheckError, BzrCommandError,
35
33
NotBranchError, DivergedBranches, NotConflicted,
36
34
NoSuchFile, NoWorkingTree, FileInWrongBranch,
37
35
NotVersionedError, NotABundle)
38
from bzrlib.log import show_one_log
39
36
from bzrlib.merge import Merge3Merger
40
37
from bzrlib.option import Option
42
38
from bzrlib.progress import DummyProgress, ProgressPhase
43
39
from bzrlib.revision import common_ancestor
44
40
from bzrlib.revisionspec import RevisionSpec
46
from bzrlib.trace import mutter, note, log_error, warning, is_quiet
41
from bzrlib.trace import mutter, note, log_error, warning, is_quiet, info
47
42
from bzrlib.transport.local import LocalTransport
49
43
import bzrlib.urlutils as urlutils
50
44
from bzrlib.workingtree import WorkingTree
94
88
return bzrdir.BzrDirMetaFormat1()
95
89
if typestring == "metaweave":
96
90
format = bzrdir.BzrDirMetaFormat1()
97
format.repository_format = bzrlib.repository.RepositoryFormat7()
91
format.repository_format = repository.RepositoryFormat7()
99
93
if typestring == "knit":
100
94
format = bzrdir.BzrDirMetaFormat1()
101
format.repository_format = bzrlib.repository.RepositoryFormatKnit1()
95
format.repository_format = repository.RepositoryFormatKnit1()
103
97
msg = "Unknown bzr format %s. Current formats are: default, knit,\n" \
104
98
"metaweave and weave" % typestring
416
410
If there is no default location set, the first pull will set it. After
417
411
that, you can omit the location to use the default. To change the
418
default, use --remember.
412
default, use --remember. The value will only be saved if the remote
413
location can be accessed.
421
416
takes_options = ['remember', 'overwrite', 'revision', 'verbose']
506
501
If there is no default push location set, the first push will set it.
507
502
After that, you can omit the location to use the default. To change the
508
default, use --remember.
503
default, use --remember. The value will only be saved if the remote
504
location can be accessed.
511
507
takes_options = ['remember', 'overwrite', 'verbose',
530
526
display_url = urlutils.unescape_for_display(stored_loc,
531
527
self.outf.encoding)
532
self.outf.write("Using saved location: %s" % display_url)
528
self.outf.write("Using saved location: %s\n" % display_url)
533
529
location = stored_loc
535
531
transport = get_transport(location)
536
532
location_url = transport.base
537
if br_from.get_push_location() is None or remember:
538
br_from.set_push_location(location_url)
542
dir_to = bzrlib.bzrdir.BzrDir.open(location_url)
536
dir_to = bzrdir.BzrDir.open(location_url)
543
537
br_to = dir_to.open_branch()
544
538
except NotBranchError:
545
539
# create a branch.
571
565
revision_id=br_from.last_revision())
572
566
br_to = dir_to.open_branch()
573
567
count = len(br_to.revision_history())
568
# We successfully created the target, remember it
569
if br_from.get_push_location() is None or remember:
570
br_from.set_push_location(br_to.base)
572
# We were able to connect to the remote location, so remember it
573
# we don't need to successfully push because of possible divergence.
574
if br_from.get_push_location() is None or remember:
575
br_from.set_push_location(br_to.base)
575
576
old_rh = br_to.revision_history()
618
619
def run(self, from_location, to_location=None, revision=None, basis=None):
619
620
from bzrlib.transport import get_transport
620
from bzrlib.osutils import rmtree
621
621
if revision is None:
622
622
revision = [None]
623
623
elif len(revision) > 1:
653
653
to_transport = get_transport(to_location)
655
655
to_transport.mkdir('.')
656
except bzrlib.errors.FileExists:
656
except errors.FileExists:
657
657
raise BzrCommandError('Target directory "%s" already'
658
658
' exists.' % to_location)
659
except bzrlib.errors.NoSuchFile:
659
except errors.NoSuchFile:
660
660
raise BzrCommandError('Parent of "%s" does not exist.' %
664
664
dir = br_from.bzrdir.sprout(to_transport.base,
665
665
revision_id, basis_dir)
666
666
branch = dir.open_branch()
667
except bzrlib.errors.NoSuchRevision:
667
except errors.NoSuchRevision:
668
668
to_transport.delete_tree('.')
669
669
msg = "The branch %s has no revision %s." % (from_location, revision[0])
670
670
raise BzrCommandError(msg)
671
except bzrlib.errors.UnlistableBranch:
671
except errors.UnlistableBranch:
672
osutils.rmtree(to_location)
673
673
msg = "The branch %s cannot be used as a --basis" % (basis,)
674
674
raise BzrCommandError(msg)
718
718
raise BzrCommandError(
719
719
'bzr checkout --revision takes exactly 1 revision value')
720
720
if branch_location is None:
721
branch_location = bzrlib.osutils.getcwd()
721
branch_location = osutils.getcwd()
722
722
to_location = branch_location
723
723
source = Branch.open(branch_location)
724
724
if len(revision) == 1 and revision[0] is not None:
730
730
# if the source and to_location are the same,
731
731
# and there is no working tree,
732
732
# then reconstitute a branch
733
if (bzrlib.osutils.abspath(to_location) ==
734
bzrlib.osutils.abspath(branch_location)):
733
if (osutils.abspath(to_location) ==
734
osutils.abspath(branch_location)):
736
736
source.bzrdir.open_workingtree()
737
737
except errors.NoWorkingTree:
751
old_format = bzrlib.bzrdir.BzrDirFormat.get_default_format()
752
bzrlib.bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
751
old_format = bzrdir.BzrDirFormat.get_default_format()
752
bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
755
755
checkout = bzrdir.BzrDirMetaFormat1().initialize(to_location)
756
bzrlib.branch.BranchReferenceFormat().initialize(checkout, source)
756
branch.BranchReferenceFormat().initialize(checkout, source)
758
checkout_branch = bzrlib.bzrdir.BzrDir.create_branch_convenience(
758
checkout_branch = bzrdir.BzrDir.create_branch_convenience(
759
759
to_location, force_new_tree=False)
760
760
checkout = checkout_branch.bzrdir
761
761
checkout_branch.bind(source)
764
764
checkout_branch.set_revision_history(rh[:rh.index(revision_id) + 1])
765
765
checkout.create_workingtree(revision_id)
767
bzrlib.bzrdir.BzrDirFormat.set_default_format(old_format)
767
bzrdir.BzrDirFormat.set_default_format(old_format)
770
770
class cmd_renames(Command):
779
779
def run(self, dir=u'.'):
780
from bzrlib.tree import find_renames
780
781
tree = WorkingTree.open_containing(dir)[0]
781
782
old_inv = tree.basis_tree().inventory
782
783
new_inv = tree.read_working_inventory()
784
renames = list(bzrlib.tree.find_renames(old_inv, new_inv))
784
renames = list(find_renames(old_inv, new_inv))
786
786
for old_name, new_name in renames:
787
787
self.outf.write("%s => %s\n" % (old_name, new_name))
936
936
def run(self, branch="."):
937
937
from bzrlib.reconcile import reconcile
938
dir = bzrlib.bzrdir.BzrDir.open(branch)
938
dir = bzrdir.BzrDir.open(branch)
1213
1212
if file_id in basis_inv:
1215
1214
path = inv.id2path(file_id)
1216
if not os.access(bzrlib.osutils.abspath(path), os.F_OK):
1215
if not os.access(osutils.abspath(path), os.F_OK):
1218
1217
self.outf.write(path + '\n')
1328
1327
(rev2, rev1) = (rev1, rev2)
1330
1329
if (log_format == None):
1331
default = bzrlib.config.BranchConfig(b).log_format()
1330
default = config.BranchConfig(b).log_format()
1332
1331
log_format = get_log_format(long=long, short=short, line=line, default=default)
1333
1332
lf = log_formatter(log_format,
1334
1333
show_ids=show_ids,
1371
1370
b = tree.branch
1372
1371
inv = tree.read_working_inventory()
1373
1372
file_id = inv.path2id(relpath)
1374
for revno, revision_id, what in bzrlib.log.find_touching_revisions(b, file_id):
1373
for revno, revision_id, what in log.find_touching_revisions(b, file_id):
1375
1374
self.outf.write("%6d %s\n" % (revno, what))
1433
1432
"""List unknown files."""
1434
1433
@display_command
1436
from bzrlib.osutils import quotefn
1437
1435
for f in WorkingTree.open_containing(u'.')[0].unknowns():
1438
self.outf.write(quotefn(f) + '\n')
1436
self.outf.write(osutils.quotefn(f) + '\n')
1441
1439
class cmd_ignore(Command):
1689
1687
message = codecs.open(file, 'rt', bzrlib.user_encoding).read()
1691
1689
if message == "":
1692
raise BzrCommandError("empty commit message specified")
1690
raise BzrCommandError("empty commit message specified")
1695
1693
reporter = ReportCommitToLog()
1788
1786
def run(self, email=False):
1790
1788
b = WorkingTree.open_containing(u'.')[0].branch
1791
config = bzrlib.config.BranchConfig(b)
1789
c = config.BranchConfig(b)
1792
1790
except NotBranchError:
1793
config = bzrlib.config.GlobalConfig()
1791
c = config.GlobalConfig()
1796
print config.user_email()
1793
print c.user_email()
1798
print config.username()
1801
1798
class cmd_nick(Command):
1881
1878
# we don't want progress meters from the tests to go to the
1882
1879
# real output; and we don't want log messages cluttering up
1883
1880
# the real logs.
1884
save_ui = bzrlib.ui.ui_factory
1885
print '%10s: %s' % ('bzr', bzrlib.osutils.realpath(sys.argv[0]))
1881
save_ui = ui.ui_factory
1882
print '%10s: %s' % ('bzr', osutils.realpath(sys.argv[0]))
1886
1883
print '%10s: %s' % ('bzrlib', bzrlib.__path__[0])
1888
bzrlib.trace.info('running tests...')
1885
info('running tests...')
1890
bzrlib.ui.ui_factory = bzrlib.ui.SilentUIFactory()
1887
ui.ui_factory = ui.SilentUIFactory()
1891
1888
if testspecs_list is not None:
1892
1889
pattern = '|'.join(testspecs_list)
1908
1905
test_suite_factory=test_suite_factory,
1909
1906
lsprof_timed=lsprof_timed)
1911
bzrlib.trace.info('tests passed')
1908
info('tests passed')
1913
bzrlib.trace.info('tests failed')
1910
info('tests failed')
1914
1911
return int(not result)
1916
bzrlib.ui.ui_factory = save_ui
1913
ui.ui_factory = save_ui
1919
1916
def _get_bzr_branch():
1920
1917
"""If bzr is run from a branch, return Branch or None"""
1921
import bzrlib.errors
1922
from bzrlib.branch import Branch
1923
from bzrlib.osutils import abspath
1924
1918
from os.path import dirname
1927
branch = Branch.open(dirname(abspath(dirname(__file__))))
1921
branch = Branch.open(dirname(osutils.abspath(dirname(__file__))))
1929
except bzrlib.errors.BzrError:
1923
except errors.BzrError:
1933
1927
def show_version():
1934
1929
print "bzr (bazaar-ng) %s" % bzrlib.__version__
1935
1930
# is bzrlib itself in a branch?
1936
1931
branch = _get_bzr_branch()
2002
1997
base_rev_id = common_ancestor(last1, last2, source)
2004
1999
print 'merge base is revision %s' % base_rev_id
2008
if base_revno is None:
2009
raise bzrlib.errors.UnrelatedBranches()
2011
print ' r%-6d in %s' % (base_revno, branch)
2013
other_revno = branch2.revision_id_to_revno(base_revid)
2015
print ' r%-6d in %s' % (other_revno, other)
2019
2002
class cmd_merge(Command):
2020
2003
"""Perform a three-way merge.
2022
The branch is the branch you will merge from. By default, it will
2023
merge the latest revision. If you specify a revision, that
2024
revision will be merged. If you specify two revisions, the first
2025
will be used as a BASE, and the second one as OTHER. Revision
2026
numbers are always relative to the specified branch.
2005
The branch is the branch you will merge from. By default, it will merge
2006
the latest revision. If you specify a revision, that revision will be
2007
merged. If you specify two revisions, the first will be used as a BASE,
2008
and the second one as OTHER. Revision numbers are always relative to the
2028
2011
By default, bzr will try to merge in all new work from the other
2029
2012
branch, automatically determining an appropriate base. If this
2039
2022
If there is no default branch set, the first merge will set it. After
2040
2023
that, you can omit the branch to use the default. To change the
2041
default, use --remember.
2024
default, use --remember. The value will only be saved if the remote
2025
location can be accessed.
2115
2099
interesting_files = [path]
2117
2101
interesting_files = None
2118
pb = bzrlib.ui.ui_factory.nested_progress_bar()
2102
pb = ui.ui_factory.nested_progress_bar()
2121
2105
conflict_count = merge(other, base, check_clean=(not force),
2132
except bzrlib.errors.AmbiguousBase, e:
2116
except errors.AmbiguousBase, e:
2133
2117
m = ("sorry, bzr can't determine the right merge base yet\n"
2134
2118
"candidates are:\n "
2135
2119
+ "\n ".join(e.bases)
2268
2252
raise BzrCommandError('bzr revert --revision takes exactly 1 argument')
2270
2254
rev_id = revision[0].in_history(tree.branch).rev_id
2271
pb = bzrlib.ui.ui_factory.nested_progress_bar()
2255
pb = ui.ui_factory.nested_progress_bar()
2273
2257
tree.revert(file_list,
2274
2258
tree.branch.repository.revision_tree(rev_id),
2322
2306
takes_args = ['from_branch', 'to_branch']
2323
2307
def run(self, from_branch, to_branch):
2324
2308
from bzrlib.fetch import Fetcher
2325
from bzrlib.branch import Branch
2326
2309
from_b = Branch.open(from_branch)
2327
2310
to_b = Branch.open(to_branch)
2328
2311
Fetcher(to_b, from_b)
2351
2334
show_ids=False, verbose=False):
2352
2335
from bzrlib.missing import find_unmerged, iter_log_data
2353
2336
from bzrlib.log import log_formatter
2354
local_branch = bzrlib.branch.Branch.open_containing(u".")[0]
2337
local_branch = Branch.open_containing(u".")[0]
2355
2338
parent = local_branch.get_parent()
2356
2339
if other_branch is None:
2357
2340
other_branch = parent
2358
2341
if other_branch is None:
2359
2342
raise BzrCommandError("No missing location known or specified.")
2360
2343
print "Using last location: " + local_branch.get_parent()
2361
remote_branch = bzrlib.branch.Branch.open(other_branch)
2344
remote_branch = Branch.open(other_branch)
2362
2345
if remote_branch.base == local_branch.base:
2363
2346
remote_branch = local_branch
2364
2347
local_branch.lock_read()
2368
2351
local_extra, remote_extra = find_unmerged(local_branch, remote_branch)
2369
2352
if (log_format == None):
2370
default = bzrlib.config.BranchConfig(local_branch).log_format()
2353
default = config.BranchConfig(local_branch).log_format()
2371
2354
log_format = get_log_format(long=long, short=short, line=line, default=default)
2372
2355
lf = log_formatter(log_format, sys.stdout,
2373
2356
show_ids=show_ids,
2433
2416
class cmd_testament(Command):
2434
2417
"""Show testament (signing-form) of a revision."""
2435
takes_options = ['revision', 'long']
2418
takes_options = ['revision', 'long',
2419
Option('strict', help='Produce a strict testament')]
2436
2420
takes_args = ['branch?']
2437
2421
@display_command
2438
def run(self, branch=u'.', revision=None, long=False):
2439
from bzrlib.testament import Testament
2422
def run(self, branch=u'.', revision=None, long=False, strict=False):
2423
from bzrlib.testament import Testament, StrictTestament
2425
testament_class = StrictTestament
2427
testament_class = Testament
2440
2428
b = WorkingTree.open_containing(branch)[0].branch
2444
2432
rev_id = b.last_revision()
2446
2434
rev_id = revision[0].in_history(b).rev_id
2447
t = Testament.from_revision(b.repository, rev_id)
2435
t = testament_class.from_revision(b.repository, rev_id)
2449
2437
sys.stdout.writelines(t.as_text_lines())
2502
2490
takes_options = ['revision']
2504
2492
def run(self, revision_id_list=None, revision=None):
2505
import bzrlib.config as config
2506
2493
import bzrlib.gpg as gpg
2507
2494
if revision_id_list is not None and revision is not None:
2508
2495
raise BzrCommandError('You can only supply one of revision_id or --revision')
2570
2557
raise BzrCommandError('Local branch is not bound')
2573
class cmd_uncommit(bzrlib.commands.Command):
2560
class cmd_uncommit(Command):
2574
2561
"""Remove the last committed revision.
2576
2563
--verbose will print out what is being removed.
2594
2581
def run(self, location=None,
2595
2582
dry_run=False, verbose=False,
2596
2583
revision=None, force=False):
2597
from bzrlib.branch import Branch
2598
2584
from bzrlib.log import log_formatter
2600
2586
from bzrlib.uncommit import uncommit