Skip to content

fix(providers): write files with the line ending from git core.eol - #2128

Merged
woile merged 1 commit into
commitizen-tools:masterfrom
TohruSu:fix/providers-honor-core-eol
Nov 24, 2026
Merged

woile merged 1 commit into
commitizen-tools:masterfrom
TohruSu:fix/providers-honor-core-eol

Conversation

@TohruSu

@TohruSu TohruSu commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Description

Version providers write their files with Path.write_text(), so they always use the platform line ending. The other files that cz bump writes (version_files, the changelog, JSON/YAML config) go through smart_open() and follow git config core.eol (#493).

On Windows with core.eol=lf, cz bump with the pep621 provider rewrites all of pyproject.toml with CRLF, while version_files and CHANGELOG.md stay LF. uv.lock, Cargo.lock, package.json, package-lock.json and composer.json have the same problem.

This PR adds FileProvider._write_text(), which uses smart_open(), and uses it for all provider writes. If core.eol is not set, the output does not change.

Checklist

Was generative AI tooling used to co-author this PR?

  • Yes (please specify the tool below)

Generated-by: Claude Code
Assisted By: AI

Code Changes

  • Add test cases to all the changes you introduce
  • Run uv run poe all locally to ensure this change passes linter check and tests (I ran pytest, ruff and mypy separately)
  • Manually test the changes
  • Update the documentation for the changes

Expected Behavior

Provider files use the line ending from git config core.eol, like version_files and the changelog.

Steps to Test This Pull Request

Run pytest tests/providers/test_base_provider.py -k core_eol. The new test covers the six providers with core.eol set to lf and crlf. Without the fix, the lf cases fail on Windows.

Manual check on Windows: in a repository with git config core.eol lf and version_provider = "pep621", run cz bump. Before the fix, git show --stat HEAD shows every line of pyproject.toml as changed. After the fix, only the version line changes.

Additional Context

Tested on Windows 10 with Python 3.14. The full suite passes, except for 10 tests that also fail on master on this machine (no gpg, hook runner not on PATH, two file_regression snapshot names). Not tested on Linux or macOS.

Version providers wrote pyproject.toml, uv.lock, Cargo.lock,
package.json and the other files they update with Path.write_text(),
which uses the platform line ending. version_files and the changelog
are written with smart_open(), which follows `git config core.eol`.
On Windows with core.eol=lf, cz bump rewrote pyproject.toml with CRLF,
while version_files and CHANGELOG.md kept LF.

Write the provider files with smart_open() too. When core.eol is not
set, the result is the same as before (os.linesep).

Assisted By: AI
@codecov

codecov Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.29%. Comparing base (ace110d) to head (eeeeb15).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2128   +/-   ##
=======================================
  Coverage   98.29%   98.29%           
=======================================
  Files          61       61           
  Lines        2870     2874    +4     
=======================================
+ Hits         2821     2825    +4     
  Misses         49       49           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@woile
woile merged commit 5a9fe44 into commitizen-tools:master Nov 24, 2026
21 checks passed
@TohruSu
TohruSu deleted the fix/providers-honor-core-eol branch November 24, 2026 09:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants