Returns `true` when `command` is a git invocation that changes the working tree / HEAD enough that a broad re-sync is warranted (checkout, switch, pull, merge, rebase, reset, cherry-pick, `stash pop`/`stash apply`). Read-only git commands (`status`, `log`, `diff`), `commit`/`add`, and non-git commands return `false`. Only commands whose first token is `git` match, so `echo git checkout` is ignore
(command: &str)
| 12 | /// non-git commands return `false`. Only commands whose first token is `git` |
| 13 | /// match, so `echo git checkout` is ignored. |
| 14 | pub fn is_git_state_changing_command(command: &str) -> bool { |
| 15 | let tokens = shell_words(command); |
| 16 | let Some(sub_pos) = git_subcommand_pos(&tokens) else { |
| 17 | return false; |
| 18 | }; |
| 19 | let sub = tokens[sub_pos].to_ascii_lowercase(); |
| 20 | match sub.as_str() { |
| 21 | "checkout" | "switch" | "pull" | "merge" | "rebase" | "reset" | "cherry-pick" => true, |
| 22 | "stash" => { |
| 23 | let after = tokens |
| 24 | .iter() |
| 25 | .skip(sub_pos + 1) |
| 26 | .map(|t| t.to_ascii_lowercase()) |
| 27 | .find(|t| !t.starts_with('-')); |
| 28 | matches!(after.as_deref(), Some("pop" | "apply")) |
| 29 | } |
| 30 | _ => false, |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | /// The action a Cursor `afterShellExecution` hook should take for a command. |
| 35 | #[derive(Debug, Clone, PartialEq, Eq)] |
no test coverage detected