MCPcopy Create free account
hub / github.com/alibaba/open-code-review / untrackedFileDiffs

Method untrackedFileDiffs

internal/diff/git.go:584–620  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

582}
583
584func (p *Provider) untrackedFileDiffs(ctx context.Context) ([]string, error) {
585 files, err := p.untrackedFilesList(ctx)
586 if err != nil {
587 return nil, err
588 }
589
590 var results []string
591 for _, f := range files {
592 content, rerr := readWorkspaceFileForDiff(p.repoDir, f)
593 if rerr != nil {
594 continue
595 }
596
597 lineCount := bytes.Count(content, []byte{'\n'})
598 if len(content) > 0 && content[len(content)-1] != '\n' {
599 lineCount++
600 }
601
602 var sb strings.Builder
603 sb.WriteString(fmt.Sprintf("diff --git a/%s b/%s\n", f, f))
604 sb.WriteString("--- /dev/null\n")
605 sb.WriteString(fmt.Sprintf("+++ b/%s\n", f))
606 sb.WriteString(fmt.Sprintf("@@ -0,0 +1,%d @@\n", lineCount))
607
608 lines := bytes.Split(content, []byte{'\n'})
609 if len(lines) > 0 && len(lines[len(lines)-1]) == 0 {
610 lines = lines[:len(lines)-1]
611 }
612 for _, line := range lines {
613 sb.WriteByte('+')
614 sb.Write(line)
615 sb.WriteByte('\n')
616 }
617 results = append(results, sb.String())
618 }
619 return results, nil
620}
621
622func (p *Provider) untrackedFilesList(ctx context.Context) ([]string, error) {
623 out, err := p.runGit(ctx, "-c", "core.quotepath=false", "ls-files", "--others", "--exclude-standard")

Callers 1

GetDiffMethod · 0.95

Calls 4

untrackedFilesListMethod · 0.95
readWorkspaceFileForDiffFunction · 0.85
WriteMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected