MCPcopy Create free account
hub / github.com/commitizen-tools/commitizen / EOLType

Class EOLType

commitizen/git.py:17–45  ·  view source on GitHub ↗

The EOL type from `git config core.eol`.

Source from the content-addressed store, hash-verified

15
16
17class EOLType(Enum):
18 """The EOL type from `git config core.eol`."""
19
20 LF = "lf"
21 CRLF = "crlf"
22 NATIVE = "native"
23
24 @classmethod
25 def for_open(cls) -> str:
26 c = cmd.run(["git", "config", "core.eol"])
27 eol = c.out.strip().upper()
28 return cls._char_for_open()[cls._safe_cast(eol)]
29
30 @classmethod
31 def _safe_cast(cls, eol: str) -> EOLType:
32 try:
33 return cls[eol]
34 except KeyError:
35 return cls.NATIVE
36
37 @classmethod
38 @lru_cache
39 def _char_for_open(cls) -> dict[EOLType, str]:
40 """Get the EOL character for `open()`."""
41 return {
42 cls.LF: "\n",
43 cls.CRLF: "\r\n",
44 cls.NATIVE: os.linesep,
45 }
46
47
48class GitObject:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected