Skip to content

Commit

Permalink
Merge pull request #1371 from Byron/fix-empty-excludes-file
Browse files Browse the repository at this point in the history
empty paths don't error in lenient mode
  • Loading branch information
Byron authored May 17, 2024
2 parents 4735d17 + 3c7b7b3 commit 3c21741
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 1 deletion.
9 changes: 9 additions & 0 deletions gix/src/config/cache/access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,22 @@ impl Cache {
subsection_name: Option<&BStr>,
key: impl AsRef<str>,
) -> Option<Result<Cow<'_, std::path::Path>, 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,
key,
&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());
Expand Down
1 change: 0 additions & 1 deletion gix/src/repository/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Binary file modified gix/tests/fixtures/generated-archives/make_basic_repo.tar.xz
Binary file not shown.
5 changes: 5 additions & 0 deletions gix/tests/fixtures/make_basic_repo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
28 changes: 28 additions & 0 deletions gix/tests/repository/excludes.rs
Original file line number Diff line number Diff line change
@@ -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(())
}
3 changes: 3 additions & 0 deletions gix/tests/repository/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use gix::Repository;

mod config;
#[cfg(feature = "excludes")]
mod excludes;
#[cfg(feature = "attributes")]
mod filter;
mod object;
Expand Down Expand Up @@ -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),
];
Expand Down

0 comments on commit 3c21741

Please sign in to comment.