Skip to content

Commit

Permalink
[REPL] Fix #55850 by using safe_realpath instead of abspath in `p…
Browse files Browse the repository at this point in the history
…rojname` (#55851)
  • Loading branch information
christiangnrd authored Oct 5, 2024
1 parent 3a132cf commit fb77d60
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion stdlib/REPL/src/Pkg_beforeload.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ function projname(project_file::String)
end
for depot in Base.DEPOT_PATH
envdir = joinpath(depot, "environments")
if startswith(abspath(project_file), abspath(envdir))
if startswith(safe_realpath(project_file), safe_realpath(envdir))
return "@" * name
end
end
Expand Down
11 changes: 10 additions & 1 deletion stdlib/REPL/test/repl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1966,11 +1966,20 @@ end

@testset "Dummy Pkg prompt" begin
# do this in an empty depot to test default for new users
withenv("JULIA_DEPOT_PATH" => mktempdir(), "JULIA_LOAD_PATH" => nothing) do
withenv("JULIA_DEPOT_PATH" => mktempdir() * (Sys.iswindows() ? ";" : ":"), "JULIA_LOAD_PATH" => nothing) do
prompt = readchomp(`$(Base.julia_cmd()[1]) --startup-file=no -e "using REPL; print(REPL.Pkg_promptf())"`)
@test prompt == "(@v$(VERSION.major).$(VERSION.minor)) pkg> "
end

# Issue 55850
tmp_55850 = mktempdir()
tmp_sym_link = joinpath(tmp_55850, "sym")
symlink(tmp_55850, tmp_sym_link; dir_target=true)
withenv("JULIA_DEPOT_PATH" => tmp_sym_link * (Sys.iswindows() ? ";" : ":"), "JULIA_LOAD_PATH" => nothing) do
prompt = readchomp(`$(Base.julia_cmd()[1]) --startup-file=no -e "using REPL; print(REPL.projname(REPL.find_project_file()))"`)
@test prompt == "@v$(VERSION.major).$(VERSION.minor)"
end

get_prompt(proj::String) = readchomp(`$(Base.julia_cmd()[1]) --startup-file=no $(proj) -e "using REPL; print(REPL.Pkg_promptf())"`)

@test get_prompt("--project=$(pkgdir(REPL))") == "(REPL) pkg> "
Expand Down

0 comments on commit fb77d60

Please sign in to comment.