Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: global hooks #3393

Merged
merged 2 commits into from
Dec 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/hook_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,15 @@ pub fn should_exit_early(watch_files: impl IntoIterator<Item = WatchFilePattern>
true
}

pub fn dir_change() -> Option<(PathBuf, PathBuf)> {
pub fn dir_change() -> Option<(Option<PathBuf>, 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,
}
Expand Down
6 changes: 3 additions & 3 deletions src/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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(),
Expand Down
Loading