diff --git a/src/hook_env.rs b/src/hook_env.rs index 78cbec5628..d448c620ef 100644 --- a/src/hook_env.rs +++ b/src/hook_env.rs @@ -64,11 +64,15 @@ pub fn should_exit_early(watch_files: impl IntoIterator true } -pub fn dir_change() -> Option<(PathBuf, PathBuf)> { +pub fn dir_change() -> Option<(Option, PathBuf)> { match (&*env::__MISE_DIR, &*dirs::CWD) { (Some(old), Some(new)) if old != new => { trace!("dir change: {:?} -> {:?}", old, new); - Some((old.clone(), new.clone())) + Some((Some(old.clone()), new.clone())) + } + (None, Some(new)) => { + trace!("dir change: None -> {:?}", new); + Some((None, new.clone())) } _ => None, } diff --git a/src/hooks.rs b/src/hooks.rs index 03b274a165..a9f829deda 100644 --- a/src/hooks.rs +++ b/src/hooks.rs @@ -65,7 +65,7 @@ pub fn run_one_hook(ts: &Toolset, hook: Hooks) { if !new.starts_with(&root) { continue; } - if old.starts_with(&root) { + if old.is_some_and(|old| old.starts_with(&root)) { continue; } } @@ -74,7 +74,7 @@ pub fn run_one_hook(ts: &Toolset, hook: Hooks) { if new.starts_with(&root) { continue; } - if !old.starts_with(&root) { + if old.is_some_and(|old| !old.starts_with(&root)) { continue; } } @@ -110,7 +110,7 @@ fn execute(ts: &Toolset, root: &Path, hook: &Hook) -> Result<()> { "MISE_PROJECT_ROOT".to_string(), root.to_string_lossy().to_string(), ); - if let Some((old, _new)) = hook_env::dir_change() { + if let Some((Some(old), _new)) = hook_env::dir_change() { env.insert( "MISE_PREVIOUS_DIR".to_string(), old.to_string_lossy().to_string(),