( status: StatusResult, )
| 29 | } |
| 30 | |
| 31 | export function parseGitStatus( |
| 32 | status: StatusResult, |
| 33 | ): Pick<GitChangesStatus, "branch" | "staged" | "unstaged" | "untracked"> { |
| 34 | const staged: ChangedFile[] = []; |
| 35 | const unstaged: ChangedFile[] = []; |
| 36 | const untracked: ChangedFile[] = []; |
| 37 | |
| 38 | for (const file of status.files) { |
| 39 | const path = file.path; |
| 40 | const index = file.index; |
| 41 | const working = file.working_dir; |
| 42 | |
| 43 | if (index === "?" && working === "?") { |
| 44 | untracked.push(toChangedFile(path, index, working)); |
| 45 | continue; |
| 46 | } |
| 47 | |
| 48 | if (index && index !== " " && index !== "?") { |
| 49 | staged.push({ |
| 50 | path, |
| 51 | oldPath: file.path !== file.from ? file.from : undefined, |
| 52 | status: mapGitStatus(index, " "), |
| 53 | additions: 0, |
| 54 | deletions: 0, |
| 55 | }); |
| 56 | } |
| 57 | |
| 58 | if (working && working !== " " && working !== "?") { |
| 59 | unstaged.push({ |
| 60 | path, |
| 61 | status: mapGitStatus(" ", working), |
| 62 | additions: 0, |
| 63 | deletions: 0, |
| 64 | }); |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | return { |
| 69 | branch: status.current || "HEAD", |
| 70 | staged, |
| 71 | unstaged, |
| 72 | untracked, |
| 73 | }; |
| 74 | } |
| 75 | |
| 76 | export function parseGitLog(logOutput: string): CommitInfo[] { |
| 77 | if (!logOutput.trim()) return []; |
no test coverage detected