Skip to content

Commit

Permalink
env: don't store 'OPAMSWITCH' and 'OPAMROOT' in last env, they should…
Browse files Browse the repository at this point in the history
… not be reverted

They are set by '--set-switch' and '--set-root' with the idea to have them defined for the session
  • Loading branch information
rjbou authored and kit-ty-kate committed Jan 11, 2024
1 parent e0a5781 commit 7f5f055
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
10 changes: 9 additions & 1 deletion src/client/opamConfigCommand.ml
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,15 @@ let ensure_env_aux ?(base=[]) ?(set_opamroot=false) ?(set_opamswitch=false)
not (String.equal upd.envu_var "OPAM_LAST_ENV"))
updates
in
let last_env_file = write_last_env_file gt switch updates in
let last_env_file =
write_last_env_file gt switch
(* We remove OPAMSWITCH & OPAMROOT as they are not supposed
to be reverted *)
(List.filter (fun upd ->
not ((String.equal upd.envu_var "OPAMSWITCH")
|| (String.equal upd.envu_var "OPAMROOT")))
updates)
in
let updates =
OpamStd.Option.map_default (fun target ->
(env_update_resolved "OPAM_LAST_ENV" Eq
Expand Down
22 changes: 8 additions & 14 deletions tests/reftests/switch-set.test
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,15 @@ OPAMSWITCH='bar'; export OPAMSWITCH;
# OPAMSWITCH current value
bar
# opam env
OPAMSWITCH=''; export OPAMSWITCH;
# OPAMSWITCH current value
bar
# current switch
bar
# evaluate opam env
# OPAMSWITCH current value

bar
# current switch
foo
bar
### sh set-switch.sh env
# current switch
foo
Expand All @@ -142,16 +141,15 @@ OPAMSWITCH='bar'; export OPAMSWITCH;
# OPAMSWITCH current value
bar
# opam env
OPAMSWITCH=''; export OPAMSWITCH;
# OPAMSWITCH current value
bar
# current switch
bar
# evaluate opam env
# OPAMSWITCH current value

bar
# current switch
foo
bar
### opam init --bare --bypass-checks --root ./foo ./REPO -n | grep -v Cygwin
No configuration file found, using built-in defaults.

Expand Down Expand Up @@ -209,17 +207,15 @@ OPAMROOT='${BASEDIR}/bar'; export OPAMROOT;
# OPAMROOT current value
${BASEDIR}/bar
# opam env
OPAMROOT=''; export OPAMROOT;
# OPAMROOT current value
${BASEDIR}/bar
# current root
${BASEDIR}/bar
evaluate opam env
# OPAMROOT current value

${BASEDIR}/bar
# current root
[ERROR] ${BASEDIR} exists, but does not appear to be a valid opam root. Please remove it and use `opam init', or specify a different `--root' argument
# Return code 50 #
${BASEDIR}/bar
### sh set-root.sh env
# current root
${BASEDIR}/foo
Expand All @@ -231,14 +227,12 @@ OPAMROOT='${BASEDIR}/bar'; export OPAMROOT;
# OPAMROOT current value
${BASEDIR}/bar
# opam env
OPAMROOT=''; export OPAMROOT;
# OPAMROOT current value
${BASEDIR}/bar
# current root
${BASEDIR}/bar
evaluate opam env
# OPAMROOT current value

${BASEDIR}/bar
# current root
[ERROR] ${BASEDIR} exists, but does not appear to be a valid opam root. Please remove it and use `opam init', or specify a different `--root' argument
# Return code 50 #
${BASEDIR}/bar

0 comments on commit 7f5f055

Please sign in to comment.