Skip to content

fix(bump)!: only add version files and staged changes #1261

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: v5
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
fix(bump): only add version files
BREAKING CHANGE: VersionProvider has new method which will break any custom version provider
  • Loading branch information
marcusalstrom committed Oct 15, 2024
commit fd29f2a1602d115f381f3c53d4eb1eb6de214836
3 changes: 2 additions & 1 deletion commitizen/commands/bump.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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)
12 changes: 12 additions & 0 deletions commitizen/providers/base_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ def set_version(self, version: str):
Set the new current version
"""

@abstractmethod
def get_files(self) -> list[str]:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's make it a property

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe renamed as version_files would be better?

"""
Get the version files
"""


class FileProvider(VersionProvider):
"""
Expand Down Expand Up @@ -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

Expand All @@ -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
3 changes: 3 additions & 0 deletions commitizen/providers/commitizen_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
9 changes: 9 additions & 0 deletions commitizen/providers/npm_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions commitizen/providers/scm_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 []