mirror of
https://github.com/pchuan98/codex.git
synced 2026-07-01 00:31:56 +08:00
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:
@@ -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"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user