|
1 | 1 | import * as vscode from 'vscode' |
2 | | -import { execSync } from 'child_process' |
| 2 | +import { execSync, execFileSync } from 'child_process' |
3 | 3 | import { get_git_repository } from '@/utils/git-repository-utils' |
| 4 | +import { is_valid_git_branch_name } from '@/utils/is-valid-git-branch-name' |
4 | 5 | import { AsciiTree } from '@/utils/ascii-tree/ascii-tree' |
5 | 6 | import { Logger } from '@shared/utils/logger' |
6 | 7 | import { t } from '@/i18n' |
@@ -156,6 +157,23 @@ export const replace_changes_symbol = async (params: { |
156 | 157 | if (multi_root_match) { |
157 | 158 | const [, folder_name, branch_name] = multi_root_match |
158 | 159 |
|
| 160 | + if (!is_valid_git_branch_name(branch_name)) { |
| 161 | + vscode.window.showErrorMessage( |
| 162 | + t('common.error.failed-to-get-changes-from-branch-in-folder', { |
| 163 | + branch_name, |
| 164 | + folder_name |
| 165 | + }) |
| 166 | + ) |
| 167 | + if (params.symbols_cache) { |
| 168 | + params.symbols_cache.set(full_match, '', '') |
| 169 | + } |
| 170 | + result_instructions[i] = result_instructions[i].replace( |
| 171 | + replacement_regex, |
| 172 | + '' |
| 173 | + ) |
| 174 | + continue |
| 175 | + } |
| 176 | + |
159 | 177 | const workspace_folders = vscode.workspace.workspaceFolders |
160 | 178 | if (!workspace_folders) { |
161 | 179 | vscode.window.showErrorMessage( |
@@ -221,16 +239,19 @@ export const replace_changes_symbol = async (params: { |
221 | 239 |
|
222 | 240 | let diff_base: string |
223 | 241 | if (current_branch == branch_name) { |
224 | | - diff_base = execSync(`git merge-base HEAD ${branch_name}`, { |
225 | | - cwd: target_folder.uri.fsPath |
226 | | - }) |
| 242 | + diff_base = execFileSync( |
| 243 | + 'git', |
| 244 | + ['merge-base', 'HEAD', branch_name], |
| 245 | + { |
| 246 | + cwd: target_folder.uri.fsPath |
| 247 | + } |
| 248 | + ) |
227 | 249 | .toString() |
228 | 250 | .trim() |
229 | 251 | } else { |
230 | 252 | diff_base = branch_name |
231 | 253 | } |
232 | | - const diff_command = `git diff ${diff_base}` |
233 | | - const diff = execSync(diff_command, { |
| 254 | + const diff = execFileSync('git', ['diff', diff_base, '--'], { |
234 | 255 | cwd: target_folder.uri.fsPath |
235 | 256 | }).toString() |
236 | 257 |
|
@@ -296,6 +317,21 @@ export const replace_changes_symbol = async (params: { |
296 | 317 | } |
297 | 318 | } else { |
298 | 319 | const branch_name = branch_spec |
| 320 | + |
| 321 | + if (!is_valid_git_branch_name(branch_name)) { |
| 322 | + vscode.window.showErrorMessage( |
| 323 | + t('common.error.failed-to-get-changes-from-branch', { branch_name }) |
| 324 | + ) |
| 325 | + if (params.symbols_cache) { |
| 326 | + params.symbols_cache.set(full_match, '', '') |
| 327 | + } |
| 328 | + result_instructions[i] = result_instructions[i].replace( |
| 329 | + replacement_regex, |
| 330 | + '' |
| 331 | + ) |
| 332 | + continue |
| 333 | + } |
| 334 | + |
299 | 335 | const repository = await get_git_repository() |
300 | 336 | if (!repository) { |
301 | 337 | vscode.window.showErrorMessage( |
@@ -344,16 +380,19 @@ export const replace_changes_symbol = async (params: { |
344 | 380 |
|
345 | 381 | let diff_base: string |
346 | 382 | if (current_branch == branch_name) { |
347 | | - diff_base = execSync(`git merge-base HEAD ${branch_name}`, { |
348 | | - cwd: repository.rootUri.fsPath |
349 | | - }) |
| 383 | + diff_base = execFileSync( |
| 384 | + 'git', |
| 385 | + ['merge-base', 'HEAD', branch_name], |
| 386 | + { |
| 387 | + cwd: repository.rootUri.fsPath |
| 388 | + } |
| 389 | + ) |
350 | 390 | .toString() |
351 | 391 | .trim() |
352 | 392 | } else { |
353 | 393 | diff_base = branch_name |
354 | 394 | } |
355 | | - const diff_command = `git diff ${diff_base}` |
356 | | - const diff = execSync(diff_command, { |
| 395 | + const diff = execFileSync('git', ['diff', diff_base, '--'], { |
357 | 396 | cwd: repository.rootUri.fsPath |
358 | 397 | }).toString() |
359 | 398 |
|
|
0 commit comments