~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/commands.py

  • Committer: Martin Pool
  • Date: 2005-06-15 03:43:04 UTC
  • Revision ID: mbp@sourcefrog.net-20050615034304-f9419fead7b602dc
- add -r option to the branch command
  patch from aaron

Show diffs side-by-side

added added

removed removed

Lines of Context:
517
517
class cmd_branch(Command):
518
518
    """Create a new copy of a branch.
519
519
 
520
 
    If the TO_LOCATION is omitted, the last component of the
521
 
    FROM_LOCATION will be used.  In other words,
522
 
    "branch ../foo/bar" will attempt to create ./bar.
 
520
    If the TO_LOCATION is omitted, the last component of the FROM_LOCATION will
 
521
    be used.  In other words, "branch ../foo/bar" will attempt to create ./bar.
 
522
 
 
523
    To retrieve the branch as of a particular revision, supply the --revision
 
524
    parameter, as in "branch foo/bar -r 5".
523
525
    """
524
526
    takes_args = ['from_location', 'to_location?']
 
527
    takes_options = ['revision']
525
528
 
526
 
    def run(self, from_location, to_location=None):
 
529
    def run(self, from_location, to_location=None, revision=None):
527
530
        import errno
528
531
        from bzrlib.merge import merge
529
 
        from branch import find_branch, DivergedBranches
 
532
        from branch import find_branch, DivergedBranches, NoSuchRevision
 
533
        from shutil import rmtree
530
534
        try:
531
535
            br_from = find_branch(from_location)
532
536
        except OSError, e:
552
556
                raise
553
557
        br_to = Branch(to_location, init=True)
554
558
 
555
 
        from_location = pull_loc(br_from)
556
 
        br_to.update_revisions(br_from)
 
559
        try:
 
560
            br_to.update_revisions(br_from, stop_revision=revision)
 
561
        except NoSuchRevision:
 
562
            rmtree(to_location)
 
563
            msg = "The branch %s has no revision %d." % (from_location,
 
564
                                                         revision)
 
565
            raise BzrCommandError(msg)
557
566
        merge((to_location, -1), (to_location, 0), this_dir=to_location,
558
567
              check_clean=False)
 
568
        from_location = pull_loc(br_from)
559
569
        br_to.controlfile("x-pull", "wb").write(from_location + "\n")
560
570
 
561
571