Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
e4b048d
refactor: improve readability and fix typos
bearomorphism May 15, 2025
3b4dbbc
refactor(version_scheme): cleanup
bearomorphism May 17, 2025
77b3d4b
refactor(commit): simplify call
bearomorphism May 17, 2025
7a1fb3e
test(commit): when nothing is added to commit
bearomorphism May 17, 2025
b7e6a94
refactor(git): code cleanup and better test coverage
bearomorphism May 15, 2025
262733a
test(git): add test for from_rev_and_commit
bearomorphism May 17, 2025
bb63228
docs(git): from_rev_and_commit docstring
bearomorphism May 17, 2025
8477b89
refactor(EOLType): add eol enum back and reorganize methods
bearomorphism May 18, 2025
5810108
refactor(git): refactor get_tag_names
bearomorphism May 18, 2025
3b163a8
refactor(changelog): minor cleanup
bearomorphism May 19, 2025
5cc58d9
refactor(BaseConfig): use setter
bearomorphism May 20, 2025
06970e6
build(poetry): upgrade mypy version to ^1.15.0
bearomorphism May 20, 2025
d7efb1b
refactor(bump): add type for out, replace function with re escape
bearomorphism May 17, 2025
1b9a177
refactor(bump): clean up
bearomorphism May 16, 2025
2286271
test(bump): improve test coverage
bearomorphism May 16, 2025
360057b
fix(defaults): add non-capitalized default constants back and depreca…
bearomorphism May 22, 2025
1ed9d2d
refactor: misc cleanup
bearomorphism May 17, 2025
37a990b
refactor(git): extract _create_commit_cmd_string
bearomorphism May 19, 2025
5b94792
test(test_git): mock os
bearomorphism May 23, 2025
1d7563e
refactor(cli): early return and improve test coverage
bearomorphism May 23, 2025
978358a
build(termcolor): remove termcolor <3 restriction
bearomorphism May 23, 2025
2ccb269
build: specify importlib-metadata version to fix unit tests
bearomorphism May 25, 2025
baee83e
refactor(changelog): better typing, yield
bearomorphism May 24, 2025
75c90d6
build(deps-dev): bump mypy to 1.16.0
bearomorphism May 23, 2025
3bd7439
refactor(mypy): remove `unused-ignore`
gbaian10 May 31, 2025
d830b2f
refactor(cli.py): add type hints
gbaian10 May 31, 2025
0553197
refactor: add comment clarifying `no_raise` parsing to `list[int]`
gbaian10 May 31, 2025
d7594ae
refactor: remove `TypeError` handling since `Python >=3.9` is required
gbaian10 May 31, 2025
f92f380
fix(deprecated): mark deprecate in v5
bearomorphism Jun 1, 2025
868aa71
build(deps-dev): bump ruff
gbaian10 May 31, 2025
ffccec7
style(ruff): resolve F401
gbaian10 May 31, 2025
ff97584
build(ruff): add RUF022 & RUF100 rules
gbaian10 May 31, 2025
0b2b790
style(ruff): run `ruff check --fix`
gbaian10 May 31, 2025
d799f6b
refactor(BaseCommitizen): remove unused process_commit
bearomorphism May 30, 2025
1269f1c
style(tags): improve types
bearomorphism May 29, 2025
a9aeaf2
perf(tags): use set
bearomorphism May 29, 2025
dd7d41f
refactor: fix mypy output and better type
bearomorphism May 29, 2025
c75d3d0
refactor(conventional_commits): remove unnecessary checks
bearomorphism May 29, 2025
12c0dec
refactor: make methods protected, better type
bearomorphism May 30, 2025
d62821c
style: type untyped methods
bearomorphism May 30, 2025
7d40b04
style: remove Union
bearomorphism May 30, 2025
8287e17
style: better type
bearomorphism May 30, 2025
9b153b4
style: add `-> None` to __init__
bearomorphism May 30, 2025
ee4646d
build(ruff,mypy): more strict rules
bearomorphism May 30, 2025
21fae53
fix(BaseConfig): mypy error
bearomorphism May 31, 2025
afcd5c3
build(mypy): remove disallow_untyped_defs because it's already done b…
bearomorphism May 31, 2025
7ac3ea3
refactor(bump): TypedDict for bump argument
bearomorphism May 30, 2025
b7983ca
refactor(changelog): type untyped arguments
bearomorphism May 31, 2025
b2a7a51
refactor(check): remove unused argument
bearomorphism May 31, 2025
db3c1a0
style(bump): rename class for consistency
bearomorphism May 31, 2025
4aed07c
refactor(check): type CheckArgs arguments
bearomorphism May 31, 2025
5616076
refactor(commit): type commit args
bearomorphism May 31, 2025
735ad12
refactor(commands): remove unused args, type version command args
bearomorphism May 31, 2025
e2702fc
style(cli): shorten arg type
bearomorphism May 31, 2025
e631941
docs(bump): comment on a stupid looking pattern
bearomorphism May 31, 2025
92bbab0
fix(Check): make parameters backward compatiable
bearomorphism May 31, 2025
047779b
style(changelog): rename parameter for consistency
bearomorphism May 31, 2025
945d0c3
refactor(bump): improve readability and still bypass mypy check
bearomorphism May 31, 2025
2fa0452
refactor: remove unnecessary bool() and remove Any type from TypedDic…
bearomorphism May 31, 2025
022e552
style(changelog): add TODO to fixable type ignores
bearomorphism Jun 4, 2025
ba0c043
style(cli): more specific type ignore
bearomorphism Jun 4, 2025
8a3a09b
style(cli): rename kwarg to values
bearomorphism Jun 4, 2025
ff1a5ae
refactor(bump): use any to replace 'or' chain
bearomorphism Jun 6, 2025
e0cc9c4
perf(bump): avoid unnecessary list construction and rename variable t…
bearomorphism Jun 5, 2025
05ec0ba
ci: regenerate poetry lock
bearomorphism Jun 8, 2025
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
Prev Previous commit
Next Next commit
refactor(EOLType): add eol enum back and reorganize methods
  • Loading branch information
