diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2a7cc5672b..9ff73d544d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -56,7 +56,7 @@ repos: - tomli - repo: https://github.com/commitizen-tools/commitizen - rev: v4.12.1 # automatically updated by Commitizen + rev: v4.13.1 # automatically updated by Commitizen hooks: - id: commitizen - id: commitizen-branch diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c7b7598c8..15d690d15a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,30 @@ +## v4.13.1 (2026-02-03) + +### Refactor + +- **config**: replace is_empty_config with contains_commitizen_section, improve multi config resolution algorithm (#1842) + +## v4.13.0 (2026-02-01) + +### Feat + +- **bump**: add --version-files-only and deprecate --files-only (#1802) +- **version**: add --tag tag to version command (#1819) +- **cli**: add description when choosing a commit rule (#1825) +- **tags**: enable version schemes with less than 3 components (#1705) + +### Fix + +- **config**: include pyproject.toml in multi config file warning (#1803) +- add pytest ruff rule PT and fix missing deprecation warning (#1826) +- **message_length_limit**: align the behavior of message_length_limit (#1813) +- **cli**: capitalize the first characters of help texts and fix minor grammar errors + +### Refactor + +- replace hard-coded string "cz_conventional_commits" with DEFAULT_SETTINGS (#1830) +- **bump**: fix unbounded variable type issue + ## v4.12.1 (2026-01-22) ### Fix diff --git a/commitizen/__version__.py b/commitizen/__version__.py index 33111828cc..ab9d6f875c 100644 --- a/commitizen/__version__.py +++ b/commitizen/__version__.py @@ -1 +1 @@ -__version__ = "4.12.1" +__version__ = "4.13.1" diff --git a/commitizen/config/__init__.py b/commitizen/config/__init__.py index ae980af9c0..85414496f7 100644 --- a/commitizen/config/__init__.py +++ b/commitizen/config/__init__.py @@ -13,23 +13,17 @@ def _resolve_config_candidates() -> list[BaseConfig]: git_project_root = git.find_git_project_root() cfg_search_paths = [Path(".")] - if git_project_root and not cfg_search_paths[0].samefile(git_project_root): + if git_project_root and cfg_search_paths[0].resolve() != git_project_root.resolve(): cfg_search_paths.append(git_project_root) - # The following algorithm is ugly, but we need to ensure that the order of the candidates are preserved before v5. - # Also, the number of possible config files is limited, so the complexity is not a problem. candidates: list[BaseConfig] = [] for dir in cfg_search_paths: for filename in defaults.CONFIG_FILES: - out_path = dir / Path(filename) - if ( - out_path.exists() - and not any( - out_path.samefile(candidate.path) for candidate in candidates - ) - and not (conf := _create_config_from_path(out_path)).is_empty_config - ): - candidates.append(conf) + out_path = dir / filename + if out_path.is_file(): + conf = _create_config_from_path(out_path) + if conf.contains_commitizen_section(): + candidates.append(conf) return candidates @@ -43,10 +37,10 @@ def _create_config_from_path(path: Path) -> BaseConfig: def read_cfg(filepath: str | None = None) -> BaseConfig: if filepath is not None: conf_path = Path(filepath) - if not conf_path.exists(): + if not conf_path.is_file(): raise ConfigFileNotFound() conf = _create_config_from_path(conf_path) - if conf.is_empty_config: + if not conf.contains_commitizen_section(): raise ConfigFileIsEmpty() return conf diff --git a/commitizen/config/base_config.py b/commitizen/config/base_config.py index 98270915d8..f100cf9953 100644 --- a/commitizen/config/base_config.py +++ b/commitizen/config/base_config.py @@ -17,10 +17,16 @@ class BaseConfig: def __init__(self) -> None: - self.is_empty_config = False self._settings: Settings = DEFAULT_SETTINGS.copy() self._path: Path | None = None + def contains_commitizen_section(self) -> bool: + """Check if the config file contains a commitizen section. + + The implementation is different for each config file type. + """ + raise NotImplementedError() + @property def settings(self) -> Settings: return self._settings diff --git a/commitizen/config/json_config.py b/commitizen/config/json_config.py index 860ca8ed5a..3951c52854 100644 --- a/commitizen/config/json_config.py +++ b/commitizen/config/json_config.py @@ -25,6 +25,11 @@ def __init__(self, *, data: bytes | str, path: Path) -> None: self.path = path self._parse_setting(data) + def contains_commitizen_section(self) -> bool: + with self.path.open("rb") as json_file: + config_doc = json.load(json_file) + return config_doc.get("commitizen") is not None + def init_empty_config_content(self) -> None: with smart_open( self.path, "a", encoding=self._settings["encoding"] @@ -32,7 +37,7 @@ def init_empty_config_content(self) -> None: json.dump({"commitizen": {}}, json_file) def set_key(self, key: str, value: object) -> Self: - with open(self.path, "rb") as f: + with self.path.open("rb") as f: config_doc = json.load(f) config_doc["commitizen"][key] = value @@ -59,4 +64,4 @@ def _parse_setting(self, data: bytes | str) -> None: try: self.settings.update(doc["commitizen"]) except KeyError: - self.is_empty_config = True + pass diff --git a/commitizen/config/toml_config.py b/commitizen/config/toml_config.py index b10cf9bd3e..ed0bf73efb 100644 --- a/commitizen/config/toml_config.py +++ b/commitizen/config/toml_config.py @@ -26,6 +26,11 @@ def __init__(self, *, data: bytes | str, path: Path) -> None: self.path = path self._parse_setting(data) + def contains_commitizen_section(self) -> bool: + with self.path.open("rb") as f: + config_doc = parse(f.read()) + return config_doc.get("tool", {}).get("commitizen") is not None + def init_empty_config_content(self) -> None: config_doc = TOMLDocument() if os.path.isfile(self.path): @@ -67,4 +72,4 @@ def _parse_setting(self, data: bytes | str) -> None: try: self.settings.update(doc["tool"]["commitizen"]) # type: ignore[index,typeddict-item] # TODO: fix this except exceptions.NonExistentKey: - self.is_empty_config = True + pass diff --git a/commitizen/config/yaml_config.py b/commitizen/config/yaml_config.py index 58722d0f60..dd1c2c6308 100644 --- a/commitizen/config/yaml_config.py +++ b/commitizen/config/yaml_config.py @@ -32,6 +32,11 @@ def init_empty_config_content(self) -> None: ) as json_file: yaml.dump({"commitizen": {}}, json_file, explicit_start=True) + def contains_commitizen_section(self) -> bool: + with self.path.open("rb") as yaml_file: + config_doc = yaml.load(yaml_file, Loader=yaml.FullLoader) + return config_doc.get("commitizen") is not None + def _parse_setting(self, data: bytes | str) -> None: """We expect to have a section in cz.yaml looking like @@ -40,8 +45,6 @@ def _parse_setting(self, data: bytes | str) -> None: name: cz_conventional_commits ``` """ - import yaml.scanner - try: doc = yaml.safe_load(data) except yaml.YAMLError as e: @@ -50,7 +53,7 @@ def _parse_setting(self, data: bytes | str) -> None: try: self.settings.update(doc["commitizen"]) except (KeyError, TypeError): - self.is_empty_config = True + pass def set_key(self, key: str, value: object) -> Self: with open(self.path, "rb") as yaml_file: diff --git a/docs/images/cli_help/cz___help.svg b/docs/images/cli_help/cz___help.svg index ae9a135743..64b79fc0bb 100644 --- a/docs/images/cli_help/cz___help.svg +++ b/docs/images/cli_help/cz___help.svg @@ -19,136 +19,136 @@ font-weight: 700; } - .terminal-1688774822-matrix { + .terminal-199999382-matrix { font-family: Fira Code, monospace; font-size: 20px; line-height: 24.4px; font-variant-east-asian: full-width; } - .terminal-1688774822-title { + .terminal-199999382-title { font-size: 18px; font-weight: bold; font-family: arial; } - .terminal-1688774822-r1 { fill: #c5c8c6 } -.terminal-1688774822-r2 { fill: #c5c8c6;font-weight: bold } -.terminal-1688774822-r3 { fill: #d0b344 } -.terminal-1688774822-r4 { fill: #1984e9;text-decoration: underline; } -.terminal-1688774822-r5 { fill: #68a0b3;font-weight: bold } + .terminal-199999382-r1 { fill: #c5c8c6 } +.terminal-199999382-r2 { fill: #c5c8c6;font-weight: bold } +.terminal-199999382-r3 { fill: #d0b344 } +.terminal-199999382-r4 { fill: #1984e9;text-decoration: underline; } +.terminal-199999382-r5 { fill: #68a0b3;font-weight: bold } - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -160,46 +160,46 @@ - + - - $ cz --help -usage: cz [-h][--config CONFIG][--debug][-n NAME][-nr NO_RAISE] -{init,commit,c,ls,example,info,schema,bump,changelog,ch,check,version} -... - -Commitizen is a powerful release management tool that helps teams maintain  -consistent and meaningful commit messages while automating version management. -For more information, please visit https://commitizen-tools.github.io/commitizen - -options: -  -h, --help            show this help message and exit -  --config CONFIG       the path of configuration file -  --debug               use debug mode -  -n NAME, --name NAME  use the given commitizen (default: -                        cz_conventional_commits) -  -nr NO_RAISE, --no-raise NO_RAISE -                        comma separated error codes that won't raise error, -                        e.g: cz -nr 1,2,3 bump. See codes at -https://commitizen- -                        tools.github.io/commitizen/exit_codes/ - -commands: -{init,commit,c,ls,example,info,schema,bump,changelog,ch,check,version} -    init                init commitizen configuration -    commit (c)          create new commit -    ls                  show available commitizens -    example             show commit example -    info                show information about the cz -    schema              show commit schema -    bump                bump semantic version based on the git log -    changelog (ch)      generate changelog (note that it will overwrite -                        existing file) -    check               validates that a commit message matches the commitizen -                        schema -    version             get the version of the installed commitizen or the -                        current project (default: installed commitizen) - + + $ cz --help +usage: cz [-h][--config CONFIG][--debug][-n NAME][-nr NO_RAISE] +{init,commit,c,ls,example,info,schema,bump,changelog,ch,check,version} +... + +Commitizen is a powerful release management tool that helps teams maintain  +consistent and meaningful commit messages while automating version management. +For more information, please visit https://commitizen-tools.github.io/commitizen + +options: +  -h, --help            show this help message and exit +  --config CONFIG       The path to the configuration file. +  --debug               Use debug mode. +  -n NAME, --name NAME  Use the given commitizen (default: +                        cz_conventional_commits). +  -nr NO_RAISE, --no-raise NO_RAISE +                        Comma-separated error codes that won't raise error, +                        e.g., cz -nr 1,2,3 bump. See codes at +https://commitizen- +                        tools.github.io/commitizen/exit_codes/ + +commands: +{init,commit,c,ls,example,info,schema,bump,changelog,ch,check,version} +    init                Initialize commitizen configuration. +    commit (c)          Create new commit. +    ls                  Show available Commitizens. +    example             Show commit example. +    info                Show information about the cz. +    schema              Show commit schema. +    bump                Bump semantic version based on the git log. +    changelog (ch)      Generate changelog (note that it will overwrite +                        existing files). +    check               Validate that a commit message matches the commitizen +                        schema. +    version             Get the version of the installed commitizen or the +                        current project (default: installed commitizen). + diff --git a/docs/images/cli_help/cz_bump___help.svg b/docs/images/cli_help/cz_bump___help.svg index dff62998d2..ec6b4816f1 100644 --- a/docs/images/cli_help/cz_bump___help.svg +++ b/docs/images/cli_help/cz_bump___help.svg @@ -1,4 +1,4 @@ - + - - + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + + + + + + + + + + + + + + + + - + - + - - $ cz bump --help -usage: cz bump [-h][--dry-run][--files-only][--local-version][--changelog] -[--no-verify][--yes][--tag-format TAG_FORMAT] -[--bump-message BUMP_MESSAGE][--prerelease {alpha,beta,rc}] -[--devrelease DEVRELEASE][--increment {MAJOR,MINOR,PATCH}] -[--increment-mode {linear,exact}][--check-consistency] -[--annotated-tag] -[--annotated-tag-message ANNOTATED_TAG_MESSAGE][--gpg-sign] -[--changelog-to-stdout][--git-output-to-stderr][--retry] -[--major-version-zero][--template TEMPLATE][--extra EXTRA] -[--file-name FILE_NAME][--prerelease-offset PRERELEASE_OFFSET] -[--version-scheme {pep440,semver,semver2}] -[--version-type {pep440,semver,semver2}] -[--build-metadata BUILD_METADATA][--get-next] -[--allow-no-commit] -[MANUAL_VERSION] - -bump semantic version based on the git log - -positional arguments: -  MANUAL_VERSION        bump to the given version (e.g: 1.5.3) - -options: -  -h, --help            show this help message and exit -  --dry-run             show output to stdout, no commit, no modified files -  --files-only          bump version in the files from the config -  --local-version       bump only the local version portion -  --changelog, -ch      generate the changelog for the newest version -  --no-verify           this option bypasses the pre-commit and commit-msg -                        hooks -  --yes                 accept automatically questions done -  --tag-format TAG_FORMAT -                        the format used to tag the commit and read it, use it -                        in existing projects, wrap around simple quotes -  --bump-message BUMP_MESSAGE -                        template used to create the release commit, useful -                        when working with CI -  --prerelease {alpha,beta,rc}, -pr {alpha,beta,rc} -                        choose type of prerelease -  --devrelease DEVRELEASE, -d DEVRELEASE -                        specify non-negative integer for dev. release -  --increment {MAJOR,MINOR,PATCH} -                        manually specify the desired increment -  --increment-mode {linear,exact} -                        set the method by which the new version is chosen. -'linear'(default) guesses the next version based on -                        typical linear version progression, such that bumping -                        of a pre-release with lower precedence than the -                        current pre-release phase maintains the current phase -                        of higher precedence. 'exact' applies the changes that -                        have been specified (or determined from the commit -                        log) without interpretation, such that the increment -                        and pre-release are always honored -  --check-consistency, -cc -                        check consistency among versions defined in commitizen -                        configuration and version_files -  --annotated-tag, -at  create annotated tag instead of lightweight one -  --annotated-tag-message ANNOTATED_TAG_MESSAGE, -atm ANNOTATED_TAG_MESSAGE -                        create annotated tag message -  --gpg-sign, -s        sign tag instead of lightweight one -  --changelog-to-stdout -                        Output changelog to the stdout -  --git-output-to-stderr -                        Redirect git output to stderr -  --retry               retry commit if it fails the 1st time -  --major-version-zero  keep major version at zero, even for breaking changes -  --template TEMPLATE, -t TEMPLATE -                        changelog template file name (relative to the current -                        working directory) -  --extra EXTRA, -e EXTRA -                        a changelog extra variable (in the form 'key=value') -  --file-name FILE_NAME -                        file name of changelog (default: 'CHANGELOG.md') -  --prerelease-offset PRERELEASE_OFFSET -                        start pre-releases with this offset -  --version-scheme {pep440,semver,semver2} -                        choose version scheme -  --version-type {pep440,semver,semver2} -                        Deprecated, use --version-scheme instead -  --build-metadata BUILD_METADATA -                        Add additional build-metadata to the version-number -  --get-next            Determine the next version and write to stdout -  --allow-no-commit     bump version without eligible commits - + + $ cz bump --help +usage: cz bump [-h][--dry-run][--files-only][--version-files-only] +[--local-version][--changelog][--no-verify][--yes] +[--tag-format TAG_FORMAT][--bump-message BUMP_MESSAGE] +[--prerelease {alpha,beta,rc}][--devrelease DEVRELEASE] +[--increment {MAJOR,MINOR,PATCH}] +[--increment-mode {linear,exact}][--check-consistency] +[--annotated-tag] +[--annotated-tag-message ANNOTATED_TAG_MESSAGE][--gpg-sign] +[--changelog-to-stdout][--git-output-to-stderr][--retry] +[--major-version-zero][--template TEMPLATE][--extra EXTRA] +[--file-name FILE_NAME][--prerelease-offset PRERELEASE_OFFSET] +[--version-scheme {pep440,semver,semver2}] +[--version-type {pep440,semver,semver2}] +[--build-metadata BUILD_METADATA][--get-next] +[--allow-no-commit] +[MANUAL_VERSION] + +Bump semantic version based on the git log + +positional arguments: +  MANUAL_VERSION        Bump to the given version (e.g., 1.5.3). + +options: +  -h, --help            show this help message and exit +  --dry-run             Perform a dry run, without committing or modifying +                        files. +  --files-only          Bump version in the `version_files` specified in the +                        configuration file only(deprecated; use --version- +                        files-only instead). +  --version-files-only  Bump version in the files from the config +  --local-version       Bump version only the local version portion (ignoring +                        the public version). +  --changelog, -ch      Generate the changelog for the latest version. +  --no-verify           Bypass the pre-commit and commit-msg hooks. +  --yes                 Accept automatically answered questions. +  --tag-format TAG_FORMAT +                        The format used to tag the commit and read it. Use it +                        in existing projects, and wrap around simple quotes. +  --bump-message BUMP_MESSAGE +                        Template used to create the release commit, useful +                        when working with CI. +  --prerelease {alpha,beta,rc}, -pr {alpha,beta,rc} +                        Type of prerelease. +  --devrelease DEVRELEASE, -d DEVRELEASE +                        Specify non-negative integer for dev release. +  --increment {MAJOR,MINOR,PATCH} +                        Specify the desired increment. +  --increment-mode {linear,exact} +                        Set the method by which the new version is chosen. +'linear'(default) resolves the next version based on +                        typical linear version progression, where bumping of a +                        pre-release with lower precedence than the current +                        pre-release phase maintains the current phase of +                        higher precedence. 'exact' applies the changes that +                        have been specified (or determined from the commit +                        log) without interpretation, ensuring the increment +                        and pre-release are always honored. +  --check-consistency, -cc +                        Check consistency among versions defined in Commitizen +                        configuration file and `version_files`. +  --annotated-tag, -at  Create annotated tag instead of lightweight one. +  --annotated-tag-message ANNOTATED_TAG_MESSAGE, -atm ANNOTATED_TAG_MESSAGE +                        Create annotated tag message. +  --gpg-sign, -s        Sign tag instead of lightweight one. +  --changelog-to-stdout +                        Output changelog to stdout. +  --git-output-to-stderr +                        Redirect git output to stderr. +  --retry               Retry commit if it fails for the first time. +  --major-version-zero  Keep major version at zero, even for breaking changes. +  --template TEMPLATE, -t TEMPLATE +                        Changelog template file name (relative to the current +                        working directory). +  --extra EXTRA, -e EXTRA +                        Changelog extra variables (in the form 'key=value'). +  --file-name FILE_NAME +                        File name of changelog (default: 'CHANGELOG.md'). +  --prerelease-offset PRERELEASE_OFFSET +                        Start pre-releases with this offset. +  --version-scheme {pep440,semver,semver2} +                        Choose version scheme. +  --version-type {pep440,semver,semver2} +                        Deprecated, use `--version-scheme` instead. +  --build-metadata BUILD_METADATA +                        Add additional build-metadata to the version-number. +  --get-next            Determine the next version and write to stdout. +  --allow-no-commit     Bump version without eligible commits. + diff --git a/docs/images/cli_help/cz_changelog___help.svg b/docs/images/cli_help/cz_changelog___help.svg index 1d98c05b38..b0d048caed 100644 --- a/docs/images/cli_help/cz_changelog___help.svg +++ b/docs/images/cli_help/cz_changelog___help.svg @@ -19,156 +19,156 @@ font-weight: 700; } - .terminal-192800993-matrix { + .terminal-922159541-matrix { font-family: Fira Code, monospace; font-size: 20px; line-height: 24.4px; font-variant-east-asian: full-width; } - .terminal-192800993-title { + .terminal-922159541-title { font-size: 18px; font-weight: bold; font-family: arial; } - .terminal-192800993-r1 { fill: #c5c8c6 } -.terminal-192800993-r2 { fill: #c5c8c6;font-weight: bold } -.terminal-192800993-r3 { fill: #68a0b3;font-weight: bold } -.terminal-192800993-r4 { fill: #98a84b } + .terminal-922159541-r1 { fill: #c5c8c6 } +.terminal-922159541-r2 { fill: #c5c8c6;font-weight: bold } +.terminal-922159541-r3 { fill: #68a0b3;font-weight: bold } +.terminal-922159541-r4 { fill: #98a84b } - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -180,53 +180,53 @@ - + - - $ cz changelog --help -usage: cz changelog [-h][--dry-run][--file-name FILE_NAME] -[--unreleased-version UNRELEASED_VERSION][--incremental] -[--start-rev START_REV][--merge-prerelease] -[--version-scheme {pep440,semver,semver2}] -[--export-template EXPORT_TEMPLATE][--template TEMPLATE] -[--extra EXTRA][--tag-format TAG_FORMAT] - - -generate changelog (note that it will overwrite existing file) - -positional arguments: -  rev_range             generates changelog for the given version (e.g: 1.5.3) -                        or version range (e.g: 1.5.3..1.7.9) - -options: -  -h, --help            show this help message and exit -  --dry-run             show changelog to stdout -  --file-name FILE_NAME -                        file name of changelog (default: 'CHANGELOG.md') -  --unreleased-version UNRELEASED_VERSION -                        set the value for the new version (use the tag value), -                        instead of using unreleased -  --incremental         generates changelog from last created version, useful -                        if the changelog has been manually modified -  --start-rev START_REV -                        start rev of the changelog. If not set, it will -                        generate changelog from the start -  --merge-prerelease    collect all changes from prereleases into next non- -                        prerelease. If not set, it will include prereleases in -                        the changelog -  --version-scheme {pep440,semver,semver2} -                        choose version scheme -  --export-template EXPORT_TEMPLATE -                        Export the changelog template into this file instead -                        of rendering it -  --template TEMPLATE, -t TEMPLATE -                        changelog template file name (relative to the current -                        working directory) -  --extra EXTRA, -e EXTRA -                        a changelog extra variable (in the form 'key=value') -  --tag-format TAG_FORMAT -                        The format of the tag, wrap around simple quotes - + + $ cz changelog --help +usage: cz changelog [-h][--dry-run][--file-name FILE_NAME] +[--unreleased-version UNRELEASED_VERSION][--incremental] +[--start-rev START_REV][--merge-prerelease] +[--version-scheme {pep440,semver,semver2}] +[--export-template EXPORT_TEMPLATE][--template TEMPLATE] +[--extra EXTRA][--tag-format TAG_FORMAT] + + +Generate changelog (note that it will overwrite existing files) + +positional arguments: +  rev_range             Generate changelog for the given version (e.g., 1.5.3) +                        or version range (e.g., 1.5.3..1.7.9). + +options: +  -h, --help            show this help message and exit +  --dry-run             Show changelog to stdout. +  --file-name FILE_NAME +                        File name of changelog (default: 'CHANGELOG.md'). +  --unreleased-version UNRELEASED_VERSION +                        Set the value for the new version (use the tag value), +                        instead of using unreleased versions. +  --incremental         Generate changelog from the last created version, +                        useful if the changelog has been manually modified. +  --start-rev START_REV +                        Start rev of the changelog. If not set, it will +                        generate changelog from the beginning. +  --merge-prerelease    Collect all changes from prereleases into the next +                        non-prerelease. If not set, it will include +                        prereleases in the changelog. +  --version-scheme {pep440,semver,semver2} +                        Choose version scheme. +  --export-template EXPORT_TEMPLATE +                        Export the changelog template into this file instead +                        of rendering it. +  --template TEMPLATE, -t TEMPLATE +                        Changelog template file name (relative to the current +                        working directory). +  --extra EXTRA, -e EXTRA +                        Changelog extra variables (in the form 'key=value'). +  --tag-format TAG_FORMAT +                        The format of the tag, wrap around simple quotes. + diff --git a/docs/images/cli_help/cz_check___help.svg b/docs/images/cli_help/cz_check___help.svg index 0ced75f60a..1091491d36 100644 --- a/docs/images/cli_help/cz_check___help.svg +++ b/docs/images/cli_help/cz_check___help.svg @@ -1,4 +1,4 @@ - + - - + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + + + + - + - + - - $ cz check --help -usage: cz check [-h] -[--commit-msg-file COMMIT_MSG_FILE | --rev-range REV_RANGE | -d  -| -m MESSAGE] -[--allow-abort][--allowed-prefixes [ALLOWED_PREFIXES ...]] -[-l MESSAGE_LENGTH_LIMIT] - -validates that a commit message matches the commitizen schema - -options: -  -h, --help            show this help message and exit -  --commit-msg-file COMMIT_MSG_FILE -                        ask for the name of the temporal file that contains -                        the commit message. Using it in a git hook script: -MSG_FILE=$1 -  --rev-range REV_RANGE -                        a range of git rev to check. e.g, master..HEAD -  -d, --use-default-range -                        check from the default branch to HEAD. e.g, -                        refs/remotes/origin/master..HEAD -  -m MESSAGE, --message MESSAGE -                        commit message that needs to be checked -  --allow-abort         allow empty commit messages, which typically abort a -                        commit -  --allowed-prefixes [ALLOWED_PREFIXES ...] -                        allowed commit message prefixes. If the message starts -                        by one of these prefixes, the message won't be checked -                        against the regex -  -l MESSAGE_LENGTH_LIMIT, --message-length-limit MESSAGE_LENGTH_LIMIT -                        length limit of the commit message; 0 for no limit - + + $ cz check --help +usage: cz check [-h] +[--commit-msg-file COMMIT_MSG_FILE | --rev-range REV_RANGE | -d  +| -m MESSAGE] +[--allow-abort][--allowed-prefixes [ALLOWED_PREFIXES ...]] +[-l MESSAGE_LENGTH_LIMIT] + +Validate that a commit message matches the commitizen schema + +options: +  -h, --help            show this help message and exit +  --commit-msg-file COMMIT_MSG_FILE +                        Ask for the name of the temporary file that contains +                        the commit message. Use it in a git hook script: +MSG_FILE=$1. +  --rev-range REV_RANGE +                        Validate the commits in the given range of git rev, +                        e.g., master..HEAD. +  -d, --use-default-range +                        Validate the commits from the default branch to HEAD, +                        e.g., refs/remotes/origin/master..HEAD. +  -m MESSAGE, --message MESSAGE +                        Validate the given commit message. +  --allow-abort         Allow empty commit messages, which typically abort a +                        commit. +  --allowed-prefixes [ALLOWED_PREFIXES ...] +                        Skip validation for commit messages that start with +                        the specified prefixes. +  -l MESSAGE_LENGTH_LIMIT, --message-length-limit MESSAGE_LENGTH_LIMIT +                        Restrict the length of the **first line** of the +                        commit message; 0 for no limit. + diff --git a/docs/images/cli_help/cz_commit___help.svg b/docs/images/cli_help/cz_commit___help.svg index 9b68844b57..1905186bb5 100644 --- a/docs/images/cli_help/cz_commit___help.svg +++ b/docs/images/cli_help/cz_commit___help.svg @@ -1,4 +1,4 @@ - + - - + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + + + + + + + + + + - + - + - - $ cz commit --help -usage: cz commit [-h][--retry][--no-retry][--dry-run] -[--write-message-to-file FILE_PATH][-s][-a][-e] -[-l MESSAGE_LENGTH_LIMIT][--] - -create new commit - -options: -  -h, --help            show this help message and exit -  --retry               retry last commit -  --no-retry            skip retry if retry_after_failure is set to true -  --dry-run             show output to stdout, no commit, no modified files -  --write-message-to-file FILE_PATH -                        write message to file before committing (can be -                        combined with --dry-run) -  -s, --signoff         Deprecated, use 'cz commit -- -s' instead -  -a, --all             Tell the command to automatically stage files that -                        have been modified and deleted, but new files you have -                        not told Git about are not affected. -  -e, --edit            edit the commit message before committing -  -l MESSAGE_LENGTH_LIMIT, --message-length-limit MESSAGE_LENGTH_LIMIT -                        length limit of the commit message; 0 for no limit -  --                    Positional arguments separator (recommended) - + + $ cz commit --help +usage: cz commit [-h][--retry][--no-retry][--dry-run] +[--write-message-to-file FILE_PATH][-s][-a][-e] +[-l MESSAGE_LENGTH_LIMIT][--] + +Create new commit + +options: +  -h, --help            show this help message and exit +  --retry               Retry the last commit. +  --no-retry            Skip retry if --retry or `retry_after_failure` is set +                        to true. +  --dry-run             Perform a dry run, without committing or modifying +                        files. +  --write-message-to-file FILE_PATH +                        Write message to FILE_PATH before committing (can be +                        used with --dry-run). +  -s, --signoff         Deprecated, use `cz commit -- -s` instead. +  -a, --all             Automatically stage files that have been modified and +                        deleted, but new files you have not told Git about are +                        not affected. +  -e, --edit            Edit the commit message before committing. +  -l MESSAGE_LENGTH_LIMIT, --message-length-limit MESSAGE_LENGTH_LIMIT +                        Set the length limit of the commit message; 0 for no +                        limit. +  --                    Positional arguments separator (recommended). + diff --git a/docs/images/cli_help/cz_example___help.svg b/docs/images/cli_help/cz_example___help.svg index 9fe4fd659a..6bf85336b8 100644 --- a/docs/images/cli_help/cz_example___help.svg +++ b/docs/images/cli_help/cz_example___help.svg @@ -19,46 +19,46 @@ font-weight: 700; } - .terminal-1643610534-matrix { + .terminal-1249345926-matrix { font-family: Fira Code, monospace; font-size: 20px; line-height: 24.4px; font-variant-east-asian: full-width; } - .terminal-1643610534-title { + .terminal-1249345926-title { font-size: 18px; font-weight: bold; font-family: arial; } - .terminal-1643610534-r1 { fill: #c5c8c6 } -.terminal-1643610534-r2 { fill: #c5c8c6;font-weight: bold } + .terminal-1249345926-r1 { fill: #c5c8c6 } +.terminal-1249345926-r2 { fill: #c5c8c6;font-weight: bold } - + - + - + - + - + - + - + - + @@ -70,17 +70,17 @@ - + - - $ cz example --help -usage: cz example [-h] - -show commit example - -options: -  -h, --help  show this help message and exit - + + $ cz example --help +usage: cz example [-h] + +Show commit example + +options: +  -h, --help  show this help message and exit + diff --git a/docs/images/cli_help/cz_info___help.svg b/docs/images/cli_help/cz_info___help.svg index b8827e34c2..5ab81ec051 100644 --- a/docs/images/cli_help/cz_info___help.svg +++ b/docs/images/cli_help/cz_info___help.svg @@ -19,46 +19,46 @@ font-weight: 700; } - .terminal-4196041424-matrix { + .terminal-3780805296-matrix { font-family: Fira Code, monospace; font-size: 20px; line-height: 24.4px; font-variant-east-asian: full-width; } - .terminal-4196041424-title { + .terminal-3780805296-title { font-size: 18px; font-weight: bold; font-family: arial; } - .terminal-4196041424-r1 { fill: #c5c8c6 } -.terminal-4196041424-r2 { fill: #c5c8c6;font-weight: bold } + .terminal-3780805296-r1 { fill: #c5c8c6 } +.terminal-3780805296-r2 { fill: #c5c8c6;font-weight: bold } - + - + - + - + - + - + - + - + @@ -70,17 +70,17 @@ - + - - $ cz info --help -usage: cz info [-h] - -show information about the cz - -options: -  -h, --help  show this help message and exit - + + $ cz info --help +usage: cz info [-h] + +Show information about the cz + +options: +  -h, --help  show this help message and exit + diff --git a/docs/images/cli_help/cz_init___help.svg b/docs/images/cli_help/cz_init___help.svg index 41a950ebdb..709b779189 100644 --- a/docs/images/cli_help/cz_init___help.svg +++ b/docs/images/cli_help/cz_init___help.svg @@ -19,46 +19,46 @@ font-weight: 700; } - .terminal-1838121835-matrix { + .terminal-3508504009-matrix { font-family: Fira Code, monospace; font-size: 20px; line-height: 24.4px; font-variant-east-asian: full-width; } - .terminal-1838121835-title { + .terminal-3508504009-title { font-size: 18px; font-weight: bold; font-family: arial; } - .terminal-1838121835-r1 { fill: #c5c8c6 } -.terminal-1838121835-r2 { fill: #c5c8c6;font-weight: bold } + .terminal-3508504009-r1 { fill: #c5c8c6 } +.terminal-3508504009-r2 { fill: #c5c8c6;font-weight: bold } - + - + - + - + - + - + - + - + @@ -70,17 +70,17 @@ - + - - $ cz init --help -usage: cz init [-h] - -init commitizen configuration - -options: -  -h, --help  show this help message and exit - + + $ cz init --help +usage: cz init [-h] + +Initialize commitizen configuration + +options: +  -h, --help  show this help message and exit + diff --git a/docs/images/cli_help/cz_ls___help.svg b/docs/images/cli_help/cz_ls___help.svg index 3ec3532ef1..fc6e0bc7e7 100644 --- a/docs/images/cli_help/cz_ls___help.svg +++ b/docs/images/cli_help/cz_ls___help.svg @@ -19,46 +19,46 @@ font-weight: 700; } - .terminal-589791338-matrix { + .terminal-4097343530-matrix { font-family: Fira Code, monospace; font-size: 20px; line-height: 24.4px; font-variant-east-asian: full-width; } - .terminal-589791338-title { + .terminal-4097343530-title { font-size: 18px; font-weight: bold; font-family: arial; } - .terminal-589791338-r1 { fill: #c5c8c6 } -.terminal-589791338-r2 { fill: #c5c8c6;font-weight: bold } + .terminal-4097343530-r1 { fill: #c5c8c6 } +.terminal-4097343530-r2 { fill: #c5c8c6;font-weight: bold } - + - + - + - + - + - + - + - + @@ -70,17 +70,17 @@ - + - - $ cz ls --help -usage: cz ls [-h] - -show available commitizens - -options: -  -h, --help  show this help message and exit - + + $ cz ls --help +usage: cz ls [-h] + +Show available Commitizens + +options: +  -h, --help  show this help message and exit + diff --git a/docs/images/cli_help/cz_schema___help.svg b/docs/images/cli_help/cz_schema___help.svg index afe8982e9a..110569a022 100644 --- a/docs/images/cli_help/cz_schema___help.svg +++ b/docs/images/cli_help/cz_schema___help.svg @@ -19,46 +19,46 @@ font-weight: 700; } - .terminal-1497071669-matrix { + .terminal-1104904213-matrix { font-family: Fira Code, monospace; font-size: 20px; line-height: 24.4px; font-variant-east-asian: full-width; } - .terminal-1497071669-title { + .terminal-1104904213-title { font-size: 18px; font-weight: bold; font-family: arial; } - .terminal-1497071669-r1 { fill: #c5c8c6 } -.terminal-1497071669-r2 { fill: #c5c8c6;font-weight: bold } + .terminal-1104904213-r1 { fill: #c5c8c6 } +.terminal-1104904213-r2 { fill: #c5c8c6;font-weight: bold } - + - + - + - + - + - + - + - + @@ -70,17 +70,17 @@ - + - - $ cz schema --help -usage: cz schema [-h] - -show commit schema - -options: -  -h, --help  show this help message and exit - + + $ cz schema --help +usage: cz schema [-h] + +Show commit schema + +options: +  -h, --help  show this help message and exit + diff --git a/docs/images/cli_help/cz_version___help.svg b/docs/images/cli_help/cz_version___help.svg index a8e0bd844e..0c45576bc5 100644 --- a/docs/images/cli_help/cz_version___help.svg +++ b/docs/images/cli_help/cz_version___help.svg @@ -1,4 +1,4 @@ - + - - + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + + + + + + + - + - + - - $ cz version --help -usage: cz version [-h][-r | -p | -c | -v][--major | --minor] - -get the version of the installed commitizen or the current project (default: -installed commitizen) - -options: -  -h, --help        show this help message and exit -  -r, --report      get system information for reporting bugs -  -p, --project     get the version of the current project -  -c, --commitizen  get the version of the installed commitizen -  -v, --verbose     get the version of both the installed commitizen and the -                    current project -  --major           get just the major version. Need to be used with --project -                    or --verbose. -  --minor           get just the minor version. Need to be used with --project -                    or --verbose. - + + $ cz version --help +usage: cz version [-h][-r | -p | -c | -v][--major | --minor | --tag] + +Get the version of the installed commitizen or the current project (default: +installed commitizen) + +options: +  -h, --help        show this help message and exit +  -r, --report      Output the system information for reporting bugs. +  -p, --project     Output the version of the current project. +  -c, --commitizen  Output the version of the installed commitizen. +  -v, --verbose     Output the version of both the installed commitizen and +                    the current project. +  --major           Output just the major version. Must be used with --project +                    or --verbose. +  --minor           Output just the minor version. Must be used with --project +                    or --verbose. +  --tag             get the version with tag prefix. Need to be used with +                    --project or --verbose. + diff --git a/pyproject.toml b/pyproject.toml index 38cf5da23c..4a2b3850dc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "commitizen" -version = "4.12.1" +version = "4.13.1" description = "Python commitizen client tool" authors = [{ name = "Santiago Fraire", email = "santiwilly@gmail.com" }] maintainers = [ diff --git a/tests/commands/test_commit_command.py b/tests/commands/test_commit_command.py index 89a9224b85..c80a13823d 100644 --- a/tests/commands/test_commit_command.py +++ b/tests/commands/test_commit_command.py @@ -1,4 +1,4 @@ -import os +from pathlib import Path from unittest.mock import ANY import pytest @@ -76,7 +76,7 @@ def test_commit_backup_on_failure( prompt_mock_feat.assert_called_once() error_mock.assert_called_once() - assert os.path.isfile(temp_file) + assert Path(temp_file).exists() @pytest.mark.usefixtures("staging_is_clean", "commit_mock") @@ -100,7 +100,7 @@ def test_commit_retry_works( commit_mock.assert_called_with("backup commit", args="") prompt_mock.assert_not_called() success_mock.assert_called_once() - assert not os.path.isfile(temp_file) + assert not Path(temp_file).exists() @pytest.mark.usefixtures("staging_is_clean") @@ -129,7 +129,7 @@ def test_commit_retry_after_failure_works( commit_mock.assert_called_with("backup commit", args="") prompt_mock.assert_not_called() success_mock.assert_called_once() - assert not os.path.isfile(temp_file) + assert not Path(temp_file).exists() @pytest.mark.usefixtures("staging_is_clean", "backup_file") @@ -144,7 +144,7 @@ def test_commit_retry_after_failure_with_no_retry_works( commit_mock.assert_called_with("feat: user created\n\ncloses #21", args="") prompt_mock_feat.assert_called_once() success_mock.assert_called_once() - assert not os.path.isfile(temp_file) + assert not Path(temp_file).exists() @pytest.mark.usefixtures("staging_is_clean", "prompt_mock_feat") diff --git a/tests/commands/test_init_command.py b/tests/commands/test_init_command.py index 0cf6377ead..ad4431bfd4 100644 --- a/tests/commands/test_init_command.py +++ b/tests/commands/test_init_command.py @@ -1,7 +1,6 @@ from __future__ import annotations import json -import os from pathlib import Path from typing import TYPE_CHECKING, Any @@ -85,12 +84,12 @@ def test_init_without_setup_pre_commit_hook( config_data = toml_file.read() assert config_data == expected_config - assert not os.path.isfile(pre_commit_config_filename) + assert not Path(pre_commit_config_filename).exists() def test_init_when_config_already_exists(config: BaseConfig, capsys): # Set config path - path = Path(os.sep.join(["tests", "pyproject.toml"])) + path = Path("tests") / "pyproject.toml" config.path = path commands.Init(config)() diff --git a/tests/test_changelog.py b/tests/test_changelog.py index 0831bcc1ff..60dae8b50d 100644 --- a/tests/test_changelog.py +++ b/tests/test_changelog.py @@ -1,6 +1,5 @@ from __future__ import annotations -import os import re from dataclasses import dataclass from pathlib import Path @@ -1446,7 +1445,7 @@ def test_render_changelog_with_changelog_message_builder_hook_multiple_entries( def changelog_message_builder_hook(message: dict, commit: git.GitCommit): messages = [message.copy(), message.copy(), message.copy()] for idx, msg in enumerate(messages): - msg["message"] = "Message #{idx}" + msg["message"] = f"Message #{idx}" return messages parser = ConventionalCommitsCz.commit_parser @@ -1463,7 +1462,7 @@ def changelog_message_builder_hook(message: dict, commit: git.GitCommit): result = changelog.render_changelog(tree, loader, template) for idx in range(3): - assert "Message #{idx}" in result + assert f"Message #{idx}" in result def test_changelog_message_builder_hook_can_access_and_modify_change_type( @@ -1672,17 +1671,16 @@ def test_changelog_file_name_from_args_and_config(): args = { "file_name": "CUSTOM.md", - "incremental": None, - "dry_run": False, "unreleased_version": "1.0.1", } changelog = Changelog(mock_config, args) - assert os.path.normpath(changelog.file_name) == os.path.normpath( - os.path.join("/my/project", "CUSTOM.md") + assert ( + Path(changelog.file_name).resolve() == Path("/my/project/CUSTOM.md").resolve() ) - args = {"incremental": None, "dry_run": False, "unreleased_version": "1.0.1"} + args = {"unreleased_version": "1.0.1"} changelog = Changelog(mock_config, args) - assert os.path.normpath(changelog.file_name) == os.path.normpath( - os.path.join("/my/project", "CHANGELOG.md") + assert ( + Path(changelog.file_name).resolve() + == Path("/my/project/CHANGELOG.md").resolve() ) diff --git a/uv.lock b/uv.lock index 75732c7ac0..e1482cb2dc 100644 --- a/uv.lock +++ b/uv.lock @@ -195,7 +195,7 @@ wheels = [ [[package]] name = "commitizen" -version = "4.12.1" +version = "4.13.1" source = { editable = "." } dependencies = [ { name = "argcomplete" },