getUncommittedFileStatuses returns a map of relative file paths to their git status codes
(repoPath string)
| 294 | |
| 295 | // getUncommittedFileStatuses returns a map of relative file paths to their git status codes |
| 296 | func getUncommittedFileStatuses(repoPath string) (map[string]string, error) { |
| 297 | stdout, stderr, err := runGitCommand(repoPath, "status", "--porcelain", "--untracked-files=all") |
| 298 | if err != nil { |
| 299 | return nil, gitCommandError(err, stderr) |
| 300 | } |
| 301 | |
| 302 | statuses := make(map[string]string) |
| 303 | lines := strings.Split(string(stdout), "\n") |
| 304 | for _, line := range lines { |
| 305 | if len(line) < 4 { |
| 306 | continue |
| 307 | } |
| 308 | |
| 309 | status := line[:2] |
| 310 | filePath := strings.TrimSpace(line[3:]) |
| 311 | |
| 312 | // Handle renamed files (format: "old -> new") |
| 313 | if strings.Contains(filePath, " -> ") { |
| 314 | parts := strings.Split(filePath, " -> ") |
| 315 | filePath = parts[1] |
| 316 | } |
| 317 | |
| 318 | if filePath == "" { |
| 319 | continue |
| 320 | } |
| 321 | |
| 322 | normalized := filepath.Clean(filePath) |
| 323 | statuses[normalized] = status |
| 324 | } |
| 325 | |
| 326 | return statuses, nil |
| 327 | } |
| 328 | |
| 329 | // getCommitFileStatuses returns a map of file paths to their status codes for a commit |
| 330 | func getCommitFileStatuses(repoPath, commitID string) (map[string]string, error) { |
no test coverage detected