diff --git a/docs/customization.md b/docs/customization.md index e97558a308..8c43ef8f76 100644 --- a/docs/customization.md +++ b/docs/customization.md @@ -110,13 +110,13 @@ And the correspondent example for a yaml file: commitizen: name: cz_customize customize: - message_template: "{{change_type}}:{% if show_message %} {{message}}{% endif %}" + message_template: '{{change_type}}:{% if show_message %} {{message}}{% endif %}' example: 'feature: this feature enable customize through config file' - schema: ": " - schema_pattern: "(feature|bug fix):(\\s.*)" - bump_pattern: "^(break|new|fix|hotfix)" - commit_parser: "^(?Pfeature|bug fix):\\s(?P.*)?" - changelog_pattern: "^(feature|bug fix)?(!)?" + schema: ': ' + schema_pattern: '(feature|bug fix):(\\s.*)' + bump_pattern: '^(break|new|fix|hotfix)' + commit_parser: '^(?Pfeature|bug fix):\\s(?P.*)?' + changelog_pattern: '^(feature|bug fix)?(!)?' change_type_map: feature: Feat bug fix: Fix @@ -125,7 +125,7 @@ commitizen: new: MINOR fix: PATCH hotfix: PATCH - change_type_order: ["BREAKING CHANGE", "feat", "fix", "refactor", "perf"] + change_type_order: ['BREAKING CHANGE', 'feat', 'fix', 'refactor', 'perf'] info_path: cz_customize_info.txt info: This is customized info questions: diff --git a/tests/commands/test_commit_command.py b/tests/commands/test_commit_command.py index 3a92f5af48..1e8d8a6179 100644 --- a/tests/commands/test_commit_command.py +++ b/tests/commands/test_commit_command.py @@ -324,6 +324,68 @@ 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_when_nothing_added_to_commit(config, mocker: MockFixture): + prompt_mock = mocker.patch("questionary.prompt") + prompt_mock.return_value = { + "prefix": "feat", + "subject": "user created", + "scope": "", + "is_breaking_change": False, + "body": "", + "footer": "", + } + + commit_mock = mocker.patch("commitizen.git.commit") + commit_mock.return_value = cmd.Command( + 'nothing added to commit but untracked files present (use "git add" to track)', + "", + b"", + b"", + 0, + ) + + error_mock = mocker.patch("commitizen.out.error") + + commands.Commit(config, {"all": False})() + + prompt_mock.assert_called_once() + error_mock.assert_called_once() + + assert "nothing added" in error_mock.call_args[0][0] + + +@pytest.mark.usefixtures("staging_is_clean") +def test_commit_when_no_changes_added_to_commit(config, mocker: MockFixture): + prompt_mock = mocker.patch("questionary.prompt") + prompt_mock.return_value = { + "prefix": "feat", + "subject": "user created", + "scope": "", + "is_breaking_change": False, + "body": "", + "footer": "", + } + + commit_mock = mocker.patch("commitizen.git.commit") + commit_mock.return_value = cmd.Command( + 'no changes added to commit (use "git add" and/or "git commit -a")', + "", + b"", + b"", + 0, + ) + + error_mock = mocker.patch("commitizen.out.error") + + commands.Commit(config, {"all": False})() + + prompt_mock.assert_called_once() + error_mock.assert_called_once() + + assert "no changes added to commit" in error_mock.call_args[0][0] + + @pytest.mark.usefixtures("staging_is_clean") def test_commit_with_allow_empty(config, mocker: MockFixture): prompt_mock = mocker.patch("questionary.prompt") diff --git a/tests/test_cz_customize.py b/tests/test_cz_customize.py index 933b1aa065..60a56f147f 100644 --- a/tests/test_cz_customize.py +++ b/tests/test_cz_customize.py @@ -105,17 +105,22 @@ - commitizen/__version__.py - pyproject.toml customize: - message_template: "{{change_type}}:{% if show_message %} {{message}}{% endif %}" + message_template: '{{change_type}}:{% if show_message %} {{message}}{% endif %}' example: 'feature: this feature enables customization through a config file' - schema: ": " - schema_pattern: "(feature|bug fix):(\\s.*)" - bump_pattern: "^(break|new|fix|hotfix)" + schema: ': ' + schema_pattern: '(feature|bug fix):(\\s.*)' + bump_pattern: '^(break|new|fix|hotfix)' + commit_parser: '^(?Pfeature|bug fix):\\s(?P.*)?' + changelog_pattern: '^(feature|bug fix)?(!)?' + change_type_map: + feature: Feat + bug fix: Fix bump_map: break: MAJOR new: MINOR fix: PATCH hotfix: PATCH - change_type_order: ["perf", "BREAKING CHANGE", "feat", "fix", "refactor"] + change_type_order: ['perf', 'BREAKING CHANGE', 'feat', 'fix', 'refactor'] info: This is a customized cz. questions: - type: list @@ -321,6 +326,7 @@ params=[ TomlConfig(data=TOML_STR, path="not_exist.toml"), JsonConfig(data=JSON_STR, path="not_exist.json"), + YAMLConfig(data=YAML_STR, path="not_exist.yaml"), ] ) def config(request):