Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES/+git-remote.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added support for file git remotes
11 changes: 11 additions & 0 deletions pulp-glue/src/pulp_glue/file/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
16 changes: 12 additions & 4 deletions src/pulpcore/cli/file/remote.py
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -13,6 +13,7 @@
list_command,
name_option,
pulp_group,
pulp_option,
remote_filter_options,
remote_lookup_option,
role_command,
Expand All @@ -26,16 +27,23 @@


@pulp_group()
@type_option(choices={"file": PulpFileRemoteContext})
@type_option(choices={"file": PulpFileRemoteContext, "git": PulpFileGitRemoteContext})
def remote() -> None:
pass


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,),
),
]

Expand Down
6 changes: 5 additions & 1 deletion src/pulpcore/cli/file/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from pulp_glue.common.i18n import get_translation
from pulp_glue.file.context import (
PulpFileContentContext,
PulpFileGitRemoteContext,
PulpFileRemoteContext,
PulpFileRepositoryContext,
)
Expand Down Expand Up @@ -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 '[[<plugin>:]<resource_type>:]<name>' or by href."),
)
Expand Down
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
47 changes: 47 additions & 0 deletions tests/scripts/pulp_file/test_git_remote.sh
Original file line number Diff line number Diff line change
@@ -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"
Loading