GetUncommittedFiles finds all uncommitted files in a git repository. Returns absolute paths to all uncommitted files (staged, unstaged, and untracked).
(repoPath string)
| 11 | // GetUncommittedFiles finds all uncommitted files in a git repository. |
| 12 | // Returns absolute paths to all uncommitted files (staged, unstaged, and untracked). |
| 13 | func GetUncommittedFiles(repoPath string) ([]string, error) { |
| 14 | // Validate the repository path exists |
| 15 | if _, err := os.Stat(repoPath); os.IsNotExist(err) { |
| 16 | return nil, fmt.Errorf("repository path does not exist: %s", repoPath) |
| 17 | } |
| 18 | |
| 19 | // Verify it's a git repository |
| 20 | if !isGitRepository(repoPath) { |
| 21 | return nil, fmt.Errorf("%s is not a git repository (use 'git init' to initialize)", repoPath) |
| 22 | } |
| 23 | |
| 24 | // Get the repository root |
| 25 | repoRoot, err := GetRepositoryRoot(repoPath) |
| 26 | if err != nil { |
| 27 | return nil, fmt.Errorf("failed to get repository root: %w", err) |
| 28 | } |
| 29 | |
| 30 | // Get all uncommitted files |
| 31 | uncommittedFiles, err := getUncommittedFiles(repoPath) |
| 32 | if err != nil { |
| 33 | return nil, fmt.Errorf("failed to get uncommitted files: %w", err) |
| 34 | } |
| 35 | |
| 36 | // Convert to absolute paths (no filtering - include all files) |
| 37 | absolutePaths := toAbsolutePaths(repoRoot, uncommittedFiles) |
| 38 | |
| 39 | return absolutePaths, nil |
| 40 | } |
| 41 | |
| 42 | // GetUncommittedDeletedFiles returns absolute paths for tracked files deleted |
| 43 | // from the current working tree or index. |