* 获取执行预览
(
command: string,
workingDirectory: string,
_params: Record<string, any>
)
| 191 | * 获取执行预览 |
| 192 | */ |
| 193 | protected async getExecutionPreview( |
| 194 | command: string, |
| 195 | workingDirectory: string, |
| 196 | _params: Record<string, any> |
| 197 | ): Promise<string> { |
| 198 | try { |
| 199 | // 显示当前未暂存的文件 |
| 200 | const { stdout: statusOutput } = await execAsync('git status --porcelain', { |
| 201 | cwd: workingDirectory, |
| 202 | timeout: 5000, |
| 203 | }); |
| 204 | |
| 205 | if (!statusOutput.trim()) { |
| 206 | return '没有需要添加的文件'; |
| 207 | } |
| 208 | |
| 209 | let preview = '待添加的文件:\n'; |
| 210 | const lines = statusOutput.split('\n').filter(line => line.trim()); |
| 211 | |
| 212 | for (const line of lines) { |
| 213 | const status = line.substring(0, 2); |
| 214 | const file = line.substring(3); |
| 215 | |
| 216 | // 只显示未暂存的文件 |
| 217 | if (status[1] !== ' ') { |
| 218 | let statusText = ''; |
| 219 | if (status[1] === 'M') statusText = '修改'; |
| 220 | else if (status.includes('?')) statusText = '新文件'; |
| 221 | else if (status[1] === 'D') statusText = '删除'; |
| 222 | else statusText = '其他'; |
| 223 | |
| 224 | preview += ` ${statusText}: ${file}\n`; |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | return preview || '没有未暂存的文件需要添加'; |
| 229 | } catch (error) { |
| 230 | return '无法获取预览信息'; |
| 231 | } |
| 232 | } |
| 233 | |
| 234 | /** |
| 235 | * 后处理结果 |
no test coverage detected