Skip to content

Commit

Permalink
Add: Extend Git.tag to provide a gpg key, message and to force creation
Browse files Browse the repository at this point in the history
Add arguments to Git.tag method to use a specific gpg key for signing,
add a message to the tag and to force creating the tag.
  • Loading branch information
bjoernricks committed Dec 5, 2022
1 parent 9e37a37 commit 1f767dd
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
18 changes: 17 additions & 1 deletion pontos/git/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,15 +340,31 @@ def commit(
def tag(
self,
tag: str,
*,
gpg_key_id: Optional[str] = None,
message: Optional[str] = None,
force: Optional[bool] = False,
):
"""
Create a Tag
Args:
tag: Tag name to create
tag: Tag name to create.
gpg_key_id: GPG Key to sign the tag.
message: Use message to annotate the given tag.
force: True to replace an existing tag.
"""
args = ["tag"]

if gpg_key_id:
args.extend(["-u", gpg_key_id])

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

if force:
args.append("--force")

args.append(tag)

exec_git(*args, cwd=self._cwd)
Expand Down
27 changes: 27 additions & 0 deletions tests/git/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,33 @@ def test_tag(self, exec_git_mock):

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

@patch("pontos.git.git.exec_git")
def test_tag_with_gpg_key(self, exec_git_mock):
git = Git()
git.tag("test", gpg_key_id="0x123")

exec_git_mock.assert_called_once_with(
"tag", "-u", "0x123", "test", cwd=None
)

@patch("pontos.git.git.exec_git")
def test_tag_with_message(self, exec_git_mock):
git = Git()
git.tag("test", message="Tag for 123 release")

exec_git_mock.assert_called_once_with(
"tag", "-m", "Tag for 123 release", "test", cwd=None
)

@patch("pontos.git.git.exec_git")
def test_tag_with_force(self, exec_git_mock):
git = Git()
git.tag("test", force=True)

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

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

0 comments on commit 1f767dd

Please sign in to comment.