389
class cmd_pull(Command):
390
"""Pull any changes from another branch into the current one.
392
If the location is omitted, the last-used location will be used.
393
Both the revision history and the working directory will be
396
This command only works on branches that have not diverged. Branches are
397
considered diverged if both branches have had commits without first
398
pulling from the other.
400
If branches have diverged, you can use 'bzr merge' to pull the text changes
401
from one into the other.
403
takes_args = ['location?']
405
def run(self, location=None):
406
from bzrlib.merge import merge
412
stored_loc = br_to.controlfile("x-pull", "rb").read().rstrip('\n')
414
if errno == errno.ENOENT:
417
location = stored_loc
419
raise BzrCommandError("No pull location known or specified.")
420
from branch import find_branch, DivergedBranches
421
br_from = find_branch(location)
422
location = pull_loc(br_from)
423
old_revno = br_to.revno()
425
br_to.update_revisions(br_from)
426
except DivergedBranches:
427
raise BzrCommandError("These branches have diverged. Try merge.")
429
merge(('.', -1), ('.', old_revno))
430
if location != stored_loc:
431
br_to.controlfile("x-pull", "wb").write(location + "\n")
435
class cmd_branch(Command):
436
"""Create a new copy of a branch.
438
If the TO_LOCATION is omitted, the last component of the
439
FROM_LOCATION will be used. In other words,
440
"branch ../foo/bar" will attempt to create ./bar.
442
takes_args = ['from_location', 'to_location?']
444
def run(self, from_location, to_location=None):
446
from bzrlib.merge import merge
448
if to_location is None:
449
to_location = os.path.basename(from_location)
450
# FIXME: If there's a trailing slash, keep removing them
451
# until we find the right bit
454
os.mkdir(to_location)
456
if e.errno == errno.EEXIST:
457
raise BzrCommandError('Target directory "%s" already exists.' %
459
if e.errno == errno.ENOENT:
460
raise BzrCommandError('Parent of "%s" does not exist.' %
464
br_to = Branch(to_location, init=True)
465
from branch import find_branch, DivergedBranches
467
br_from = find_branch(from_location)
469
if e.errno == errno.ENOENT:
470
raise BzrCommandError('Source location "%s" does not exist.' %
475
from_location = pull_loc(br_from)
476
br_to.update_revisions(br_from)
477
merge((to_location, -1), (to_location, 0), this_dir=to_location,
479
br_to.controlfile("x-pull", "wb").write(from_location + "\n")
482
def pull_loc(branch):
483
# TODO: Should perhaps just make attribute be 'base' in
484
# RemoteBranch and Branch?
485
if hasattr(branch, "baseurl"):
486
return branch.baseurl
387
492
class cmd_renames(Command):
388
493
"""Show list of renamed files.
1009
1116
The OTHER_SPEC parameter is required. If the BASE_SPEC parameter is
1010
1117
not supplied, the common ancestor of OTHER_SPEC the current branch is used
1120
merge refuses to run if there are any uncommitted changes, unless
1013
1123
takes_args = ['other_spec', 'base_spec?']
1124
takes_options = ['force']
1015
def run(self, other_spec, base_spec=None):
1126
def run(self, other_spec, base_spec=None, force=False):
1016
1127
from bzrlib.merge import merge
1017
merge(parse_spec(other_spec), parse_spec(base_spec))
1128
merge(parse_spec(other_spec), parse_spec(base_spec),
1129
check_clean=(not force))
1020
1132
class cmd_revert(Command):
1022
Reverse all changes since the last commit. Only versioned files are
1133
"""Reverse all changes since the last commit.
1135
Only versioned files are affected.
1137
TODO: Store backups of any files that will be reverted, so
1138
that the revert can be undone.
1025
1140
takes_options = ['revision']
1027
1142
def run(self, revision=-1):
1028
merge.merge(('.', revision), parse_spec('.'), no_changes=False,
1143
merge(('.', revision), parse_spec('.'),
1032
1148
class cmd_assert_fail(Command):