Watch
1
0
Fork
You've already forked git-lad
0
forked from datalad/git-lad
git-lad/git_lad/commands/create.py

78 lines
2 KiB
Python

from pathlib import Path
import rich_click as click
from datalad_core.create import (
AnnexInitMode,
DatasetInitMode,
create_dataset,
)
from git_lad.cmd_resources import (
AnnexNoInitMode,
CmdResources,
DatasetNoInitMode,
std_option,
)
@click.command()
@click.argument(
'directory',
type=click.Path(
file_okay=False,
dir_okay=True,
path_type=Path,
),
default=None,
)
@std_option('bare-repository')
@std_option(
'target-branch',
help="""\
Use <branch-name> for the initial branch in the newly created repository. If
not specified, fall back to Git's default name. The name can be customized via
the <init.defaultBranch> configuration variable.""",
)
@std_option('annex-description')
@std_option('no-annex')
@std_option('no-dataset')
@std_option('private-annex')
@std_option('quiet')
@click.pass_obj
def create(
res: CmdResources, # noqa: ARG001
directory: Path | None = None,
*,
bare: bool = False,
branch: str | None = None,
description: str | None = None,
message: str | None = None,
no_annex: str | None = None,
no_dataset: DatasetNoInitMode | None = None,
private: bool = False,
quiet: bool = False,
):
"""Create a repository/dataset in a new/empty directory"""
annex_opt_map = {
str(AnnexNoInitMode.INIT): AnnexInitMode.OFF,
str(AnnexNoInitMode.ENABLEREMOTE): AnnexInitMode.NOENABLEREMOTE,
None: AnnexInitMode.FULL,
}
dataset_opt_map = {
DatasetNoInitMode.INIT: None,
DatasetNoInitMode.PROTECTGIT: DatasetInitMode.ID,
DatasetNoInitMode.BACKEND: DatasetInitMode.ID | DatasetInitMode.PROTECTGIT,
None: DatasetInitMode.ID | DatasetInitMode.PROTECTGIT | DatasetInitMode.BACKEND,
}
return create_dataset(
directory or Path.cwd(),
annex_init=annex_opt_map[no_annex],
bare=bare,
branch=branch,
dataset_init=dataset_opt_map[no_dataset],
description=description,
message=message,
private=private,
quiet=quiet,
)