MCPcopy Create free account
hub / github.com/echoVic/blade-code / getExecutionPreview

Method getExecutionPreview

src/tools/builtin/git/git-add.ts:193–232  ·  view source on GitHub ↗

* 获取执行预览

(
    command: string,
    workingDirectory: string,
    _params: Record<string, any>
  )

Source from the content-addressed store, hash-verified

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 * 后处理结果

Callers 1

confirmExecutionFunction · 0.45

Calls 1

filterMethod · 0.45

Tested by

no test coverage detected