MCPcopy Index your code
hub / github.com/nikivdev/go / runGitIgnore

Function runGitIgnore

cli/flow/main.go:3292–3425  ·  view source on GitHub ↗
(ctx *snap.Context)

Source from the content-addressed store, hash-verified

3290}
3291
3292func runGitIgnore(ctx *snap.Context) error {
3293 if err := ensureGitRepository(); err != nil {
3294 return err
3295 }
3296
3297 // Get all changed and untracked files
3298 cmd := exec.Command("git", "status", "--porcelain")
3299 output, err := cmd.Output()
3300 if err != nil {
3301 return fmt.Errorf("git status: %w", err)
3302 }
3303
3304 lines := strings.Split(strings.TrimSpace(string(output)), "\n")
3305 if len(lines) == 0 || (len(lines) == 1 && lines[0] == "") {
3306 fmt.Fprintln(ctx.Stdout(), "No changed or untracked files")
3307 return nil
3308 }
3309
3310 type fileEntry struct {
3311 status string
3312 path string
3313 }
3314
3315 var entries []fileEntry
3316 seenDirs := make(map[string]bool)
3317
3318 for _, line := range lines {
3319 if len(line) < 4 {
3320 continue
3321 }
3322 status := strings.TrimSpace(line[:2])
3323 path := strings.TrimSpace(line[3:])
3324 if path == "" {
3325 continue
3326 }
3327
3328 entries = append(entries, fileEntry{status: status, path: path})
3329
3330 // Also add parent directories as options
3331 dir := filepath.Dir(path)
3332 for dir != "." && dir != "/" && !seenDirs[dir] {
3333 seenDirs[dir] = true
3334 entries = append(entries, fileEntry{status: "dir", path: dir + "/"})
3335 dir = filepath.Dir(dir)
3336 }
3337 }
3338
3339 if len(entries) == 0 {
3340 fmt.Fprintln(ctx.Stdout(), "No files to ignore")
3341 return nil
3342 }
3343
3344 // Sort: directories first, then files
3345 sort.Slice(entries, func(i, j int) bool {
3346 iIsDir := strings.HasSuffix(entries[i].path, "/")
3347 jIsDir := strings.HasSuffix(entries[j].path, "/")
3348 if iIsDir != jIsDir {
3349 return iIsDir

Callers 1

mainFunction · 0.85

Calls 1

ensureGitRepositoryFunction · 0.85

Tested by

no test coverage detected