Skip to content

Commit d5d4eed

Browse files
committed
commit: add support to enable/disable gpg signing
You can use "--gpg-sign" and "--no-gpg-sign" to enable/disable gpg signing. If you don't specify any of them, pkgdev will use the value listed in metadata/layout.conf. You can also set this in configuration, using `commit.no-gpg-sign=` or `commit.gpg-sign=`. Resolves: #146 Signed-off-by: Arthur Zamarin <[email protected]>
1 parent 9e8b9c8 commit d5d4eed

File tree

4 files changed

+34
-1
lines changed

4 files changed

+34
-1
lines changed

data/share/bash-completion/completions/pkgdev

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ _pkgdev() {
7575
-A --ask
7676
--mangle
7777
--signoff
78+
--gpg-sign --no-gpg-sign
7879
-m --message
7980
-M --message-template
8081
-e --edit

data/share/zsh/site-functions/_pkgdev

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ case $state in
4848
{'(--ask)-A','(-A)--ask'}'[confirm creating commit with QA errors]' \
4949
'--mangle[forcibly enable/disable file mangling]' \
5050
'--signoff[add a Signed-off-by trailer]' \
51+
'--gpg-sign[enable GPG signing]' \
52+
'--no-gpg-sign[disable GPG signing]' \
5153
\*{--message,-m}'[specify commit message]:message' \
5254
{'(--message-template)-M','(-M)--message-template'}'[use commit message template from specified file]:template:_files' \
5355
{'(--edit)-e','(-e)--edit'}'[force edit of commit]' \

src/pkgdev/scripts/pkgdev_commit.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,16 @@ def __call__(self, parser, namespace, value, option_string=None):
161161
Signed-off-by line containing the committer's legal name.
162162
""",
163163
)
164+
commit_opts.add_argument(
165+
"--gpg-sign",
166+
action=argparse.BooleanOptionalAction,
167+
help="GPG-sign commit",
168+
docs="""
169+
Pass ``--gpg-sign`` or ``--no-gpg-sign`` to the ``git commit`` command.
170+
This option enables to override the default behavior or the behavior
171+
defined by ``sign-commits = true`` in ``metadata/layout.conf`` file.
172+
""",
173+
)
164174
commit_opts.add_argument(
165175
"-d",
166176
"--distdir",
@@ -832,7 +842,9 @@ def _commit_validate(parser, namespace):
832842
namespace.scan_args.extend(shlex.split(namespace.pkgcheck_scan))
833843
namespace.scan_args.extend(["--exit", "GentooCI", "--staged"])
834844

835-
if namespace.repo.config.sign_commits:
845+
if namespace.gpg_sign is False:
846+
namespace.commit_args.append("--no-gpg-sign")
847+
elif namespace.gpg_sign is True or namespace.repo.config.sign_commits:
836848
namespace.commit_args.append("--gpg-sign")
837849

838850

tests/scripts/test_pkgdev_commit.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,15 @@ def test_commit_signing(self, repo, make_git_repo, tool):
5858
options, _ = tool.parse_args(["commit", "-u", "--signoff"])
5959
assert "--signoff" in options.commit_args
6060
assert "--gpg-sign" not in options.commit_args
61+
# enable using specific argument
62+
with chdir(repo.location):
63+
options, _ = tool.parse_args(["commit", "-u", "--gpg-sign"])
64+
assert "--signoff" not in options.commit_args
65+
assert "--gpg-sign" in options.commit_args
66+
67+
options, _ = tool.parse_args(["commit", "-u", "--signoff", "--gpg-sign"])
68+
assert "--signoff" in options.commit_args
69+
assert "--gpg-sign" in options.commit_args
6170
# signed commits enabled by layout.conf setting
6271
with open(pjoin(git_repo.path, "metadata/layout.conf"), "a+") as f:
6372
f.write("sign-commits = true\n")
@@ -69,6 +78,15 @@ def test_commit_signing(self, repo, make_git_repo, tool):
6978
options, _ = tool.parse_args(["commit", "-u", "--signoff"])
7079
assert "--signoff" in options.commit_args
7180
assert "--gpg-sign" in options.commit_args
81+
# disable using specific argument
82+
with chdir(repo.location):
83+
options, _ = tool.parse_args(["commit", "-u", "--no-gpg-sign"])
84+
assert "--signoff" not in options.commit_args
85+
assert "--gpg-sign" not in options.commit_args
86+
87+
options, _ = tool.parse_args(["commit", "-u", "--signoff", "--no-gpg-sign"])
88+
assert "--signoff" in options.commit_args
89+
assert "--gpg-sign" not in options.commit_args
7290

7391
def test_git_commit_args(self, repo, make_git_repo, tool):
7492
git_repo = make_git_repo(repo.location)

0 commit comments

Comments
 (0)