From 27f7f2f37d1695eb5a73836c6c41c4604d5d5b7b Mon Sep 17 00:00:00 2001 From: Jeff Dickey <216188+jdx@users.noreply.github.com> Date: Wed, 13 Dec 2023 00:33:07 -0600 Subject: [PATCH] hook-env: use new non-aggressive PATH logic only in experimental mode --- e2e/cd/test_bash | 1 + src/cli/hook_env.rs | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/e2e/cd/test_bash b/e2e/cd/test_bash index 60b827f769..131c2ab289 100755 --- a/e2e/cd/test_bash +++ b/e2e/cd/test_bash @@ -2,6 +2,7 @@ # shellcheck disable=SC2088 set -euo pipefail +export RTX_EXPERIMENTAL=1 orig_path="$PATH" # shellcheck disable=SC1090 diff --git a/src/cli/hook_env.rs b/src/cli/hook_env.rs index defd7bc366..7df80c1072 100644 --- a/src/cli/hook_env.rs +++ b/src/cli/hook_env.rs @@ -10,6 +10,7 @@ use terminal_size::{terminal_size, Width}; use crate::config::Config; +use crate::config::Settings; use crate::direnv::DirenvDiff; use crate::env::__RTX_DIFF; use crate::env_diff::{EnvDiff, EnvDiffOperation}; @@ -48,7 +49,7 @@ impl HookEnv { paths.extend(ts.list_paths(&config)); // load the active runtime paths diff.path = paths.clone(); // update __RTX_DIFF with the new paths for the next run - patches.extend(self.build_path_operations(&paths, &__RTX_DIFF.path)?); + patches.extend(self.build_path_operations(&config.settings, &paths, &__RTX_DIFF.path)?); patches.push(self.build_diff_operation(&diff)?); patches.push(self.build_watch_operation(&config)?); @@ -87,14 +88,17 @@ impl HookEnv { /// modifies the PATH and optionally DIRENV_DIFF env var if it exists fn build_path_operations( &self, + settings: &Settings, installs: &Vec<PathBuf>, to_remove: &Vec<PathBuf>, ) -> Result<Vec<EnvDiffOperation>> { let full = join_paths(&*env::PATH)?.to_string_lossy().to_string(); let (pre, post) = match &*env::__RTX_ORIG_PATH { Some(orig_path) => match full.split_once(&format!(":{orig_path}")) { - Some((pre, post)) => (pre.to_string(), (orig_path.to_string() + post)), - None => (String::new(), full), + Some((pre, post)) if settings.experimental => { + (pre.to_string(), (orig_path.to_string() + post)) + } + _ => (String::new(), full), }, None => (String::new(), full), };