Wrap the body of the commit message to the --body-length-limit length.
(self, message: str)
| 114 | ) |
| 115 | |
| 116 | def _wrap_body(self, message: str) -> str: |
| 117 | """ |
| 118 | Wrap the body of the commit message to the --body-length-limit length. |
| 119 | """ |
| 120 | |
| 121 | body_length_limit = self.arguments.get("body_length_limit") |
| 122 | if body_length_limit is None: |
| 123 | body_length_limit = self.config.settings["body_length_limit"] |
| 124 | # By the contract, body_length_limit is set to 0 for no limit |
| 125 | if not body_length_limit or body_length_limit <= 0: |
| 126 | return message |
| 127 | |
| 128 | lines = message.split("\n") |
| 129 | if len(lines) < 3: |
| 130 | return message |
| 131 | |
| 132 | # Preserve intentional blank (or whitespace-only) lines while wrapping |
| 133 | # non-empty body lines. textwrap.wrap() returns [] for such lines, so |
| 134 | # they must be special-cased to avoid being silently dropped. |
| 135 | wrapped_body_lines = chain.from_iterable( |
| 136 | textwrap.wrap(line, width=body_length_limit) if line.strip() else [line] |
| 137 | for line in lines[2:] |
| 138 | ) |
| 139 | return "\n".join(chain(lines[:2], wrapped_body_lines)) |
| 140 | |
| 141 | def manual_edit(self, message: str) -> str: |
| 142 | """Open the message in the git editor and return the edited message. |
no test coverage detected