surshar / claude-code
Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands.
Built by Anthropic · github.com/anthropics
| 1 | /** |
| 2 | * One git invocation named by what it asks: its subcommand, and its kind. |
| 3 | * |
| 4 | * For a `diff` what kind (`--shortstat`, `--numstat`, or the path its body |
| 5 | * is asked for), for a `rev-parse` whether it finds the repository |
| 6 | * (`--show-toplevel`) or reads `HEAD` (the poll's fallback where no file |
| 7 | * answers), so a test reads a session's spawns as the built-in's list. |
| 8 | * |
| 9 | * @param argv the invocation, program first, any pinned lead after it |
| 10 | * @returns `rev-parse --show-toplevel`, `status`, `diff --numstat`, ... |
| 11 | */ |
| 12 | export function gitWordOf(argv: readonly string[]) { |
| 13 | const [subcommand = '?'] = argv.filter( |
| 14 | (word, at) => at > 0 && !word.startsWith('-') && argv[at - 1] !== '-c', |
| 15 | ) |
| 16 | |
| 17 | const dashes = argv.indexOf('--') |
| 18 | |
| 19 | if (subcommand === 'rev-parse') { |
| 20 | return argv.includes('--show-toplevel') |
| 21 | ? 'rev-parse --show-toplevel' |
| 22 | : 'rev-parse HEAD' |
| 23 | } |
| 24 | |
| 25 | if (subcommand !== 'diff') { |
| 26 | return subcommand |
| 27 | } |
| 28 | |
| 29 | if (dashes !== -1) { |
| 30 | return `diff -- ${argv.slice(dashes + 1).join(' ')}` |
| 31 | } |
| 32 | |
| 33 | const stat = argv.find(word => word === '--shortstat' || word === '--numstat') |
| 34 | |
| 35 | return stat ? `diff ${stat}` : 'diff' |
| 36 | } |