GetUncommittedDeletedFiles returns absolute paths for tracked files deleted from the current working tree or index.
(repoPath string)
| 42 | // GetUncommittedDeletedFiles returns absolute paths for tracked files deleted |
| 43 | // from the current working tree or index. |
| 44 | func GetUncommittedDeletedFiles(repoPath string) ([]string, error) { |
| 45 | if _, err := os.Stat(repoPath); os.IsNotExist(err) { |
| 46 | return nil, fmt.Errorf("repository path does not exist: %s", repoPath) |
| 47 | } |
| 48 | if !isGitRepository(repoPath) { |
| 49 | return nil, fmt.Errorf("%s is not a git repository (use 'git init' to initialize)", repoPath) |
| 50 | } |
| 51 | |
| 52 | repoRoot, err := GetRepositoryRoot(repoPath) |
| 53 | if err != nil { |
| 54 | return nil, fmt.Errorf("failed to get repository root: %w", err) |
| 55 | } |
| 56 | |
| 57 | statusMap, err := getUncommittedFileStatuses(repoPath) |
| 58 | if err != nil { |
| 59 | return nil, err |
| 60 | } |
| 61 | |
| 62 | var deleted []string |
| 63 | for relPath, status := range statusMap { |
| 64 | if len(status) < 2 { |
| 65 | continue |
| 66 | } |
| 67 | if status[0] == 'D' || status[1] == 'D' { |
| 68 | deleted = append(deleted, filepath.Join(repoRoot, relPath)) |
| 69 | } |
| 70 | } |
| 71 | sort.Strings(deleted) |
| 72 | |
| 73 | return deleted, nil |
| 74 | } |
| 75 | |
| 76 | // GetUncommittedRenames returns staged renames that git itself detected, as a |
| 77 | // map of old absolute path -> new absolute path. Git reports these as status |
no test coverage detected