getUncommittedFiles returns a list of all uncommitted files (relative to repo root)
(repoPath string)
| 187 | |
| 188 | // getUncommittedFiles returns a list of all uncommitted files (relative to repo root) |
| 189 | func getUncommittedFiles(repoPath string) ([]string, error) { |
| 190 | stdout, stderr, err := runGitCommand(repoPath, "status", "--porcelain", "--untracked-files=all") |
| 191 | if err != nil { |
| 192 | // Check if git is not installed |
| 193 | if strings.Contains(stderr, "not found") || strings.Contains(stderr, "not recognized") { |
| 194 | return nil, fmt.Errorf("git command not found - please install Git to use the --repo flag") |
| 195 | } |
| 196 | return nil, gitCommandError(err, stderr) |
| 197 | } |
| 198 | |
| 199 | // Parse the porcelain output |
| 200 | var files []string |
| 201 | lines := strings.Split(string(stdout), "\n") |
| 202 | for _, line := range lines { |
| 203 | if len(line) < 3 { |
| 204 | continue |
| 205 | } |
| 206 | |
| 207 | // Porcelain format: XY filename |
| 208 | // X = status in index, Y = status in working tree |
| 209 | // Skip deleted files (D in either position) as they don't exist on the filesystem |
| 210 | statusX := line[0] |
| 211 | statusY := line[1] |
| 212 | if statusX == 'D' || statusY == 'D' { |
| 213 | continue |
| 214 | } |
| 215 | |
| 216 | filePath := strings.TrimSpace(line[3:]) |
| 217 | |
| 218 | // Handle renamed files (format: "old -> new") |
| 219 | if strings.Contains(filePath, " -> ") { |
| 220 | parts := strings.Split(filePath, " -> ") |
| 221 | filePath = parts[1] // Use the new filename |
| 222 | } |
| 223 | |
| 224 | if filePath != "" { |
| 225 | files = append(files, filePath) |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | return files, nil |
| 230 | } |
| 231 | |
| 232 | // GetCommitDartFiles finds all files that were changed in a specific commit. |
| 233 | // Returns absolute paths to all files added, modified, or renamed in the commit. |
no test coverage detected