diff --git a/src/client/opamConfigCommand.ml b/src/client/opamConfigCommand.ml index 83bcca450f7..ccae3369d26 100644 --- a/src/client/opamConfigCommand.ml +++ b/src/client/opamConfigCommand.ml @@ -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 diff --git a/tests/reftests/switch-set.test b/tests/reftests/switch-set.test index ed033e00ea9..190d27eda42 100644 --- a/tests/reftests/switch-set.test +++ b/tests/reftests/switch-set.test @@ -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 @@ -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. @@ -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 @@ -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