MCPcopy Index your code
hub / github.com/21st-dev/1code / parseGitStatus

Function parseGitStatus

src/main/lib/git/utils/parse-status.ts:31–74  ·  view source on GitHub ↗
(
	status: StatusResult,
)

Source from the content-addressed store, hash-verified

29}
30
31export 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
76export function parseGitLog(logOutput: string): CommitInfo[] {
77 if (!logOutput.trim()) return [];

Callers 1

createStatusRouterFunction · 0.90

Calls 2

toChangedFileFunction · 0.85
mapGitStatusFunction · 0.85

Tested by

no test coverage detected