diff --git a/gix/src/config/cache/access.rs b/gix/src/config/cache/access.rs index 660ab771a7a..f35699aa09d 100644 --- a/gix/src/config/cache/access.rs +++ b/gix/src/config/cache/access.rs @@ -219,6 +219,8 @@ impl Cache { subsection_name: Option<&BStr>, key: impl AsRef, ) -> Option, gix_config::path::interpolate::Error>> { + let section_name = section_name.as_ref(); + let key = key.as_ref(); let path = self.resolved.path_filter( section_name, subsection_name, @@ -226,6 +228,13 @@ impl Cache { &mut self.filter_config_section.clone(), )?; + if self.lenient_config && path.is_empty() { + gix_trace::info!( + "Ignored empty path at {section_name}.{subsection_name:?}.{key} due to lenient configuration" + ); + return None; + } + let install_dir = crate::path::install_dir().ok(); let home = self.home_dir(); let ctx = config::cache::interpolate_context(install_dir.as_deref(), home.as_deref()); diff --git a/gix/src/repository/attributes.rs b/gix/src/repository/attributes.rs index 06bcb569970..55e28e3ff49 100644 --- a/gix/src/repository/attributes.rs +++ b/gix/src/repository/attributes.rs @@ -105,7 +105,6 @@ impl Repository { /// /// When only excludes are desired, this is the most efficient way to obtain them. Otherwise use /// [`Repository::attributes()`] for accessing both attributes and excludes. - // TODO: test #[doc(alias = "is_path_ignored", alias = "git2")] #[cfg(feature = "excludes")] pub fn excludes( diff --git a/gix/tests/fixtures/generated-archives/make_basic_repo.tar.xz b/gix/tests/fixtures/generated-archives/make_basic_repo.tar.xz index dc37073d9cd..454da7b4bb1 100644 Binary files a/gix/tests/fixtures/generated-archives/make_basic_repo.tar.xz and b/gix/tests/fixtures/generated-archives/make_basic_repo.tar.xz differ diff --git a/gix/tests/fixtures/make_basic_repo.sh b/gix/tests/fixtures/make_basic_repo.sh index ac50aea64cb..4bf4b59cac7 100755 --- a/gix/tests/fixtures/make_basic_repo.sh +++ b/gix/tests/fixtures/make_basic_repo.sh @@ -31,4 +31,9 @@ git init all-untracked >a mkdir d >d/a +) + +git init empty-core-excludes +(cd empty-core-excludes + echo $'[core]\n\texcludesFile = ' >> .git/config ) \ No newline at end of file diff --git a/gix/tests/repository/excludes.rs b/gix/tests/repository/excludes.rs new file mode 100644 index 00000000000..5904b4be425 --- /dev/null +++ b/gix/tests/repository/excludes.rs @@ -0,0 +1,28 @@ +use crate::util::named_subrepo_opts; +use gix_worktree::stack::state::ignore::Source; + +#[test] +fn empty_core_excludes() -> crate::Result { + let repo = named_subrepo_opts( + "make_basic_repo.sh", + "empty-core-excludes", + gix::open::Options::default().strict_config(true), + )?; + let index = repo.index_or_empty()?; + match repo.excludes(&index, None, Source::WorktreeThenIdMappingIfNotSkipped) { + Ok(_) => { + unreachable!("Should fail due to empty excludes path") + } + Err(err) => { + assert_eq!( + err.to_string(), + "The value for `core.excludesFile` could not be read from configuration" + ); + } + }; + + let repo = gix::open_opts(repo.git_dir(), repo.open_options().clone().strict_config(false))?; + repo.excludes(&index, None, Source::WorktreeThenIdMappingIfNotSkipped) + .expect("empty paths are now just skipped"); + Ok(()) +} diff --git a/gix/tests/repository/mod.rs b/gix/tests/repository/mod.rs index 646d08c6829..750987bc590 100644 --- a/gix/tests/repository/mod.rs +++ b/gix/tests/repository/mod.rs @@ -1,6 +1,8 @@ use gix::Repository; mod config; +#[cfg(feature = "excludes")] +mod excludes; #[cfg(feature = "attributes")] mod filter; mod object; @@ -38,6 +40,7 @@ mod dirwalk { ("all-untracked".to_string(), Repository), ("bare-repo-with-index.git".to_string(), Directory), ("bare.git".into(), Directory), + ("empty-core-excludes".into(), Repository), ("non-bare-repo-without-index".into(), Repository), ("some".into(), Directory), ];