| 14 | type GitignorePatterns []string |
| 15 | |
| 16 | func 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 |