From 52517259fe372235045449e2fd0fc14e57f292d1 Mon Sep 17 00:00:00 2001 From: James Kunstle Date: Jul 21 2021 20:42:24 +0000 Subject: Added 'remote' to rpkg from rhpkg Users wanted the ability to add packages as remote easily between different OS targets. e.g. if one was updating a package for Fedora, they might want to add the same package, or another package, targetted for RHEL as a remote. This change adds this functionality, accomodating both centpkg and fedpkg package repositories. The intended functionality of this feature already exists in a limited form in rhpkg, which will override the work done in this change. Fixes: https://pagure.io/fedpkg/issue/439 Jira: RHELCMP-5411 Significant contribution by onosek@redhat.com Signed-off-by: James Kunstle --- diff --git a/etc/bash_completion.d/rpkg.bash b/etc/bash_completion.d/rpkg.bash index c7f0880..b804a2e 100644 --- a/etc/bash_completion.d/rpkg.bash +++ b/etc/bash_completion.d/rpkg.bash @@ -35,7 +35,7 @@ _rpkg() local options="--help -v -q" local options_value="--release --user --path" local commands="build chain-build ci clean clog clone co container-build container-build-config commit compile copr-build diff flatpak-build \ - gimmespec giturl help gitbuildhash import install lint local mockbuild mock-config new new-sources patch prep pull push retire scratch-build sources \ + gimmespec giturl help gitbuildhash import install lint local mockbuild mock-config new new-sources patch prep pull push retire remote scratch-build sources \ srpm switch-branch tag unused-patches upload verify-files verrel" # parse main options and get command @@ -195,6 +195,9 @@ _rpkg() retire) after_more=true ;; + remote) + options="--repo-name --remote-name" + ;; scratch-build) options="--nowait --background --md5" options_target="--target" diff --git a/pyrpkg/__init__.py b/pyrpkg/__init__.py index a7d834d..4fb0362 100644 --- a/pyrpkg/__init__.py +++ b/pyrpkg/__init__.py @@ -4051,3 +4051,20 @@ class Commands(object): raise rpkgError( 'The following error occurred while trying to determine the ' 'API versions supported by MBS: {0}'.format(error_msg)) + + def remote(self, remote_name, repo_name): + """Add remote pointing repository from remote dist-git service + + Simply a wrapper on 'git remote ...' interface that uses + internal values to get package-specific target URL. + + :param str remote_name: chosen name for remote + :param str repo_name: remote repository name. If remote repository has + same name as current repository, repo_name can be None + """ + + # gets the dist-git url for the project in the current folder. + anongiturl = self._get_namespace_anongiturl(repo_name or self.ns_repo_name) + + self._run_command(['git', 'remote', 'add', remote_name, anongiturl]) + self._run_command(['git', 'fetch', remote_name]) diff --git a/pyrpkg/cli.py b/pyrpkg/cli.py index 2bcfc6f..79b4abc 100644 --- a/pyrpkg/cli.py +++ b/pyrpkg/cli.py @@ -416,6 +416,7 @@ class cliClient(object): self.register_prep() self.register_pull() self.register_push() + self.register_remote() self.register_remove_side_tag() self.register_request_side_tag() self.register_retire() @@ -1309,6 +1310,47 @@ class cliClient(object): push_parser.add_argument('--force', '-f', help='Force push', action='store_true') push_parser.set_defaults(command=self.push) + def register_remote(self): + """ + Add command remote and options + Experimental function + """ + remote_parser = self.subparsers.add_parser( + 'remote', + help='Add repository from remote dist-git services.' + 'This is an experimental interface derived from rhpkg.' + 'Please note that some or all current functionality is subject to change.') + + remote_subparsers = remote_parser.add_subparsers( + dest='remote_action', + description='Adds dist-git remote by package name.' + 'Resolves URL to RPM repo automatically.') + + remote_add_parser = remote_subparsers.add_parser( + 'add', + description='Add a new repository from remote dist-git service ' + 'to the current repository.') + + default_remote_name = self.name + + if self.config.has_option(self.name, 'default_remote_name'): + default_remote_name = self.config.get(self.name, 'default_remote_name') + + # the default remote name is either set as something specific or it's + # an empty string, and if it's an empty string we set it to the default. + if default_remote_name == '': + default_remote_name = self.name + + remote_add_parser.add_argument( + '--remote-name', + help='User can set own name for remote; Default value={}.'.format(default_remote_name), + default=default_remote_name) + remote_add_parser.add_argument( + '--repo-name', + help='Specify repo to add from source; Default to repo in working directory.') + + remote_parser.set_defaults(command=self.remote) + def register_remove_side_tag(self): """Register remove-side-tag command.""" parser = self.subparsers.add_parser( @@ -2543,6 +2585,18 @@ class cliClient(object): 'credential.useHttpPath': 'true'} self.cmd.push(getattr(self.args, 'force', False), extra_config) + def remote(self): + """Handle command remote""" + # will be in self.args by default if not user specified by the + # --remote-name flag. + if ("remote_name" in vars(self.args)): + self.cmd.remote(self.args.remote_name, # name for remote + self.args.repo_name) # name of package; + else: + # not overloading the function of "<> remote", + # expecting that this will show the current remotes. + self.cmd._run_command(["git", "remote", "-v"]) + def remove_side_tag(self): self.cmd.remove_side_tag(self.args.TAG) print("Tag deleted.")