fix: don't auto approve git -C ... (#20085)

It's safer to make sure these commands go through approval flows.
This commit is contained in:
Owen Lin
2026-04-28 22:06:55 +00:00
committed by GitHub
parent 66b0781502
commit 2e598df6fc
2 changed files with 33 additions and 16 deletions
@@ -58,7 +58,10 @@ fn is_git_global_option_with_inline_value(arg: &str) -> bool {
pub(crate) fn git_global_option_requires_prompt(arg: &str) -> bool {
matches!(
arg,
"-c" | "--config-env"
// `-C` can redirect Git into a repo whose config runs helpers such as
// `core.fsmonitor` during read-only commands like `status`.
"-C" | "-c"
| "--config-env"
| "--exec-path"
| "--git-dir"
| "--namespace"
@@ -66,7 +69,7 @@ pub(crate) fn git_global_option_requires_prompt(arg: &str) -> bool {
| "--work-tree"
) || matches!(
arg,
s if (s.starts_with("-c") && s.len() > 2)
s if ((s.starts_with("-C") || s.starts_with("-c")) && s.len() > 2)
|| s.starts_with("--config-env=")
|| s.starts_with("--exec-path=")
|| s.starts_with("--git-dir=")
@@ -181,4 +184,10 @@ mod tests {
fn rm_f_is_dangerous() {
assert!(command_might_be_dangerous(&vec_str(&["rm", "-f", "/"])));
}
#[test]
fn git_dash_c_requires_prompt() {
assert!(git_global_option_requires_prompt("-C"));
assert!(git_global_option_requires_prompt("-C/path/to/repo"));
}
}