(command: string)
| 2566 | * NO_COLOR=1 git status — env var prefix hides the command |
| 2567 | */ |
| 2568 | export function isNormalizedGitCommand(command: string): boolean { |
| 2569 | // Fast path: catch the most common case before any parsing |
| 2570 | if (command.startsWith('git ') || command === 'git') { |
| 2571 | return true |
| 2572 | } |
| 2573 | const stripped = stripSafeWrappers(command) |
| 2574 | const parsed = tryParseShellCommand(stripped) |
| 2575 | if (parsed.success && parsed.tokens.length > 0) { |
| 2576 | // Direct git command |
| 2577 | if (parsed.tokens[0] === 'git') { |
| 2578 | return true |
| 2579 | } |
| 2580 | // "xargs git ..." — xargs runs git in the current directory, |
| 2581 | // so it must be treated as a git command for cd+git security checks. |
| 2582 | // This matches the xargs prefix handling in filterRulesByContentsMatchingInput. |
| 2583 | if (parsed.tokens[0] === 'xargs' && parsed.tokens.includes('git')) { |
| 2584 | return true |
| 2585 | } |
| 2586 | return false |
| 2587 | } |
| 2588 | return /^git(?:\s|$)/.test(stripped) |
| 2589 | } |
| 2590 | |
| 2591 | /** |
| 2592 | * Checks if a subcommand is a cd command after normalizing away safe wrappers |
no test coverage detected