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

Function LoadGitignoreAtRef

internal/diff/gitignore.go:16–40  ·  view source on GitHub ↗
(ctx context.Context, repoDir, ref string, runner *gitcmd.Runner)

Source from the content-addressed store, hash-verified

14type GitignorePatterns []string
15
16func LoadGitignoreAtRef(ctx context.Context, repoDir, ref string, runner *gitcmd.Runner) (GitignorePatterns, error) {
17 if runner == nil {
18 runner = gitcmd.New(1)
19 }
20 entries, err := runner.Output(ctx, repoDir, "ls-tree", "-z", "--full-tree", "--end-of-options", ref)
21 if err != nil {
22 return nil, fmt.Errorf("locate root .gitignore at %s: %w", ref, err)
23 }
24 for entry := range strings.SplitSeq(string(entries), "\x00") {
25 metadata, name, _ := strings.Cut(entry, "\t")
26 if name != ".gitignore" {
27 continue
28 }
29 mode, oid, _ := strings.Cut(metadata, " blob ")
30 if mode != "100644" && mode != "100755" {
31 break
32 }
33 data, err := runner.Output(ctx, repoDir, "cat-file", "blob", oid)
34 if err != nil {
35 return nil, fmt.Errorf("read root .gitignore at %s: %w", ref, err)
36 }
37 return parseGitignorePatterns(data), nil
38 }
39 return nil, nil
40}
41
42// ExcludedDirs is the list of directory prefixes that scanners and diff
43// providers should always skip. Exposed so internal/scan and other consumers

Callers 3

PrepareInputFunction · 0.92
GetDiffSetMethod · 0.85
TestLoadGitignoreAtRefFunction · 0.85

Calls 3

NewFunction · 0.92
parseGitignorePatternsFunction · 0.85
OutputMethod · 0.80

Tested by 1

TestLoadGitignoreAtRefFunction · 0.68