diff --git a/src/API.jl b/src/API.jl index 60f3c7f84a..384d19a8b4 100644 --- a/src/API.jl +++ b/src/API.jl @@ -12,7 +12,7 @@ using Serialization import ..depots, ..depots1, ..logdir, ..devdir, ..printpkgstyle import ..Operations, ..GitTools, ..Pkg, ..Registry -import ..can_fancyprint, ..pathrepr, ..isurl +import ..can_fancyprint, ..pathrepr, ..isurl, ..PREV_ENV_PATH using ..Types, ..TOML using ..Types: VersionTypes using Base.BinaryPlatforms @@ -1527,9 +1527,11 @@ function status(ctx::Context, pkgs::Vector{PackageSpec}; diff::Bool=false, mode= end -function activate(;temp=false, shared=false, io::IO=stderr_f()) +function activate(;temp=false, shared=false, prev=false, io::IO=stderr_f()) shared && pkgerror("Must give a name for a shared environment") temp && return activate(mktempdir(); io=io) + prev && return activate(PREV_ENV_PATH[]; io=io) + PREV_ENV_PATH[] = Base.active_project() Base.ACTIVE_PROJECT[] = nothing p = Base.active_project() p === nothing || printpkgstyle(io, :Activating, "project at $(pathrepr(dirname(p)))") @@ -1585,6 +1587,7 @@ function activate(path::AbstractString; shared::Bool=false, temp::Bool=false, io fullpath = joinpath(Pkg.envdir(Pkg.depots1()), path) end end + PREV_ENV_PATH[] = Base.active_project() Base.ACTIVE_PROJECT[] = Base.load_path_expand(fullpath) p = Base.active_project() if p !== nothing diff --git a/src/Pkg.jl b/src/Pkg.jl index 33bc28b161..538ff3a572 100644 --- a/src/Pkg.jl +++ b/src/Pkg.jl @@ -37,6 +37,7 @@ const OFFLINE_MODE = Ref(false) const DEFAULT_IO = Ref{Union{IO,Nothing}}(nothing) stderr_f() = something(DEFAULT_IO[], stderr) stdout_f() = something(DEFAULT_IO[], stdout) +const PREV_ENV_PATH = Ref{String}("") can_fancyprint(io::IO) = (io isa Base.TTY) && (get(ENV, "CI", nothing) != "true") @@ -393,7 +394,7 @@ any packages listed as arguments, the output will be limited to those packages. Setting `diff=true` will, if the environment is in a git repository, limit the output to the difference as compared to the last git commit. -See [`Pkg.project`](@ref) and [`Pkg.dependencies`](@ref) to get the project/manifest +See [`Pkg.project`](@ref) and [`Pkg.dependencies`](@ref) to get the project/manifest status as a Julia object instead of printing it. !!! compat "Julia 1.1" diff --git a/src/REPLMode/argument_parsers.jl b/src/REPLMode/argument_parsers.jl index 0884937566..2ad9188c2f 100644 --- a/src/REPLMode/argument_parsers.jl +++ b/src/REPLMode/argument_parsers.jl @@ -195,7 +195,10 @@ function parse_activate(args::Vector{QString}, options) return [x.raw] end x = x.raw - if first(x) == '@' + if x == "-" + options[:prev] = true + return [] + elseif first(x) == '@' options[:shared] = true return [x[2:end]] else diff --git a/test/new.jl b/test/new.jl index 4696c55ef1..5f5793f206 100644 --- a/test/new.jl +++ b/test/new.jl @@ -325,6 +325,10 @@ end api, opts = first(Pkg.pkg"activate --temp") @test api == Pkg.activate @test opts == Dict(:temp => true) + # - activating the previous project + api, opts = first(Pkg.pkg"activate -") + @test api == Pkg.activate + @test opts == Dict(:prev => true) end end @@ -337,6 +341,23 @@ end Pkg.activate(; io=io, temp=true) output = String(take!(io)) @test occursin(r"Activating new project at `.*`", output) + prev_env = Base.active_project() + + # - activating the previous project + Pkg.activate(; temp=true) + @test prev_env != Base.active_project() + Pkg.activate(; prev=true) + @test prev_env == Base.active_project() + + Pkg.activate(; temp=true) + @test prev_env != Base.active_project() + Pkg.activate(; prev=true) + @test prev_env == Base.active_project() + + Pkg.activate("") + @test prev_env != Base.active_project() + Pkg.activate(; prev=true) + @test prev_env == Base.active_project() end end