parseQuotedDiffHeader extracts the old and new paths from a "diff --git" line in which at least one side is quoted, with the "a/" and "b/" prefixes removed. It reports false for a fully unquoted header, which the plain regex still handles.
(line string)
| 138 | // removed. It reports false for a fully unquoted header, which the plain |
| 139 | // regex still handles. |
| 140 | func parseQuotedDiffHeader(line string) (oldPath string, newPath string, ok bool) { |
| 141 | rest, ok := strings.CutPrefix(line, "diff --git ") |
| 142 | if !ok { |
| 143 | return "", "", false |
| 144 | } |
| 145 | first, second, ok := splitHeaderPaths(rest) |
| 146 | if !ok { |
| 147 | return "", "", false |
| 148 | } |
| 149 | oldPath, okOld := strings.CutPrefix(first, "a/") |
| 150 | newPath, okNew := strings.CutPrefix(second, "b/") |
| 151 | if !okOld || !okNew { |
| 152 | return "", "", false |
| 153 | } |
| 154 | return oldPath, newPath, true |
| 155 | } |
| 156 | |
| 157 | // unquoteRenamePath decodes a "rename from"/"rename to" operand, which git |
| 158 | // quotes by the same rule and without any a/ or b/ prefix. A path git left |
no test coverage detected