Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat(version-cmd): add toggle of--no-verify option togit commit#927

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletionsdocs/configuration.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -702,6 +702,24 @@ When :ref:`config-allow_zero_version` is set to ``false``, this setting is ignor

----

.. _config-no_git_verify:

``no_git_verify``
"""""""""""""""""

**Type:** ``bool``

This flag is passed along to ``git`` upon performing a ``git commit`` during :ref:`cmd-version`.

When true, it will bypass any git hooks that are set for the repository when Python Semantic
Release makes a version commit. When false, the commit is performed as normal. This option
has no effect when there are not any git hooks configured nor when the ``--no-commit`` option
is passed.

**Default:** ``false``

----

.. _config-publish:

``publish``
Expand Down
3 changes: 3 additions & 0 deletionssemantic_release/cli/commands/version.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -330,6 +330,7 @@ def version( # noqa: C901
commit_author = runtime.commit_author
commit_message = runtime.commit_message
major_on_zero = runtime.major_on_zero
no_verify = runtime.no_git_verify
build_command = runtime.build_command
opts = runtime.global_cli_options
gha_output = VersionGitHubActionsOutput()
Expand DownExpand Up@@ -613,6 +614,7 @@ def custom_git_environment() -> ContextManager[None]:
)

command += f"git commit -m '{indented_commit_message}'"
command += "--no-verify" if no_verify else ""

noop_report(
indented(
Expand All@@ -628,6 +630,7 @@ def custom_git_environment() -> ContextManager[None]:
repo.git.commit(
m=commit_message.format(version=new_version),
date=int(commit_date.timestamp()),
no_verify=no_verify,
)

# Run the tagging after potentially creating a new HEAD commit.
Expand Down
3 changes: 3 additions & 0 deletionssemantic_release/cli/config.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -225,6 +225,7 @@ class RawConfig(BaseModel):
major_on_zero: bool = True
allow_zero_version: bool = True
remote: RemoteConfig = RemoteConfig()
no_git_verify: bool = False
tag_format: str = "v{version}"
publish: PublishConfig = PublishConfig()
version_toml: Optional[Tuple[str, ...]] = None
Expand DownExpand Up@@ -347,6 +348,7 @@ class RuntimeContext:
major_on_zero: bool
allow_zero_version: bool
prerelease: bool
no_git_verify: bool
assets: List[str]
commit_author: Actor
commit_message: str
Expand DownExpand Up@@ -596,6 +598,7 @@ def from_raw_config(
upload_to_vcs_release=raw.publish.upload_to_vcs_release,
global_cli_options=global_cli_options,
masker=masker,
no_git_verify=raw.no_git_verify,
)
# credential masker
self.apply_log_masking(self.masker)
Expand Down
52 changes: 51 additions & 1 deletiontests/command_line/test_version.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,7 +5,9 @@
import os
import re
import shutil
from pathlib import Path
from subprocess import CompletedProcess
from textwrap import dedent
from typing import TYPE_CHECKING
from unittest import mock

Expand All@@ -24,7 +26,6 @@
)

if TYPE_CHECKING:
from pathlib import Path
from unittest.mock import MagicMock

from click.testing import CliRunner
Expand DownExpand Up@@ -547,6 +548,55 @@ def test_version_prints_current_version_if_no_new_version(
assert result.stdout == "1.2.0-alpha.2\n"


def test_version_version_no_verify(
repo_with_single_branch_angular_commits: Repo,
cli_runner: CliRunner,
update_pyproject_toml: UpdatePyprojectTomlFn,
):
# setup: set configuration setting
update_pyproject_toml("tool.semantic_release.no_git_verify", True)
repo_with_single_branch_angular_commits.git.commit(
m="chore: adjust project configuration for --no-verify release commits", a=True
)
# create executable pre-commit script
precommit_hook = Path(
repo_with_single_branch_angular_commits.git_dir, "hooks", "pre-commit"
)
precommit_hook.parent.mkdir(parents=True, exist_ok=True)
precommit_hook.write_text(
dedent(
"""\
#!/bin/sh
echo >&2 "Always fail pre-commit" && exit 1;
"""
)
)
precommit_hook.chmod(0o754)
repo_with_single_branch_angular_commits.git.config(
"core.hookspath",
str(
precommit_hook.parent.relative_to(
repo_with_single_branch_angular_commits.working_dir
)
),
local=True,
)
# Take measurement beforehand
head_before = repo_with_single_branch_angular_commits.head.commit

# Execute
result = cli_runner.invoke(
main, [version_subcmd, "--patch", "--no-tag", "--no-push"]
)

# Evaluate
head_after = repo_with_single_branch_angular_commits.head.commit

assert head_before != head_after # A commit has been made
assert head_before in repo_with_single_branch_angular_commits.head.commit.parents
assert result.exit_code == 0


@pytest.mark.parametrize("shell", ("/usr/bin/bash", "/usr/bin/zsh", "powershell"))
def test_version_runs_build_command(
repo_with_git_flow_angular_commits: Repo,
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp