Watch
1
0
Fork
You've already forked git-lad
0
forked from datalad/git-lad
git-lad/git_lad/commands/clone.py
Michael Hanke 006a6a38dc
rf: make --shallow a standard option
This is anticipating the addition of a `get` command.
2026-06-07 07:26:41 +02:00

74 lines
1.8 KiB
Python

from pathlib import Path
import rich_click as click
from datalad_core.clone import (
AnnexInitMode,
clone_annexrepo,
)
from git_lad.cmd_resources import (
AnnexNoInitMode,
CmdResources,
std_option,
)
@click.command()
@click.argument('repository')
@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="""\
Instead of pointing the newly created HEAD to the branch pointed to by the
cloned repository's HEAD, point to <NAME> branch instead. In a non-bare
repository, this is the branch that will be checked out. --branch can also
take tags and detaches the HEAD at that commit in the resulting repository
""",
)
@std_option('annex-description')
@std_option('no-annex')
@std_option('private-annex')
@std_option('quiet')
@std_option('shallow')
@click.pass_obj
def clone(
res: CmdResources,
repository: str,
directory: Path | None = None,
*,
bare: bool = False,
branch: str | None = None,
description: str | None = None,
no_annex: str | None = None,
private: bool = False,
shallow: str | None = None,
quiet: bool = False,
):
"""Clone a repository/dataset into a new directory"""
annex_opt_map = {
str(AnnexNoInitMode.INIT): AnnexInitMode.OFF,
str(AnnexNoInitMode.ENABLEREMOTE): AnnexInitMode.NOENABLEREMOTE,
None: AnnexInitMode.FULL,
}
return clone_annexrepo(
source=repository,
directory=directory,
annex_init=annex_opt_map[no_annex],
bare=bare,
branch=branch,
description=description,
private=private,
shallow=shallow,
quiet=quiet,
progress_handler=None if quiet else res.progress_handler,
)