bearomorphism authored and Lee-W committed Jun 8, 2025
commit 8477b89f96bf02318309d8d11d1d22e91ee008a8
48 changes: 33 additions & 15 deletions commitizen/git.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,44 @@
from __future__ import annotations

import os
from enum import Enum
from functools import lru_cache
from pathlib import Path
from tempfile import NamedTemporaryFile

from commitizen import cmd, out
from commitizen.exceptions import GitCommandError

_UNIX_EOL = "\n"
_WINDOWS_EOL = "\r\n"

class EOLType(Enum):
"""The EOL type from `git config core.eol`."""

LF = "lf"
CRLF = "crlf"
NATIVE = "native"

@classmethod
def for_open(cls) -> str:
c = cmd.run("git config core.eol")
eol = c.out.strip().upper()
return cls._char_for_open()[cls._safe_cast(eol)]

@classmethod
def _safe_cast(cls, eol: str) -> EOLType:
try:
return cls[eol]
except KeyError:
return cls.NATIVE

@classmethod
@lru_cache
def _char_for_open(cls) -> dict[EOLType, str]:
"""Get the EOL character for `open()`."""
return {
cls.LF: "\n",
cls.CRLF: "\r\n",
cls.NATIVE: os.linesep,
}


class GitObject:
Expand Down Expand Up @@ -268,18 +298,6 @@ def is_git_project() -> bool:
return c.out.strip() == "true"


def get_eol_for_open() -> str:
# See: https://git-scm.com/docs/git-config#Documentation/git-config.txt-coreeol
c = cmd.run("git config core.eol")
eol = c.out.strip().lower()

if eol == "lf":
return _UNIX_EOL
if eol == "crlf":
return _WINDOWS_EOL
return os.linesep


def get_core_editor() -> str | None:
c = cmd.run("git var GIT_EDITOR")
if c.out:
Expand All @@ -289,7 +307,7 @@ def get_core_editor() -> str | None:

def smart_open(*args, **kwargs):
"""Open a file with the EOL style determined from Git."""
return open(*args, newline=get_eol_for_open(), **kwargs)
return open(*args, newline=EOLType.for_open(), **kwargs)


def _get_log_as_str_list(start: str | None, end: str, args: str) -> list[str]:
Expand Down
8 changes: 4 additions & 4 deletions tests/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,16 +318,16 @@ def test_is_staging_clean_when_updating_file(tmp_commitizen_project):

def test_get_eol_for_open(tmp_commitizen_project):
with tmp_commitizen_project.as_cwd():
assert git.get_eol_for_open() == os.linesep
assert git.EOLType.for_open() == os.linesep

cmd.run("git config core.eol lf")
assert git.get_eol_for_open() == "\n"
assert git.EOLType.for_open() == "\n"

cmd.run("git config core.eol crlf")
assert git.get_eol_for_open() == "\r\n"
assert git.EOLType.for_open() == "\r\n"

cmd.run("git config core.eol native")
assert git.get_eol_for_open() == os.linesep
assert git.EOLType.for_open() == os.linesep


def test_get_core_editor(mocker):
Expand Down