| 1338 | note = _HOOK_COMMAND_NOTE.rstrip("\n") |
| 1339 | |
| 1340 | def repl(m: re.Match[str]) -> str: |
| 1341 | indent = m.group(1) |
| 1342 | instruction = m.group(2) |
| 1343 | previous_lines = content[:m.start()].splitlines() |
| 1344 | if previous_lines and previous_lines[-1] == indent + note: |
| 1345 | return m.group(0) |
| 1346 | # ``eol`` is empty when the regex matched via ``$`` because the |
| 1347 | # instruction was the final line of a file with no trailing |
| 1348 | # newline. Default to ``\n`` so the note never collapses onto |
| 1349 | # the same line as the instruction. |
| 1350 | eol = m.group(3) or "\n" |
| 1351 | return ( |
| 1352 | indent |
| 1353 | + note |
| 1354 | + eol |
| 1355 | + indent |
| 1356 | + instruction |
| 1357 | + eol |
| 1358 | ) |
| 1359 | |
| 1360 | return re.sub( |
| 1361 | r"(?m)^([ \t]*)(- For each executable hook, output the following[^\r\n]*)(\r\n|\n|$)", |