def _setup_annex_repo(path, initopts=None, fake_dates=False, description=None): """Create and configure a repository at `path` This includes a default setup of annex.largefiles. Parameters ---------- path: str or Path Path of the repository initopts: dict, optional Git options to be passed to the AnnexRepo constructor fake_dates: bool, optional Passed to the AnnexRepo constructor description: str, optional Passed to the AnnexRepo constructor Returns ------- AnnexRepo, dict Created repository and records for any repo component that needs to be passed to git-add as a result of the setup procedure. """ # always come with annex when created from scratch tbrepo = AnnexRepo( path, create=True, create_sanity_checks=False, # do not set backend here, to avoid a dedicated commit backend=None, # None causes version to be taken from config version=None, description=description, git_opts=initopts, fake_dates=fake_dates) # set the annex backend in .gitattributes as a staged change tbrepo.set_default_backend(cfg.obtain('datalad.repo.backend'), persistent=True, commit=False) add_to_git = { tbrepo.pathobj / '.gitattributes': { 'type': 'file', 'state': 'added', } } # make sure that v6 annex repos never commit content under .datalad attrs_cfg = (('config', 'annex.largefiles', 'nothing'), ( 'metadata/aggregate*', 'annex.largefiles', 'nothing'), ('metadata/objects/**', 'annex.largefiles', '({})'.format( cfg.obtain('datalad.metadata.create-aggregate-annex-limit')))) attrs = tbrepo.get_gitattributes( [op.join('.datalad', i[0]) for i in attrs_cfg]) set_attrs = [] for p, k, v in attrs_cfg: if not attrs.get(op.join('.datalad', p), {}).get(k, None) == v: set_attrs.append((p, {k: v})) if set_attrs: tbrepo.set_gitattributes(set_attrs, attrfile=op.join('.datalad', '.gitattributes')) # prevent git annex from ever annexing .git* stuff (gh-1597) attrs = tbrepo.get_gitattributes('.git') if not attrs.get('.git', {}).get('annex.largefiles', None) == 'nothing': tbrepo.set_gitattributes([('**/.git*', { 'annex.largefiles': 'nothing' })]) # must use the repo.pathobj as this will have resolved symlinks add_to_git[tbrepo.pathobj / '.gitattributes'] = { 'type': 'file', 'state': 'untracked' } return tbrepo, add_to_git