Add global and .git/info/exclude ignore files

This commit is contained in:
Paul Nameless 2025-04-13 16:56:27 +02:00
parent dfae07e69c
commit ac25d05e27

View file

@ -3147,12 +3147,53 @@ async fn build_gitignore(abs_path: &Path, fs: &dyn Fs) -> Result<Gitignore> {
let mut combined_builder = GitignoreBuilder::new(parent);
let home = home_dir();
if !home.as_os_str().is_empty() {
let global_ignore_path = home.join(".config/git/ignore");
let repo_root = abs_path.parent().unwrap_or_else(|| Path::new("/"));
let repo_git_path = repo_root.join(".git");
let repo_git_config_path = repo_git_path.join("config");
let mut global_ignore_path = None;
if let Ok(config_output) = std::process::Command::new("git")
.args(["config", "--file", &repo_git_config_path.to_string_lossy(), "core.excludesFile"])
.output()
{
if config_output.status.success() {
let path_str = String::from_utf8_lossy(&config_output.stdout).trim().to_string();
if !path_str.is_empty() {
let path = PathBuf::from(path_str);
global_ignore_path = Some(path);
}
}
}
if global_ignore_path.is_none() {
if let Ok(config_output) = std::process::Command::new("git")
.args(["config", "--global", "core.excludesFile"])
.output()
{
if config_output.status.success() {
let path_str = String::from_utf8_lossy(&config_output.stdout).trim().to_string();
if !path_str.is_empty() {
let path = PathBuf::from(path_str);
global_ignore_path = Some(path);
}
}
}
}
if global_ignore_path.is_none() && !home.as_os_str().is_empty() {
global_ignore_path = Some(home.join(".config/git/ignore"));
}
let repo_git_exclude_path = repo_git_path.join("info/exclude");
if let Ok(exclude_contents) = fs.load(&repo_git_exclude_path).await {
for line in exclude_contents.lines() {
let _ = combined_builder.add_line(Some(repo_git_exclude_path.clone()), line);
}
}
if let Some(global_ignore_path) = global_ignore_path {
if let Ok(global_contents) = fs.load(&global_ignore_path).await {
for line in global_contents.lines() {
// Ignore errors for global gitignore entries, as we don't want to block
// local gitignore functionality if the global one has issues
let _ = combined_builder.add_line(Some(global_ignore_path.clone()), line);
}
}