The EOL type from `git config core.eol`.
| 15 | |
| 16 | |
| 17 | class 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 | |
| 48 | class GitObject: |
nothing calls this directly
no outgoing calls
no test coverage detected