diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 52049e967f..986b63f875 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -49,7 +49,7 @@ repos: - tomli - repo: https://github.com/commitizen-tools/commitizen - rev: v4.0.0 # automatically updated by Commitizen + rev: v4.1.0 # automatically updated by Commitizen hooks: - id: commitizen - id: commitizen-branch diff --git a/CHANGELOG.md b/CHANGELOG.md index c6556ab016..858f7d7181 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## v4.1.0 (2024-12-06) + +### Feat + +- **commit**: allow '-- --allow-empty' to create empty commits + ## v4.0.0 (2024-11-26) ## v3.31.0 (2024-11-16) diff --git a/commitizen/__version__.py b/commitizen/__version__.py index ce1305bf4e..7039708762 100644 --- a/commitizen/__version__.py +++ b/commitizen/__version__.py @@ -1 +1 @@ -__version__ = "4.0.0" +__version__ = "4.1.0" diff --git a/commitizen/changelog.py b/commitizen/changelog.py index 32a66c47eb..7f300354b6 100644 --- a/commitizen/changelog.py +++ b/commitizen/changelog.py @@ -29,9 +29,10 @@ import re from collections import OrderedDict, defaultdict +from collections.abc import Iterable from dataclasses import dataclass from datetime import date -from typing import TYPE_CHECKING, Iterable +from typing import TYPE_CHECKING from jinja2 import ( BaseLoader, diff --git a/commitizen/changelog_formats/restructuredtext.py b/commitizen/changelog_formats/restructuredtext.py index 09d032400c..8bcf9a4a4f 100644 --- a/commitizen/changelog_formats/restructuredtext.py +++ b/commitizen/changelog_formats/restructuredtext.py @@ -3,7 +3,7 @@ import re import sys from itertools import zip_longest -from typing import IO, TYPE_CHECKING, Any, Tuple, Union +from typing import IO, TYPE_CHECKING, Any, Union from commitizen.changelog import Metadata @@ -18,7 +18,7 @@ # Can't use `|` operator and native type because of https://bugs.python.org/issue42233 only fixed in 3.10 -TitleKind: TypeAlias = Union[str, Tuple[str, str]] +TitleKind: TypeAlias = Union[str, tuple[str, str]] class RestructuredText(BaseFormat): diff --git a/commitizen/cli.py b/commitizen/cli.py index 1e0b1c6276..2ee7d41eba 100644 --- a/commitizen/cli.py +++ b/commitizen/cli.py @@ -3,11 +3,12 @@ import argparse import logging import sys +from collections.abc import Sequence from copy import deepcopy from functools import partial from pathlib import Path from types import TracebackType -from typing import Any, Sequence +from typing import Any import argcomplete from decli import cli diff --git a/commitizen/commands/commit.py b/commitizen/commands/commit.py index 9b13a020b6..abecb3b3ca 100644 --- a/commitizen/commands/commit.py +++ b/commitizen/commands/commit.py @@ -93,6 +93,10 @@ def manual_edit(self, message: str) -> str: return message def __call__(self): + extra_args: str = self.arguments.get("extra_cli_args", "") + + allow_empty: bool = "--allow-empty" in extra_args + dry_run: bool = self.arguments.get("dry_run") write_message_to_file: bool = self.arguments.get("write_message_to_file") manual_edit: bool = self.arguments.get("edit") @@ -101,7 +105,7 @@ def __call__(self): if is_all: c = git.add("-u") - if git.is_staging_clean() and not dry_run: + if git.is_staging_clean() and not (dry_run or allow_empty): raise NothingToCommitError("No files added to staging!") if write_message_to_file is not None and write_message_to_file.is_dir(): @@ -137,8 +141,6 @@ def __call__(self): always_signoff: bool = self.config.settings["always_signoff"] signoff: bool = self.arguments.get("signoff") - extra_args = self.arguments.get("extra_cli_args", "") - if signoff: out.warn( "signoff mechanic is deprecated, please use `cz commit -- -s` instead." diff --git a/commitizen/cz/__init__.py b/commitizen/cz/__init__.py index 04603a9ec4..cb17fe32cd 100644 --- a/commitizen/cz/__init__.py +++ b/commitizen/cz/__init__.py @@ -4,7 +4,7 @@ import pkgutil import sys import warnings -from typing import Iterable +from collections.abc import Iterable if sys.version_info >= (3, 10): from importlib import metadata diff --git a/commitizen/cz/base.py b/commitizen/cz/base.py index 70929e2f83..43455a74ca 100644 --- a/commitizen/cz/base.py +++ b/commitizen/cz/base.py @@ -1,7 +1,8 @@ from __future__ import annotations from abc import ABCMeta, abstractmethod -from typing import Any, Callable, Iterable, Protocol +from collections.abc import Iterable +from typing import Any, Callable, Protocol from jinja2 import BaseLoader, PackageLoader from prompt_toolkit.styles import Style, merge_styles diff --git a/commitizen/defaults.py b/commitizen/defaults.py index 996c243196..d776e38d7a 100644 --- a/commitizen/defaults.py +++ b/commitizen/defaults.py @@ -2,7 +2,8 @@ import pathlib from collections import OrderedDict -from typing import Any, Iterable, MutableMapping, TypedDict +from collections.abc import Iterable, MutableMapping +from typing import Any, TypedDict # Type Questions = Iterable[MutableMapping[str, Any]] diff --git a/commitizen/version_schemes.py b/commitizen/version_schemes.py index 346287a065..554864e3bf 100644 --- a/commitizen/version_schemes.py +++ b/commitizen/version_schemes.py @@ -10,7 +10,6 @@ ClassVar, Literal, Protocol, - Type, cast, runtime_checkable, ) @@ -150,7 +149,7 @@ def bump( # With PEP 440 and SemVer semantic, Scheme is the type, Version is an instance Version: TypeAlias = VersionProtocol -VersionScheme: TypeAlias = Type[VersionProtocol] +VersionScheme: TypeAlias = type[VersionProtocol] class BaseVersion(_BaseVersion): diff --git a/poetry.lock b/poetry.lock index ad3607415b..973f01720b 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.8.4 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.8.3 and should not be changed by hand. [[package]] name = "argcomplete" @@ -756,13 +756,13 @@ pyyaml = ">=5.1" [[package]] name = "mkdocs-material" -version = "9.5.46" +version = "9.5.47" description = "Documentation that simply works" optional = false python-versions = ">=3.8" files = [ - {file = "mkdocs_material-9.5.46-py3-none-any.whl", hash = "sha256:98f0a2039c62e551a68aad0791a8d41324ff90c03a6e6cea381a384b84908b83"}, - {file = "mkdocs_material-9.5.46.tar.gz", hash = "sha256:ae2043f4238e572f9a40e0b577f50400d6fc31e2fef8ea141800aebf3bd273d7"}, + {file = "mkdocs_material-9.5.47-py3-none-any.whl", hash = "sha256:53fb9c9624e7865da6ec807d116cd7be24b3cb36ab31b1d1d1a9af58c56009a2"}, + {file = "mkdocs_material-9.5.47.tar.gz", hash = "sha256:fc3b7a8e00ad896660bd3a5cc12ca0cb28bdc2bcbe2a946b5714c23ac91b0ede"}, ] [package.dependencies] @@ -968,13 +968,13 @@ testing = ["pytest", "pytest-benchmark"] [[package]] name = "pre-commit" -version = "3.8.0" +version = "4.0.1" description = "A framework for managing and maintaining multi-language pre-commit hooks." optional = false python-versions = ">=3.9" files = [ - {file = "pre_commit-3.8.0-py2.py3-none-any.whl", hash = "sha256:9a90a53bf82fdd8778d58085faf8d83df56e40dfe18f45b19446e26bf1b3a63f"}, - {file = "pre_commit-3.8.0.tar.gz", hash = "sha256:8bb6494d4a20423842e198980c9ecf9f96607a07ea29549e180eef9ae80fe7af"}, + {file = "pre_commit-4.0.1-py2.py3-none-any.whl", hash = "sha256:efde913840816312445dc98787724647c65473daefe420785f885e8ed9a06878"}, + {file = "pre_commit-4.0.1.tar.gz", hash = "sha256:80905ac375958c0444c65e9cebebd948b3cdb518f335a091a670a89d652139d2"}, ] [package.dependencies] @@ -1057,13 +1057,13 @@ extra = ["pygments (>=2.12)"] [[package]] name = "pytest" -version = "8.3.3" +version = "8.3.4" description = "pytest: simple powerful testing with Python" optional = false python-versions = ">=3.8" files = [ - {file = "pytest-8.3.3-py3-none-any.whl", hash = "sha256:a6853c7375b2663155079443d2e45de913a911a11d669df02a50814944db57b2"}, - {file = "pytest-8.3.3.tar.gz", hash = "sha256:70b98107bd648308a7952b06e6ca9a50bc660be218d53c257cc1fc94fda10181"}, + {file = "pytest-8.3.4-py3-none-any.whl", hash = "sha256:50e16d954148559c9a74109af1eaf0c945ba2d8f30f0a3d3335edde19788b6f6"}, + {file = "pytest-8.3.4.tar.gz", hash = "sha256:965370d062bce11e73868e0335abac31b4d3de0e82f4007408d242b4f8610761"}, ] [package.dependencies] @@ -1079,17 +1079,17 @@ dev = ["argcomplete", "attrs (>=19.2)", "hypothesis (>=3.56)", "mock", "pygments [[package]] name = "pytest-cov" -version = "5.0.0" +version = "6.0.0" description = "Pytest plugin for measuring coverage." optional = false -python-versions = ">=3.8" +python-versions = ">=3.9" files = [ - {file = "pytest-cov-5.0.0.tar.gz", hash = "sha256:5837b58e9f6ebd335b0f8060eecce69b662415b16dc503883a02f45dfeb14857"}, - {file = "pytest_cov-5.0.0-py3-none-any.whl", hash = "sha256:4f0764a1219df53214206bf1feea4633c3b558a2925c8b59f144f682861ce652"}, + {file = "pytest-cov-6.0.0.tar.gz", hash = "sha256:fde0b595ca248bb8e2d76f020b465f3b107c9632e6a1d1705f17834c89dcadc0"}, + {file = "pytest_cov-6.0.0-py3-none-any.whl", hash = "sha256:eee6f1b9e61008bd34975a4d5bab25801eb31898b032dd55addc93e96fcaaa35"}, ] [package.dependencies] -coverage = {version = ">=5.2.1", extras = ["toml"]} +coverage = {version = ">=7.5", extras = ["toml"]} pytest = ">=4.6" [package.extras] @@ -1432,29 +1432,29 @@ jupyter = ["ipywidgets (>=7.5.1,<9)"] [[package]] name = "ruff" -version = "0.7.4" +version = "0.8.2" description = "An extremely fast Python linter and code formatter, written in Rust." optional = false python-versions = ">=3.7" files = [ - {file = "ruff-0.7.4-py3-none-linux_armv6l.whl", hash = "sha256:a4919925e7684a3f18e18243cd6bea7cfb8e968a6eaa8437971f681b7ec51478"}, - {file = "ruff-0.7.4-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:cfb365c135b830778dda8c04fb7d4280ed0b984e1aec27f574445231e20d6c63"}, - {file = "ruff-0.7.4-py3-none-macosx_11_0_arm64.whl", hash = "sha256:63a569b36bc66fbadec5beaa539dd81e0527cb258b94e29e0531ce41bacc1f20"}, - {file = "ruff-0.7.4-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:0d06218747d361d06fd2fdac734e7fa92df36df93035db3dc2ad7aa9852cb109"}, - {file = "ruff-0.7.4-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:e0cea28d0944f74ebc33e9f934238f15c758841f9f5edd180b5315c203293452"}, - {file = "ruff-0.7.4-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:80094ecd4793c68b2571b128f91754d60f692d64bc0d7272ec9197fdd09bf9ea"}, - {file = "ruff-0.7.4-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:997512325c6620d1c4c2b15db49ef59543ef9cd0f4aa8065ec2ae5103cedc7e7"}, - {file = "ruff-0.7.4-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:00b4cf3a6b5fad6d1a66e7574d78956bbd09abfd6c8a997798f01f5da3d46a05"}, - {file = "ruff-0.7.4-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:7dbdc7d8274e1422722933d1edddfdc65b4336abf0b16dfcb9dedd6e6a517d06"}, - {file = "ruff-0.7.4-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:0e92dfb5f00eaedb1501b2f906ccabfd67b2355bdf117fea9719fc99ac2145bc"}, - {file = "ruff-0.7.4-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:3bd726099f277d735dc38900b6a8d6cf070f80828877941983a57bca1cd92172"}, - {file = "ruff-0.7.4-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:2e32829c429dd081ee5ba39aef436603e5b22335c3d3fff013cd585806a6486a"}, - {file = "ruff-0.7.4-py3-none-musllinux_1_2_i686.whl", hash = "sha256:662a63b4971807623f6f90c1fb664613f67cc182dc4d991471c23c541fee62dd"}, - {file = "ruff-0.7.4-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:876f5e09eaae3eb76814c1d3b68879891d6fde4824c015d48e7a7da4cf066a3a"}, - {file = "ruff-0.7.4-py3-none-win32.whl", hash = "sha256:75c53f54904be42dd52a548728a5b572344b50d9b2873d13a3f8c5e3b91f5cac"}, - {file = "ruff-0.7.4-py3-none-win_amd64.whl", hash = "sha256:745775c7b39f914238ed1f1b0bebed0b9155a17cd8bc0b08d3c87e4703b990d6"}, - {file = "ruff-0.7.4-py3-none-win_arm64.whl", hash = "sha256:11bff065102c3ae9d3ea4dc9ecdfe5a5171349cdd0787c1fc64761212fc9cf1f"}, - {file = "ruff-0.7.4.tar.gz", hash = "sha256:cd12e35031f5af6b9b93715d8c4f40360070b2041f81273d0527683d5708fce2"}, + {file = "ruff-0.8.2-py3-none-linux_armv6l.whl", hash = "sha256:c49ab4da37e7c457105aadfd2725e24305ff9bc908487a9bf8d548c6dad8bb3d"}, + {file = "ruff-0.8.2-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:ec016beb69ac16be416c435828be702ee694c0d722505f9c1f35e1b9c0cc1bf5"}, + {file = "ruff-0.8.2-py3-none-macosx_11_0_arm64.whl", hash = "sha256:f05cdf8d050b30e2ba55c9b09330b51f9f97d36d4673213679b965d25a785f3c"}, + {file = "ruff-0.8.2-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:60f578c11feb1d3d257b2fb043ddb47501ab4816e7e221fbb0077f0d5d4e7b6f"}, + {file = "ruff-0.8.2-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:cbd5cf9b0ae8f30eebc7b360171bd50f59ab29d39f06a670b3e4501a36ba5897"}, + {file = "ruff-0.8.2-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:b402ddee3d777683de60ff76da801fa7e5e8a71038f57ee53e903afbcefdaa58"}, + {file = "ruff-0.8.2-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:705832cd7d85605cb7858d8a13d75993c8f3ef1397b0831289109e953d833d29"}, + {file = "ruff-0.8.2-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:32096b41aaf7a5cc095fa45b4167b890e4c8d3fd217603f3634c92a541de7248"}, + {file = "ruff-0.8.2-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:e769083da9439508833cfc7c23e351e1809e67f47c50248250ce1ac52c21fb93"}, + {file = "ruff-0.8.2-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:5fe716592ae8a376c2673fdfc1f5c0c193a6d0411f90a496863c99cd9e2ae25d"}, + {file = "ruff-0.8.2-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:81c148825277e737493242b44c5388a300584d73d5774defa9245aaef55448b0"}, + {file = "ruff-0.8.2-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:d261d7850c8367704874847d95febc698a950bf061c9475d4a8b7689adc4f7fa"}, + {file = "ruff-0.8.2-py3-none-musllinux_1_2_i686.whl", hash = "sha256:1ca4e3a87496dc07d2427b7dd7ffa88a1e597c28dad65ae6433ecb9f2e4f022f"}, + {file = "ruff-0.8.2-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:729850feed82ef2440aa27946ab39c18cb4a8889c1128a6d589ffa028ddcfc22"}, + {file = "ruff-0.8.2-py3-none-win32.whl", hash = "sha256:ac42caaa0411d6a7d9594363294416e0e48fc1279e1b0e948391695db2b3d5b1"}, + {file = "ruff-0.8.2-py3-none-win_amd64.whl", hash = "sha256:2aae99ec70abf43372612a838d97bfe77d45146254568d94926e8ed5bbb409ea"}, + {file = "ruff-0.8.2-py3-none-win_arm64.whl", hash = "sha256:fb88e2a506b70cfbc2de6fae6681c4f944f7dd5f2fe87233a7233d888bad73e8"}, + {file = "ruff-0.8.2.tar.gz", hash = "sha256:b84f4f414dda8ac7f75075c1fa0b905ac0ff25361f42e6d5da681a465e0f78e5"}, ] [[package]] @@ -1779,4 +1779,4 @@ type = ["pytest-mypy"] [metadata] lock-version = "2.0" python-versions = ">=3.9" -content-hash = "a26dd45789ef8d0cc79465fe620060d29bde139d45a70885a80c413dd668dc81" +content-hash = "36ac305c62f5139da82126a1b3bc71f86320af1abab5c473b3c0d21c81e214bd" diff --git a/pyproject.toml b/pyproject.toml index b15581952e..e1b884f479 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,15 +1,15 @@ [tool.commitizen] -version = "4.0.0" +version = "4.1.0" tag_format = "v$version" version_files = [ - "pyproject.toml:version", - "commitizen/__version__.py", - ".pre-commit-config.yaml:rev:.+Commitizen", + "pyproject.toml:version", + "commitizen/__version__.py", + ".pre-commit-config.yaml:rev:.+Commitizen", ] [tool.poetry] name = "commitizen" -version = "4.0.0" +version = "4.1.0" description = "Python commitizen client tool" authors = ["Santiago Fraire "] license = "MIT" @@ -32,10 +32,7 @@ classifiers = [ "Programming Language :: Python :: 3.13", "Programming Language :: Python :: Implementation :: CPython", ] -packages = [ - {include = "commitizen"}, - {include = "commitizen/py.typed"}, -] +packages = [{ include = "commitizen" }, { include = "commitizen/py.typed" }] [tool.poetry.dependencies] python = ">=3.9" @@ -51,21 +48,21 @@ argcomplete = ">=1.12.1,<3.6" typing-extensions = { version = "^4.0.1", python = "<3.11" } charset-normalizer = ">=2.1.0,<4" # Use the Python 3.11 and 3.12 compatible API: https://github.com/python/importlib_metadata#compatibility -importlib_metadata = { version = ">=8.0.0,<9", python = "<3.10"} +importlib_metadata = { version = ">=8.0.0,<9", python = "<3.10" } [tool.poetry.group.dev.dependencies] # dev tool ipython = "^8.0" # test pytest = ">=7.2,<9.0" -pytest-cov = ">=4,<6" +pytest-cov = ">=4,<7" pytest-mock = "^3.10" pytest-regressions = "^2.4.0" pytest-freezer = "^0.4.6" pytest-xdist = "^3.1.0" # linter -ruff = ">=0.5.0,<0.8.0" -pre-commit = ">=2.18,<4.0" +ruff = ">=0.5.0,<0.9.0" +pre-commit = ">=2.18,<5.0" mypy = "^1.4" types-PyYAML = ">=5.4.3,<7.0.0" types-termcolor = "^0.1.1" @@ -108,33 +105,33 @@ semver = "commitizen.version_schemes:SemVer" semver2 = "commitizen.version_schemes:SemVer2" [tool.coverage] - [tool.coverage.report] - show_missing = true - exclude_lines = [ - # Have to re-enable the standard pragma - 'pragma: no cover', - - # Don't complain about missing debug-only code: - 'def __repr__', - 'if self\.debug', - - # Don't complain if tests don't hit defensive assertion code: - 'raise AssertionError', - 'raise NotImplementedError', - - # Don't complain if non-runnable code isn't run: - 'if 0:', - 'if __name__ == .__main__.:', - 'if TYPE_CHECKING:', - ] - omit = [ - 'env/*', - 'venv/*', - '.venv/*', - '*/virtualenv/*', - '*/virtualenvs/*', - '*/tests/*', - ] +[tool.coverage.report] +show_missing = true +exclude_lines = [ + # Have to re-enable the standard pragma + 'pragma: no cover', + + # Don't complain about missing debug-only code: + 'def __repr__', + 'if self\.debug', + + # Don't complain if tests don't hit defensive assertion code: + 'raise AssertionError', + 'raise NotImplementedError', + + # Don't complain if non-runnable code isn't run: + 'if 0:', + 'if __name__ == .__main__.:', + 'if TYPE_CHECKING:', +] +omit = [ + 'env/*', + 'venv/*', + '.venv/*', + '*/virtualenv/*', + '*/virtualenvs/*', + '*/tests/*', +] [build-system] requires = ["poetry_core>=1.0.0"] @@ -157,11 +154,7 @@ select = [ # isort "I", ] -ignore = [ - "E501", - "D1", - "D415" -] +ignore = ["E501", "D1", "D415"] [tool.ruff.lint.isort] known-first-party = ["commitizen", "tests"] @@ -179,7 +172,7 @@ warn_unused_ignores = true warn_unused_configs = true [[tool.mypy.overrides]] -module = "py.*" # Legacy pytest dependencies +module = "py.*" # Legacy pytest dependencies ignore_missing_imports = true [tool.codespell] diff --git a/tests/commands/test_commit_command.py b/tests/commands/test_commit_command.py index 85959abe33..55751f6902 100644 --- a/tests/commands/test_commit_command.py +++ b/tests/commands/test_commit_command.py @@ -324,6 +324,55 @@ def test_commit_when_nothing_to_commit(config, mocker: MockFixture): assert "No files added to staging!" in str(excinfo.value) +@pytest.mark.usefixtures("staging_is_clean") +def test_commit_with_allow_empty(config, mocker: MockFixture): + prompt_mock = mocker.patch("questionary.prompt") + prompt_mock.return_value = { + "prefix": "feat", + "subject": "user created", + "scope": "", + "is_breaking_change": False, + "body": "closes #21", + "footer": "", + } + + commit_mock = mocker.patch("commitizen.git.commit") + commit_mock.return_value = cmd.Command("success", "", b"", b"", 0) + success_mock = mocker.patch("commitizen.out.success") + + commands.Commit(config, {"extra_cli_args": "--allow-empty"})() + + commit_mock.assert_called_with( + "feat: user created\n\ncloses #21", args="--allow-empty" + ) + success_mock.assert_called_once() + + +@pytest.mark.usefixtures("staging_is_clean") +def test_commit_with_signoff_and_allow_empty(config, mocker: MockFixture): + prompt_mock = mocker.patch("questionary.prompt") + prompt_mock.return_value = { + "prefix": "feat", + "subject": "user created", + "scope": "", + "is_breaking_change": False, + "body": "closes #21", + "footer": "", + } + + commit_mock = mocker.patch("commitizen.git.commit") + commit_mock.return_value = cmd.Command("success", "", b"", b"", 0) + success_mock = mocker.patch("commitizen.out.success") + + config.settings["always_signoff"] = True + commands.Commit(config, {"extra_cli_args": "--allow-empty"})() + + commit_mock.assert_called_with( + "feat: user created\n\ncloses #21", args="--allow-empty -s" + ) + success_mock.assert_called_once() + + @pytest.mark.usefixtures("staging_is_clean") def test_commit_when_customized_expected_raised(config, mocker: MockFixture, capsys): _err = ValueError() diff --git a/tests/conftest.py b/tests/conftest.py index 95f3df3b20..1e6bc15f0c 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -3,8 +3,8 @@ import os import re import tempfile +from collections.abc import Iterator from pathlib import Path -from typing import Iterator import pytest from pytest_mock import MockerFixture diff --git a/tests/providers/conftest.py b/tests/providers/conftest.py index b4432ca524..f73cdb72a5 100644 --- a/tests/providers/conftest.py +++ b/tests/providers/conftest.py @@ -1,8 +1,8 @@ from __future__ import annotations import os +from collections.abc import Iterator from pathlib import Path -from typing import Iterator import pytest