* Get git status including current branch, HEAD commit, and working tree changes * Excludes binary files from patches and truncates large patches
(params: GitStatusParams)
| 1138 | * Excludes binary files from patches and truncates large patches |
| 1139 | */ |
| 1140 | async function handleGetGitStatus(params: GitStatusParams): Promise<GitStatusResponse> { |
| 1141 | const startTime = Date.now() |
| 1142 | logger.info("[Git:getGitStatus] Getting git status", JSON.stringify({ |
| 1143 | repoDir: params.repoDir, |
| 1144 | workTreeId: params.workTreeId, |
| 1145 | })) |
| 1146 | |
| 1147 | try { |
| 1148 | const workingDir = await resolveWorkingDirFromGitStatusParams(params) |
| 1149 | const summary = await collectGitSummaryData(workingDir) |
| 1150 | |
| 1151 | // Get staged changes (diff --cached) |
| 1152 | const stagedDiffResult = await execGit(["diff", "--cached"], workingDir) |
| 1153 | const stagedPatchRaw = stagedDiffResult.success ? stagedDiffResult.stdout : "" |
| 1154 | const { patch: stagedPatch, truncated: stagedTruncated } = truncatePatch(stagedPatchRaw) |
| 1155 | |
| 1156 | // Get unstaged changes (diff without --cached) |
| 1157 | const unstagedDiffResult = await execGit(["diff"], workingDir) |
| 1158 | const unstagedPatchRaw = unstagedDiffResult.success ? unstagedDiffResult.stdout : "" |
| 1159 | const { patch: unstagedPatch, truncated: unstagedTruncated } = truncatePatch(unstagedPatchRaw) |
| 1160 | |
| 1161 | logger.info("[Git:getGitStatus] Status retrieved", JSON.stringify({ |
| 1162 | branch: summary.branch, |
| 1163 | headCommit: summary.headCommit, |
| 1164 | hasChanges: summary.hasChanges, |
| 1165 | stagedCount: summary.staged.files.length, |
| 1166 | unstagedCount: summary.unstaged.files.length, |
| 1167 | untrackedCount: summary.untracked.length, |
| 1168 | stagedTruncated, |
| 1169 | unstagedTruncated, |
| 1170 | duration: Date.now() - startTime, |
| 1171 | })) |
| 1172 | |
| 1173 | return { |
| 1174 | branch: summary.branch, |
| 1175 | headCommit: summary.headCommit, |
| 1176 | ahead: summary.ahead, |
| 1177 | hasChanges: summary.hasChanges, |
| 1178 | staged: { |
| 1179 | files: summary.staged.files, |
| 1180 | patch: stagedPatch, |
| 1181 | stats: summary.staged.stats, |
| 1182 | }, |
| 1183 | unstaged: { |
| 1184 | files: summary.unstaged.files, |
| 1185 | patch: unstagedPatch, |
| 1186 | stats: summary.unstaged.stats, |
| 1187 | }, |
| 1188 | untracked: summary.untracked, |
| 1189 | } |
| 1190 | } catch (error: any) { |
| 1191 | logger.error("[Git:getGitStatus] Error:", JSON.stringify({ error: error.message, stack: error.stack, duration: Date.now() - startTime })) |
| 1192 | throw error |
| 1193 | } |
| 1194 | } |
| 1195 | |
| 1196 | /** |
| 1197 | * List files with optional fuzzy search (supports subdirectories) |
no test coverage detected