Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/API.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)))")
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/Pkg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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"
Expand Down
5 changes: 4 additions & 1 deletion src/REPLMode/argument_parsers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions test/new.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down