Skip to content

Commit

Permalink
hook-env: use new non-aggressive PATH logic only in experimental mode
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Dec 13, 2023
1 parent 743321d commit 27f7f2f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions e2e/cd/test_bash
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# shellcheck disable=SC2088
set -euo pipefail

export RTX_EXPERIMENTAL=1
orig_path="$PATH"

# shellcheck disable=SC1090
Expand Down
10 changes: 7 additions & 3 deletions src/cli/hook_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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)?);

Expand Down Expand Up @@ -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))

Check warning on line 99 in src/cli/hook_env.rs

View check run for this annotation

Codecov / codecov/patch

src/cli/hook_env.rs#L98-L99

Added lines #L98 - L99 were not covered by tests
}
_ => (String::new(), full),

Check warning on line 101 in src/cli/hook_env.rs

View check run for this annotation

Codecov / codecov/patch

src/cli/hook_env.rs#L101

Added line #L101 was not covered by tests
},
None => (String::new(), full),
};
Expand Down

0 comments on commit 27f7f2f

Please sign in to comment.