( ctx context.Context, repoPath string, oldSHA string, newSHA string, ignoreWhitespace bool, params parser.DiffCutParams, )
| 516 | } |
| 517 | |
| 518 | func (g *Git) diffCutFromHunk( |
| 519 | ctx context.Context, |
| 520 | repoPath string, |
| 521 | oldSHA string, |
| 522 | newSHA string, |
| 523 | ignoreWhitespace bool, |
| 524 | params parser.DiffCutParams, |
| 525 | ) (parser.HunkHeader, parser.Hunk, error) { |
| 526 | pipeRead, pipeWrite := io.Pipe() |
| 527 | stderr := bytes.NewBuffer(nil) |
| 528 | go func() { |
| 529 | var err error |
| 530 | |
| 531 | defer func() { |
| 532 | // If running of the command below fails, make the pipe reader also fail with the same error. |
| 533 | _ = pipeWrite.CloseWithError(err) |
| 534 | }() |
| 535 | |
| 536 | cmd := command.New("diff", |
| 537 | command.WithFlag("--patch"), |
| 538 | command.WithFlag("--full-index"), |
| 539 | command.WithFlag("--no-color"), |
| 540 | command.WithFlag("--unified=100000000"), |
| 541 | command.WithArg(oldSHA), |
| 542 | command.WithArg(newSHA)) |
| 543 | |
| 544 | if ignoreWhitespace { |
| 545 | // Ignore whitespace when comparing lines. |
| 546 | cmd.Add(command.WithFlag("-w")) |
| 547 | } |
| 548 | |
| 549 | err = cmd.Run(ctx, |
| 550 | command.WithDir(repoPath), |
| 551 | command.WithStdout(pipeWrite), |
| 552 | command.WithStderr(stderr)) |
| 553 | }() |
| 554 | |
| 555 | diffCutHeader, linesHunk, err := parser.DiffCut(pipeRead, params) |
| 556 | if errStderr := parseDiffStderr(stderr); errStderr != nil { |
| 557 | // First check if there's something in the stderr buffer, if yes that's the error |
| 558 | return parser.HunkHeader{}, parser.Hunk{}, errStderr |
| 559 | } |
| 560 | if err != nil { |
| 561 | // Next check if reading the git diff output caused an error |
| 562 | return parser.HunkHeader{}, parser.Hunk{}, err |
| 563 | } |
| 564 | |
| 565 | return diffCutHeader, linesHunk, nil |
| 566 | } |
| 567 | |
| 568 | func (g *Git) diffCutFromBlob( |
| 569 | ctx context.Context, |
no test coverage detected