| 297 | } |
| 298 | |
| 299 | func changedFilesNames(w io.Writer, r io.Reader) error { |
| 300 | diff, err := io.ReadAll(r) |
| 301 | if err != nil { |
| 302 | return err |
| 303 | } |
| 304 | |
| 305 | // This is kind of a gnarly regex. We're looking lines of the format: |
| 306 | // diff --git a/9114-triage b/9114-triage |
| 307 | // diff --git "a/hello-\360\237\230\200-world" "b/hello-\360\237\230\200-world" |
| 308 | // |
| 309 | // From these lines we would look to extract: |
| 310 | // 9114-triage |
| 311 | // "hello-\360\237\230\200-world" |
| 312 | // |
| 313 | // Note that the b/ is removed but in the second case the preceeding quote remains. |
| 314 | // This is important for how git handles filenames that would be quoted with core.quotePath. |
| 315 | // https://git-scm.com/docs/git-config#Documentation/git-config.txt-corequotePath |
| 316 | // |
| 317 | // Thus we capture the quote if it exists, and everything that follows the b/ |
| 318 | // We then concatenate those two capture groups together which for the examples above would be: |
| 319 | // `` + 9114-triage |
| 320 | // `"`` + hello-\360\237\230\200-world" |
| 321 | // |
| 322 | // Where I'm using the `` to indicate a string to avoid confusion with the " character. |
| 323 | matches := diffHeaderRegexp.FindAllStringSubmatch(string(diff), -1) |
| 324 | |
| 325 | for _, val := range matches { |
| 326 | name := strings.TrimSpace(val[1] + val[2]) |
| 327 | if _, err := w.Write([]byte(name + "\n")); err != nil { |
| 328 | return err |
| 329 | } |
| 330 | } |
| 331 | |
| 332 | return nil |
| 333 | } |
| 334 | |
| 335 | func sanitizedReader(r io.Reader) io.Reader { |
| 336 | return transform.NewReader(r, sanitizer{}) |