diff --git a/commitizen/commands/bump.py b/commitizen/commands/bump.py index a3682df8f3..ca8420ae9b 100644 --- a/commitizen/commands/bump.py +++ b/commitizen/commands/bump.py @@ -344,6 +344,7 @@ def __call__(self) -> None: # noqa: C901 ) provider.set_version(str(new_version)) + files.extend(provider.get_files()) if self.pre_bump_hooks: hooks.run( @@ -420,7 +421,7 @@ def __call__(self) -> None: # noqa: C901 out.success("Done!") def _get_commit_args(self) -> str: - commit_args = ["-a"] + commit_args = [] if self.no_verify: commit_args.append("--no-verify") return " ".join(commit_args) diff --git a/commitizen/providers/base_provider.py b/commitizen/providers/base_provider.py index 34048318e2..1c816d1f18 100644 --- a/commitizen/providers/base_provider.py +++ b/commitizen/providers/base_provider.py @@ -34,6 +34,12 @@ def set_version(self, version: str): Set the new current version """ + @abstractmethod + def get_files(self) -> list[str]: + """ + Get the version files + """ + class FileProvider(VersionProvider): """ @@ -66,6 +72,9 @@ def set_version(self, version: str): def get(self, document: dict[str, Any]) -> str: return document["version"] # type: ignore + def get_files(self) -> list[str]: + return [str(self.file)] + def set(self, document: dict[str, Any], version: str): document["version"] = version @@ -87,5 +96,8 @@ def set_version(self, version: str): def get(self, document: tomlkit.TOMLDocument) -> str: return document["project"]["version"] # type: ignore + def get_files(self) -> list[str]: + return [str(self.file)] + def set(self, document: tomlkit.TOMLDocument, version: str): document["project"]["version"] = version # type: ignore diff --git a/commitizen/providers/commitizen_provider.py b/commitizen/providers/commitizen_provider.py index a1da25ff72..689a57cd2d 100644 --- a/commitizen/providers/commitizen_provider.py +++ b/commitizen/providers/commitizen_provider.py @@ -13,3 +13,6 @@ def get_version(self) -> str: def set_version(self, version: str): self.config.set_key("version", version) + + def get_files(self) -> list[str]: + return [str(self.config._path)] diff --git a/commitizen/providers/npm_provider.py b/commitizen/providers/npm_provider.py index 12900ff7de..a465c1141f 100644 --- a/commitizen/providers/npm_provider.py +++ b/commitizen/providers/npm_provider.py @@ -58,6 +58,15 @@ def set_version(self, version: str) -> None: json.dumps(shrinkwrap_document, indent=self.indent) + "\n" ) + def get_files(self) -> list[str]: + files = [] + files.append(str(self.package_file)) + if self.lock_file.exists(): + files.append(str(self.lock_file)) + if self.shrinkwrap_file.exists(): + files.append(str(self.shrinkwrap_file)) + return files + def get_package_version(self, document: dict[str, Any]) -> str: return document["version"] # type: ignore diff --git a/commitizen/providers/scm_provider.py b/commitizen/providers/scm_provider.py index 33e470cfc6..e233c17e47 100644 --- a/commitizen/providers/scm_provider.py +++ b/commitizen/providers/scm_provider.py @@ -78,3 +78,7 @@ def get_version(self) -> str: def set_version(self, version: str): # Not necessary pass + + def get_files(self) -> list[str]: + # No files for this provider + return [] diff --git a/docs/config.md b/docs/config.md index 210b5d7ff8..2b06b3506b 100644 --- a/docs/config.md +++ b/docs/config.md @@ -366,6 +366,9 @@ class MyProvider(VersionProvider): def set_version(self, version: str): self.file.write_text(version) + def get_files(self) -> list[str]: + return [str(file)] + ``` ```python title="setup.py" diff --git a/tests/commands/test_bump_command.py b/tests/commands/test_bump_command.py index 81273764dd..e9a750a18b 100644 --- a/tests/commands/test_bump_command.py +++ b/tests/commands/test_bump_command.py @@ -535,6 +535,18 @@ def test_bump_major_version_zero_when_major_is_not_zero(mocker, tmp_commitizen_p assert expected_error_message in str(excinfo.value) +def test_bump_not_add_unstaged(mocker: MockFixture, tmp_commitizen_project): + unstaged_file = "ui.py" + create_file_and_commit("feat: new file", unstaged_file) + tmp_file = tmp_commitizen_project.join(unstaged_file) + tmp_file.write("updated content") + testargs = ["cz", "bump", "--yes"] + mocker.patch.object(sys, "argv", testargs) + cli.main() + cmd_res = cmd.run("git diff --name-only") + assert unstaged_file in cmd_res.out + + def test_bump_files_only(mocker: MockFixture, tmp_commitizen_project): tmp_version_file = tmp_commitizen_project.join("__version__.py") tmp_version_file.write("0.1.0") diff --git a/tests/providers/test_cargo_provider.py b/tests/providers/test_cargo_provider.py index 646ef3a53d..fd298e3a41 100644 --- a/tests/providers/test_cargo_provider.py +++ b/tests/providers/test_cargo_provider.py @@ -58,3 +58,6 @@ def test_cargo_provider( provider.set_version("42.1") assert file.read_text() == dedent(expected) + + files = provider.get_files() + assert filename in files diff --git a/tests/providers/test_composer_provider.py b/tests/providers/test_composer_provider.py index 45cbc8afa4..23667193f4 100644 --- a/tests/providers/test_composer_provider.py +++ b/tests/providers/test_composer_provider.py @@ -45,3 +45,6 @@ def test_composer_provider( provider.set_version("42.1") assert file.read_text() == dedent(expected) + + files = provider.get_files() + assert filename in files diff --git a/tests/providers/test_npm_provider.py b/tests/providers/test_npm_provider.py index bc9399916d..4f886bda35 100644 --- a/tests/providers/test_npm_provider.py +++ b/tests/providers/test_npm_provider.py @@ -96,3 +96,10 @@ def test_npm_provider( assert pkg_lock.read_text() == dedent(pkg_lock_expected) if pkg_shrinkwrap_content: assert pkg_shrinkwrap.read_text() == dedent(pkg_shrinkwrap_expected) + + files = provider.get_files() + assert NpmProvider.package_filename in files + if pkg_lock_content: + assert NpmProvider.lock_filename in files + if pkg_shrinkwrap_content: + assert NpmProvider.shrinkwrap_filename in files diff --git a/tests/providers/test_pep621_provider.py b/tests/providers/test_pep621_provider.py index 16bb479cc4..1393eea9ed 100644 --- a/tests/providers/test_pep621_provider.py +++ b/tests/providers/test_pep621_provider.py @@ -41,3 +41,6 @@ def test_cargo_provider( provider.set_version("42.1") assert file.read_text() == dedent(expected) + + files = provider.get_files() + assert filename in files diff --git a/tests/providers/test_poetry_provider.py b/tests/providers/test_poetry_provider.py index e26e2a44fb..cc34265668 100644 --- a/tests/providers/test_poetry_provider.py +++ b/tests/providers/test_poetry_provider.py @@ -41,3 +41,6 @@ def test_cargo_provider( provider.set_version("42.1") assert file.read_text() == dedent(expected) + + files = provider.get_files() + assert filename in files diff --git a/tests/providers/test_scm_provider.py b/tests/providers/test_scm_provider.py index 01e7ab9943..a3de66b162 100644 --- a/tests/providers/test_scm_provider.py +++ b/tests/providers/test_scm_provider.py @@ -60,6 +60,10 @@ def test_scm_provider( # Should not fail on set_version() provider.set_version("43.1") + # Should not have any files + files = provider.get_files() + assert files == [] + @pytest.mark.usefixtures("tmp_git_project") def test_scm_provider_default_without_commits_and_tags(config: BaseConfig):