def create_temp_sprout(branch, additional_colocated_branches=None, dir=None): """Create a temporary sprout of a branch. This attempts to fetch the least amount of history as possible. """ td = osutils.mkdtemp(dir=dir) def destroy(): shutil.rmtree(td) try: # preserve whatever source format we have. to_dir = branch.controldir.sprout( td, None, create_tree_if_local=True, source_branch=branch, stacked=branch._format.supports_stacking()) # TODO(jelmer): Fetch these during the initial clone for branch_name in additional_colocated_branches or []: try: add_branch = branch.controldir.open_branch(name=branch_name) except (errors.NotBranchError, errors.NoColocatedBranchSupport): pass else: local_add_branch = to_dir.create_branch(name=branch_name) add_branch.push(local_add_branch) assert (add_branch.last_revision() == local_add_branch.last_revision()) return to_dir.open_workingtree(), destroy except BaseException as e: shutil.rmtree(td) raise e
def test_diff_outside_tree(self): tree = self.make_branch_and_tree('branch1') tree.commit('nothing') tree.commit('nothing') # A directory we can run commands from which we hope is not contained # in a brz tree (though if there is one at or above $TEMPDIR, this is # false and may cause test failures). # Watch out for tricky test dir (on OSX /tmp -> /private/tmp) tmp_dir = osutils.realpath(osutils.mkdtemp()) self.addCleanup(osutils.rmtree, tmp_dir) # We expect a read-to-root attempt to occur. self.permit_url('file:///') expected_error = u'brz: ERROR: Not a branch: "%s/branch2/".\n' % tmp_dir # -r X..Y out, err = self.run_bzr('diff -r revno:2:branch2..revno:1', retcode=3, working_dir=tmp_dir) self.assertEqual('', out) self.assertEqual(expected_error, err) # -r X out, err = self.run_bzr('diff -r revno:2:branch2', retcode=3, working_dir=tmp_dir) self.assertEqual('', out) self.assertEqual(expected_error, err) # -r X.. out, err = self.run_bzr('diff -r revno:2:branch2..', retcode=3, working_dir=tmp_dir) self.assertEqual('', out) self.assertEqual(expected_error, err) # no -r at all. out, err = self.run_bzr('diff', retcode=3, working_dir=tmp_dir) self.assertEqual('', out) self.assertEqual(u'brz: ERROR: Not a branch: "%s/".\n' % tmp_dir, err)
def commit_tree(self, tree, revision_id=None): tree.commit("This is a message", rev_id=revision_id) tempdir = osutils.mkdtemp( prefix='testbzrsvn-', suffix='.tmp', dir=self.test_dir) self.addCleanup(shutil.rmtree, tempdir) to_branch = ControlDir.create_branch_and_repo( os.path.join(tempdir, 'branch')) tree.branch.push(to_branch) return to_branch.basis_tree()
def test_cwd_log(self): # Watch out for tricky test dir (on OSX /tmp -> /private/tmp) tmp_dir = osutils.realpath(osutils.mkdtemp()) # We expect a read-to-root attempt to occur. self.permit_url('file:///') self.addCleanup(osutils.rmtree, tmp_dir) out, err = self.run_bzr('log', retcode=3, working_dir=tmp_dir) self.assertEqual(u'brz: ERROR: Not a branch: "%s/".\n' % (tmp_dir,), err)
def create_temp_sprout( branch: Branch, additional_colocated_branches: Optional[List[str]] = None, dir: Optional[str] = None, path: Optional[str] = None, ) -> Tuple[WorkingTree, Callable[[], None]]: """Create a temporary sprout of a branch. This attempts to fetch the least amount of history as possible. """ if path is None: td = osutils.mkdtemp(dir=dir) else: td = path os.mkdir(path) def destroy() -> None: shutil.rmtree(td) # Only use stacking if the remote repository supports chks because of # https://bugs.launchpad.net/bzr/+bug/375013 use_stacking = ( branch._format.supports_stacking() and branch.repository._format.supports_chks ) try: # preserve whatever source format we have. to_dir = branch.controldir.sprout( td, None, create_tree_if_local=True, source_branch=branch, stacked=use_stacking, ) # TODO(jelmer): Fetch these during the initial clone for branch_name in set(additional_colocated_branches or []): try: add_branch = branch.controldir.open_branch(name=branch_name) except (errors.NotBranchError, errors.NoColocatedBranchSupport): pass else: local_add_branch = to_dir.create_branch(name=branch_name) add_branch.push(local_add_branch) assert add_branch.last_revision() == local_add_branch.last_revision() return to_dir.open_workingtree(), destroy except BaseException as e: destroy() raise e