Skip to content

Commit

Permalink
fix printing paths when pwd is not in the project (#217)
Browse files Browse the repository at this point in the history
(cherry picked from commit 6f0ff7f1eb2d0103518ef9e91abf13723c8a497e)
  • Loading branch information
KristofferC committed Mar 23, 2018
1 parent baf7b61 commit dd96c7d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 16 deletions.
2 changes: 1 addition & 1 deletion stdlib/Pkg3/src/API.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function up(ctx::Context, pkgs::Vector{PackageSpec};
else
for reg in registries()
if isdir(joinpath(reg, ".git"))
regpath = pathrepr(reg)
regpath = pathrepr(ctx, reg)
printpkgstyle(ctx, :Updating, "registry at ", regpath)
LibGit2.with(LibGit2.GitRepo, reg) do repo
if LibGit2.isdirty(repo)
Expand Down
2 changes: 1 addition & 1 deletion stdlib/Pkg3/src/Operations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,7 @@ function build_versions(ctx::Context, uuids::Vector{UUID}; might_need_to_resolve
for (uuid, name, hash_or_path, build_file) in builds
log_file = splitext(build_file)[1] * ".log"
printpkgstyle(ctx, :Building,
rpad(name * " ", max_name + 1, ""), "", Types.pathrepr(log_file))
rpad(name * " ", max_name + 1, ""), "", Types.pathrepr(ctx, log_file))

code = """
empty!(Base.DEPOT_PATH)
Expand Down
19 changes: 5 additions & 14 deletions stdlib/Pkg3/src/Types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1180,22 +1180,13 @@ function printpkgstyle(ctx::Context, cmd::Symbol, text::String...; kwargs...)
printpkgstyle(stdout, cmd, text...; kwargs...)
end

# Give a short path string representation
pathrepr(path::String, base::String=pwd()) = pathrepr(nothing, path, base)

function pathrepr(ctx::Union{Nothing, Context}, path::String, base::String=pwd())
if ctx isa Context
project_path = abspath(dirname(ctx.env.project_file))
path = joinpath(project_path, path)
if startswith(path, project_path)
# Path in project
if startswith(base, project_path)
# We are in project
path = relpath(path, base)
else
path = relpath(path, project_path)
end
end
project_path = dirname(ctx.env.project_file)
path = joinpath(project_path, path)
if startswith(path, project_path) && startswith(base, project_path)
# We are in project and path is in project
path = relpath(path, base)
end
if !Sys.iswindows() && isabspath(path)
home = joinpath(homedir(), "")
Expand Down

0 comments on commit dd96c7d

Please sign in to comment.