Skip to content

Commit

Permalink
Add: Allow to disable signing for git.commit and git.tag
Browse files Browse the repository at this point in the history
Allow to create commits and tags without signing them. This is
especially useful for testing purposes.
  • Loading branch information
bjoernricks committed Aug 8, 2023
1 parent e995061 commit d6043a0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pontos/git/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ def commit(
message: str,
*,
verify: Optional[bool] = None,
gpg_sign: Optional[bool] = None,
gpg_signing_key: Optional[str] = None,
) -> None:
"""
Expand All @@ -413,13 +414,16 @@ def commit(
Args:
message: Message of the commit
verify: Set to False to skip git hooks
gpg_sign: Set to False to skip signing the commit via GPG
gpg_signing_key: GPG Key ID to use to sign the commit
"""
args = ["commit"]
if verify is False:
args.append("--no-verify")
if gpg_signing_key:
args.append(f"-S{gpg_signing_key}")
if gpg_sign is False:
args.append("--no-gpg-sign")

args.extend(["-m", message])

Expand All @@ -432,6 +436,7 @@ def tag(
gpg_key_id: Optional[str] = None,
message: Optional[str] = None,
force: Optional[bool] = False,
sign: Optional[bool] = None,
) -> None:
"""
Create a Tag
Expand All @@ -441,6 +446,7 @@ def tag(
gpg_key_id: GPG Key to sign the tag.
message: Use message to annotate the given tag.
force: True to replace an existing tag.
sign: Set to False to deactivate signing of the tag.
"""
args = ["tag"]

Expand All @@ -453,6 +459,9 @@ def tag(
if force:
args.append("--force")

if sign is False:
args.append("--no-sign")

args.append(tag)

self.exec(*args)
Expand Down
18 changes: 18 additions & 0 deletions tests/git/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,15 @@ def test_commit_without_verify(self, exec_git_mock):
"commit", "--no-verify", "-m", "Add foo", cwd=None
)

@patch("pontos.git.git.exec_git")
def test_commit_without_gpg_sign(self, exec_git_mock):
git = Git()
git.commit("Add foo", gpg_sign=False)

exec_git_mock.assert_called_once_with(
"commit", "--no-gpg-sign", "-m", "Add foo", cwd=None
)

@patch("pontos.git.git.exec_git")
def test_tag(self, exec_git_mock):
git = Git()
Expand Down Expand Up @@ -428,6 +437,15 @@ def test_tag_with_force(self, exec_git_mock):
"tag", "--force", "test", cwd=None
)

@patch("pontos.git.git.exec_git")
def test_tag_without_sign(self, exec_git_mock):
git = Git()
git.tag("test", sign=False)

exec_git_mock.assert_called_once_with(
"tag", "--no-sign", "test", cwd=None
)

@patch("pontos.git.git.exec_git")
def test_fetch(self, exec_git_mock):
git = Git()
Expand Down

0 comments on commit d6043a0

Please sign in to comment.