diff --git a/pulp-glue/src/pulp_glue/file/context.py b/pulp-glue/src/pulp_glue/file/context.py index 181797cf8..00f6e423c 100644 --- a/pulp-glue/src/pulp_glue/file/context.py +++ b/pulp-glue/src/pulp_glue/file/context.py @@ -121,6 +121,17 @@ class PulpFileRemoteContext(PulpRemoteContext): NEEDS_PLUGINS = [PluginRequirement("file", specifier=">=1.6.0")] +class PulpFileGitRemoteContext(PulpRemoteContext): + PLUGIN = "file" + RESOURCE_TYPE = "git" + ENTITY = _("file git remote") + ENTITIES = _("file git remotes") + HREF = "file_git_remote_href" + ID_PREFIX = "remotes_file_git" + CAPABILITIES = {"roles": [PluginRequirement("file", specifier=">=3.104.0.dev")]} + NEEDS_PLUGINS = [PluginRequirement("file", specifier=">=3.104.0.dev")] + + class PulpFileRepositoryVersionContext(PulpRepositoryVersionContext): HREF = "file_file_repository_version_href" ID_PREFIX = "repositories_file_file_versions" diff --git a/src/pulpcore/cli/file/remote.py b/src/pulpcore/cli/file/remote.py index ac771b59d..d1f89604d 100644 --- a/src/pulpcore/cli/file/remote.py +++ b/src/pulpcore/cli/file/remote.py @@ -1,7 +1,7 @@ import click from pulp_glue.common.i18n import get_translation -from pulp_glue.file.context import PulpFileRemoteContext +from pulp_glue.file.context import PulpFileGitRemoteContext, PulpFileRemoteContext from pulp_cli.generic import ( PulpCLIContext, @@ -15,6 +15,7 @@ name_option, pass_pulp_context, pulp_group, + pulp_option, remote_filter_options, remote_lookup_option, role_command, @@ -31,7 +32,7 @@ "-t", "--type", "remote_type", - type=click.Choice(["file"], case_sensitive=False), + type=click.Choice(["file", "git"], case_sensitive=False), default="file", ) @pass_pulp_context @@ -39,6 +40,8 @@ def remote(ctx: click.Context, pulp_ctx: PulpCLIContext, /, remote_type: str) -> None: if remote_type == "file": ctx.obj = PulpFileRemoteContext(pulp_ctx) + elif remote_type == "git": + ctx.obj = PulpFileGitRemoteContext(pulp_ctx) else: raise NotImplementedError() @@ -46,8 +49,15 @@ def remote(ctx: click.Context, pulp_ctx: PulpCLIContext, /, remote_type: str) -> lookup_options = [href_option, name_option, remote_lookup_option] nested_lookup_options = [remote_lookup_option] file_remote_options = [ - click.option( - "--policy", type=click.Choice(["immediate", "on_demand", "streamed"], case_sensitive=False) + pulp_option( + "--policy", + type=click.Choice(["immediate", "on_demand", "streamed"], case_sensitive=False), + allowed_with_contexts=(PulpFileRemoteContext,), + ), + pulp_option( + "--git-ref", + help=_("The git ref (branch, tag, or commit hash) to sync from. Defaults to HEAD."), + allowed_with_contexts=(PulpFileGitRemoteContext,), ), ] diff --git a/src/pulpcore/cli/file/repository.py b/src/pulpcore/cli/file/repository.py index 4d412d9e7..a60190a98 100644 --- a/src/pulpcore/cli/file/repository.py +++ b/src/pulpcore/cli/file/repository.py @@ -12,6 +12,7 @@ from pulp_glue.common.i18n import get_translation from pulp_glue.file.context import ( PulpFileContentContext, + PulpFileGitRemoteContext, PulpFileRemoteContext, PulpFileRepositoryContext, ) @@ -54,7 +55,10 @@ "--remote", default_plugin="file", default_type="file", - context_table={"file:file": PulpFileRemoteContext}, + context_table={ + "file:file": PulpFileRemoteContext, + "file:git": PulpFileGitRemoteContext, + }, href_pattern=PulpRemoteContext.HREF_PATTERN, help=_("Remote used for syncing in the form '[[:]:]' or by href."), )