(ctx context.Context)
| 660 | } |
| 661 | |
| 662 | func (p *Provider) untrackedFileDiffs(ctx context.Context) ([]string, error) { |
| 663 | files, err := p.untrackedFilesList(ctx) |
| 664 | if err != nil { |
| 665 | return nil, err |
| 666 | } |
| 667 | |
| 668 | var results []string |
| 669 | for _, f := range files { |
| 670 | content, rerr := readWorkspaceFileForDiffWithLimit(p.repoDir, f, maxUntrackedFileSize) |
| 671 | if errors.Is(rerr, errWorkspaceFileTooLarge) { |
| 672 | results = append(results, untrackedBinaryDiff(f)) |
| 673 | continue |
| 674 | } |
| 675 | if rerr != nil { |
| 676 | continue |
| 677 | } |
| 678 | |
| 679 | if looksBinary(content) { |
| 680 | // Emit git's own binary marker so the parser flags the file and |
| 681 | // the selection layer excludes it, matching the tracked path where |
| 682 | // `git diff` itself reports "Binary files ... differ". |
| 683 | results = append(results, untrackedBinaryDiff(f)) |
| 684 | continue |
| 685 | } |
| 686 | |
| 687 | lineCount := bytes.Count(content, []byte{'\n'}) |
| 688 | if len(content) > 0 && content[len(content)-1] != '\n' { |
| 689 | lineCount++ |
| 690 | } |
| 691 | |
| 692 | var sb strings.Builder |
| 693 | sb.WriteString(fmt.Sprintf("diff --git a/%s b/%s\n", f, f)) |
| 694 | sb.WriteString("--- /dev/null\n") |
| 695 | sb.WriteString(fmt.Sprintf("+++ b/%s\n", f)) |
| 696 | sb.WriteString(fmt.Sprintf("@@ -0,0 +1,%d @@\n", lineCount)) |
| 697 | |
| 698 | lines := bytes.Split(content, []byte{'\n'}) |
| 699 | if len(lines) > 0 && len(lines[len(lines)-1]) == 0 { |
| 700 | lines = lines[:len(lines)-1] |
| 701 | } |
| 702 | for _, line := range lines { |
| 703 | sb.WriteByte('+') |
| 704 | sb.Write(line) |
| 705 | sb.WriteByte('\n') |
| 706 | } |
| 707 | results = append(results, sb.String()) |
| 708 | } |
| 709 | return results, nil |
| 710 | } |
| 711 | |
| 712 | func (p *Provider) untrackedFilesList(ctx context.Context) ([]string, error) { |
| 713 | // -z, and no trimming of the records it produces. Without it git quotes |
no test coverage detected