From f595f1ad9869f0042450501289a06b1bc8603e01 Mon Sep 17 00:00:00 2001 From: Captain ALM Date: Mon, 3 Jun 2024 14:04:37 +0100 Subject: [PATCH] Add signing support for tags in rabbitvcs. --- python3-pkg-rabbitvcs-git-gittyup/client.py | 51 +++++++++++++-------- 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/python3-pkg-rabbitvcs-git-gittyup/client.py b/python3-pkg-rabbitvcs-git-gittyup/client.py index 739b4d3..f9be865 100644 --- a/python3-pkg-rabbitvcs-git-gittyup/client.py +++ b/python3-pkg-rabbitvcs-git-gittyup/client.py @@ -765,6 +765,22 @@ class GittyupClient(object): self._config_set("remote \"origin\"", "url", host) self.config.write_to_path() + def _get_gpg_sig(self): + try: + config_user_signingkey = S(self._config_get_glb(("user", ), "signingkey")) + if config_user_signingkey == "": + raise KeyError() + except KeyError: + return None + + try: + config_commit_gpgsign = S(self._config_get_glb(("commit", ), "gpgsign")) + if config_commit_gpgsign == "" or config_commit_gpgsign.lower() != "true": + raise KeyError() + return config_user_signingkey + except KeyError: + return None + def commit(self, message, parents=None, committer=None, commit_time=None, commit_timezone=None, author=None, author_time=None, author_timezone=None, encoding=None, commit_all=False): @@ -817,27 +833,10 @@ class GittyupClient(object): if commit_timezone is None: commit_timezone = helper.utc_offset() - try: - config_user_signingkey = S(self._config_get_glb(("user", ), "signingkey")) - if config_user_signingkey == "": - raise KeyError() - except KeyError: - config_user_signingkey = None - - config_commit_gpgsign = "false" - if config_user_signingkey is not None: - try: - config_commit_gpgsign = S(self._config_get_glb(("commit", ), "gpgsign")) - if config_commit_gpgsign == "": - raise KeyError() - else: - config_commit_gpgsign = config_commit_gpgsign.lower() - except KeyError: - config_commit_gpgsign = "false" - config_user_signingkey = None + config_user_signingkey = self._get_gpg_sig() commit_id = None - if config_commit_gpgsign == "true": + if config_user_signingkey is not None: self.notify("GPG Signing Key: "+S(config_user_signingkey)) commit_id = self.repo.do_commit(**helper.to_bytes({ "message": message, @@ -1362,7 +1361,19 @@ class GittyupClient(object): @param revision: The revision to tag. Defaults to HEAD """ - dulwich.porcelain.tag(self.repo, name, objectish=revision, message=message) + config_user_signingkey = self._get_gpg_sig() + + if config_user_signingkey is not None: + self.notify("GPG Signing Key: "+S(config_user_signingkey)) + if hasattr(dulwich.porcelain,'tag'): + dulwich.porcelain.tag(self.repo, name, objectish=revision, message=message, sign=str(config_user_signingkey)) + else: + dulwich.porcelain.tag_create(self.repo, name, objectish=revision, message=message, sign=str(config_user_signingkey)) + else: + if hasattr(dulwich.porcelain,'tag'): + dulwich.porcelain.tag(self.repo, name, objectish=revision, message=message) + else: + dulwich.porcelain.tag_create(self.repo, name, objectish=revision, message=message) def tag_delete(self, name): """