From 4bf23a20127ad39a2e4213fac8bf37b8d8933fb9 Mon Sep 17 00:00:00 2001 From: Gerrod Ubben Date: Mon, 16 Feb 2026 10:02:37 -0500 Subject: [PATCH] Add git file remote Generated by: cursor-compose-2.5 --- CHANGES/+git-remote.feature | 1 + pulp-glue/src/pulp_glue/file/context.py | 11 +++++ src/pulpcore/cli/file/remote.py | 16 ++++++-- src/pulpcore/cli/file/repository.py | 6 ++- tests/conftest.py | 1 + tests/scripts/pulp_file/test_git_remote.sh | 47 ++++++++++++++++++++++ 6 files changed, 77 insertions(+), 5 deletions(-) create mode 100644 CHANGES/+git-remote.feature create mode 100755 tests/scripts/pulp_file/test_git_remote.sh diff --git a/CHANGES/+git-remote.feature b/CHANGES/+git-remote.feature new file mode 100644 index 000000000..54e58977f --- /dev/null +++ b/CHANGES/+git-remote.feature @@ -0,0 +1 @@ +Added support for file git remotes diff --git a/pulp-glue/src/pulp_glue/file/context.py b/pulp-glue/src/pulp_glue/file/context.py index 181797cf8..76f88cf07 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_file_git_remote_href" + ID_PREFIX = "remotes_file_git" + CAPABILITIES = {"roles": [PluginRequirement("file", specifier=">=3.104.0")]} + NEEDS_PLUGINS = [PluginRequirement("file", specifier=">=3.104.0")] + + 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 96caf5bd1..372333287 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 ( common_remote_create_options, @@ -13,6 +13,7 @@ list_command, name_option, pulp_group, + pulp_option, remote_filter_options, remote_lookup_option, role_command, @@ -26,7 +27,7 @@ @pulp_group() -@type_option(choices={"file": PulpFileRemoteContext}) +@type_option(choices={"file": PulpFileRemoteContext, "git": PulpFileGitRemoteContext}) def remote() -> None: pass @@ -34,8 +35,15 @@ def remote() -> None: 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 5393dab14..6c00edec9 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, ) @@ -53,7 +54,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."), ) diff --git a/tests/conftest.py b/tests/conftest.py index 654095c0a..65f08e15d 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -13,6 +13,7 @@ def pulp_cli_vars(pulp_cli_vars: dict[str, str]) -> dict[str, str]: result.update( { "FILE_REMOTE_URL": urljoin(PULP_FIXTURES_URL, "/file/PULP_MANIFEST"), + "GIT_REMOTE_URL": "https://github.com/pulp/pulp-fixtures.git", "FILE_REMOTE2_URL": urljoin(PULP_FIXTURES_URL, "/file2/PULP_MANIFEST"), "FILE_LARGE_REMOTE_URL": urljoin(PULP_FIXTURES_URL, "/file-perf/PULP_MANIFEST"), "CONTAINER_REMOTE_URL": "https://quay.io", diff --git a/tests/scripts/pulp_file/test_git_remote.sh b/tests/scripts/pulp_file/test_git_remote.sh new file mode 100755 index 000000000..ee9356c1a --- /dev/null +++ b/tests/scripts/pulp_file/test_git_remote.sh @@ -0,0 +1,47 @@ +#!/bin/bash + +set -eu +# shellcheck source=tests/scripts/config.source +. "$(dirname "$(dirname "$(realpath "$0")")")"/config.source + +pulp debug has-plugin --name "file" --specifier ">=3.104.0" || exit 23 + +GIT_REMOTE_URL="${GIT_REMOTE_URL:-https://github.com/pulp/pulp-fixtures.git}" + +cleanup() { + pulp file repository destroy --name "cli_test_file_git_repo" || true + pulp file remote --type git destroy --name "cli_test_file_git_remote" || true +} +trap cleanup EXIT + +cleanup + +expect_succ pulp file remote --type git list + +expect_succ pulp file remote --type git create \ + --name "cli_test_file_git_remote" \ + --url "$GIT_REMOTE_URL" \ + --git-ref main +HREF="$(echo "$OUTPUT" | jq -r '.pulp_href')" +remote_prn="$(echo "$OUTPUT" | jq -r '.prn')" +test "$(echo "$OUTPUT" | jq -r '.git_ref')" = "main" + +expect_succ pulp file remote --type git show --remote "cli_test_file_git_remote" +expect_succ pulp file remote --type git show --remote "$HREF" +expect_succ pulp file remote --type git show --remote "${remote_prn}" + +expect_succ pulp file remote --type git list --name-contains "cli_test_file_git" +test "$(echo "$OUTPUT" | jq -r '.[0].name')" = "cli_test_file_git_remote" + +expect_succ pulp file remote --type git update --remote "$HREF" --git-ref master +expect_succ pulp file remote --type git show --remote "cli_test_file_git_remote" +test "$(echo "$OUTPUT" | jq -r '.git_ref')" = "master" + +expect_succ pulp file repository create --name "cli_test_file_git_repo" +expect_succ pulp file repository update \ + --repository "cli_test_file_git_repo" \ + --remote "file:git:cli_test_file_git_remote" +expect_succ pulp file repository show --repository "cli_test_file_git_repo" +test "$(echo "$OUTPUT" | jq -r '.remote')" = "$HREF" + +expect_succ pulp file remote --type git destroy --name "cli_test_file_git_remote"