Skip to content

Commit

Permalink
improve the error message around incorrect worktree paths
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Oct 17, 2023
1 parent 886289f commit dd57957
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
7 changes: 5 additions & 2 deletions gix/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,11 @@ pub enum Error {
ResolveIncludes(#[from] gix_config::file::includes::Error),
#[error(transparent)]
FromEnv(#[from] gix_config::file::init::from_env::Error),
#[error(transparent)]
PathInterpolation(#[from] gix_config::path::interpolate::Error),
#[error("The path {path:?} at the 'core.worktree' configuration could not be interpolated")]
PathInterpolation {
path: BString,
source: gix_config::path::interpolate::Error,
},
#[error("{source:?} configuration overrides at open or init time could not be applied.")]
ConfigOverrides {
#[source]
Expand Down
6 changes: 5 additions & 1 deletion gix/src/open/repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,13 @@ impl ThreadSafeRepository {
.resolved
.path_filter("core", None, Core::WORKTREE.name, &mut filter_config_section)
{
let wt_clone = wt.clone();
let wt_path = wt
.interpolate(interpolate_context(git_install_dir.as_deref(), home.as_deref()))
.map_err(config::Error::PathInterpolation)?;
.map_err(|err| config::Error::PathInterpolation {
path: wt_clone.value.into_owned(),
source: err,
})?;
worktree_dir = gix_path::normalize(git_dir.join(wt_path).into(), current_dir).map(Cow::into_owned);
#[allow(unused_variables)]
if let Some(worktree_path) = worktree_dir.as_deref().filter(|wtd| !wtd.is_dir()) {
Expand Down
2 changes: 1 addition & 1 deletion gix/tests/repository/open.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ fn non_bare_split_worktree_invalid_worktree_path_empty() -> crate::Result {
)
.unwrap_err();
assert!(
matches!(err, gix::open::Error::Config(gix::config::Error::PathInterpolation(_))),
matches!(err, gix::open::Error::Config(gix::config::Error::PathInterpolation{..})),
"DEVIATION: could not read path at core.worktree as empty is always invalid, git tries to use an empty path, even though it's better to reject it"
);
Ok(())
Expand Down

0 comments on commit dd57957

Please sign in to comment.