Esempio n. 1
0
 def test_get_set_default_format(self):
     # set the format and then set it back again
     old_format = BranchFormat.get_default_format()
     BranchFormat.set_default_format(SampleBranchFormat())
     try:
         # the default branch format is used by the meta dir format
         # which is not the default bzrdir format at this point
         dir = BzrDirMetaFormat1().initialize('memory:///')
         result = dir.create_branch()
         self.assertEqual(result, 'A branch')
     finally:
         BranchFormat.set_default_format(old_format)
     self.assertEqual(old_format, BranchFormat.get_default_format())
Esempio n. 2
0
 def test_get_set_default_format(self):
     # set the format and then set it back again
     old_format = BranchFormat.get_default_format()
     BranchFormat.set_default_format(SampleBranchFormat())
     try:
         # the default branch format is used by the meta dir format
         # which is not the default bzrdir format at this point
         dir = BzrDirMetaFormat1().initialize('memory:///')
         result = dir.create_branch()
         self.assertEqual(result, 'A branch')
     finally:
         BranchFormat.set_default_format(old_format)
     self.assertEqual(old_format, BranchFormat.get_default_format())
Esempio n. 3
0
def get_branch(repo, relpath, format=None):
    """Return existing branch in destination repo. Create new if don't exist.

    @param  format:     force create new branch in specified format.
    """
    repo_trans = repo.bzrdir.root_transport
    try:
        br_dir = BzrDir.open(repo_trans.abspath(relpath))
        branch = br_dir.open_branch()
    except errors.NotBranchError:
        # create destination branch directory, creating parents as needed.
        needed = [relpath]
        while needed:
            try:
                repo_trans.mkdir(needed[-1])
                needed.pop()
            except errors.NoSuchFile:
                parent = urlutils.dirname(needed[-1])
                if parent == '':
                    raise errors.BzrCommandError('Could not create branch dir')
                needed.append(parent)
        br_dir = BzrDir.create(repo_trans.abspath(relpath))
        if format is None:
            format = BranchFormat.get_default_format()
        branch = format.initialize(br_dir)

        note('Created destination branch %s' % relpath)

    if branch.repository.bzrdir.root_transport.base != repo_trans.base:
        raise errors.BzrCommandError('Branch %s does not use repository %s'
                                     % (relpath, repo_trans.base))
    # XXX: hack to make sure the branch is using the same repository
    # instance, for locking purposes
    branch.repository = repo
    return branch
Esempio n. 4
0
def get_branch(repo, relpath, format=None):
    """Return existing branch in destination repo. Create new if don't exist.

    @param  format:     force create new branch in specified format.
    """
    repo_trans = repo.bzrdir.root_transport
    try:
        br_dir = BzrDir.open(repo_trans.abspath(relpath))
        branch = br_dir.open_branch()
    except errors.NotBranchError:
        # create destination branch directory, creating parents as needed.
        needed = [relpath]
        while needed:
            try:
                repo_trans.mkdir(needed[-1])
                needed.pop()
            except errors.NoSuchFile:
                parent = urlutils.dirname(needed[-1])
                if parent == '':
                    raise errors.BzrCommandError('Could not create branch dir')
                needed.append(parent)
        br_dir = BzrDir.create(repo_trans.abspath(relpath))
        if format is None:
            format = BranchFormat.get_default_format()
        branch = format.initialize(br_dir)

        note('Created destination branch %s' % relpath)

    if branch.repository.bzrdir.root_transport.base != repo_trans.base:
        raise errors.BzrCommandError('Branch %s does not use repository %s' %
                                     (relpath, repo_trans.base))
    # XXX: hack to make sure the branch is using the same repository
    # instance, for locking purposes
    branch.repository = repo
    return branch
Esempio n. 5
0
 def test_default_format_is_same_as_bzrdir_default(self):
     # XXX: it might be nice if there was only one place the default was
     # set, but at the moment that's not true -- mbp 20070814 -- 
     # https://bugs.launchpad.net/bzr/+bug/132376
     self.assertEqual(BranchFormat.get_default_format(),
             BzrDirFormat.get_default_format().get_branch_format())
Esempio n. 6
0
 def test_default_format(self):
     # update this if you change the default branch format
     self.assertIsInstance(BranchFormat.get_default_format(),
             BzrBranchFormat6)
Esempio n. 7
0
 def test_default_format_is_same_as_bzrdir_default(self):
     # XXX: it might be nice if there was only one place the default was
     # set, but at the moment that's not true -- mbp 20070814 --
     # https://bugs.launchpad.net/bzr/+bug/132376
     self.assertEqual(BranchFormat.get_default_format(),
                      BzrDirFormat.get_default_format().get_branch_format())
Esempio n. 8
0
 def test_default_format(self):
     # update this if you change the default branch format
     self.assertIsInstance(BranchFormat.get_default_format(),
                           BzrBranchFormat6)