| 509 | } |
| 510 | |
| 511 | fn is_ignored_by_git(project_path: &Path, git_config_global: Option<&Path>) -> Option<bool> { |
| 512 | let fallback_global_excludes = || { |
| 513 | git_config_global |
| 514 | .and_then(|path| is_ignored_by_explicit_global_excludes(project_path, path)) |
| 515 | }; |
| 516 | let dir_name = active_data_dir_name(project_path); |
| 517 | let mut command = Command::new(crate::git::git_program()); |
| 518 | command |
| 519 | .arg("-C") |
| 520 | .arg(project_path) |
| 521 | .arg("check-ignore") |
| 522 | .arg("-q") |
| 523 | .arg(format!("{dir_name}/")) |
| 524 | .stdout(Stdio::null()) |
| 525 | .stderr(Stdio::null()); |
| 526 | |
| 527 | if let Some(path) = git_config_global { |
| 528 | command.env_clear(); |
| 529 | command.env("PATH", git_subprocess_path()); |
| 530 | command.env("GIT_CONFIG_GLOBAL", path); |
| 531 | command.env("GIT_CONFIG_NOSYSTEM", "1"); |
| 532 | } |
| 533 | |
| 534 | let Ok(status) = command.status() else { |
| 535 | return fallback_global_excludes(); |
| 536 | }; |
| 537 | |
| 538 | match status.code() { |
| 539 | Some(0) => Some(true), |
| 540 | Some(1) => Some(false), |
| 541 | _ => fallback_global_excludes(), |
| 542 | } |
| 543 | } |
| 544 | |
| 545 | fn is_ignored_by_explicit_global_excludes( |
| 546 | project_path: &Path, |