Skip to content

Commit

Permalink
improve develop err message (#421)
Browse files Browse the repository at this point in the history
* improve develop err message

* small changes
  • Loading branch information
innerlee authored and KristofferC committed Jul 3, 2018
1 parent 4272648 commit 165b9ec
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
10 changes: 10 additions & 0 deletions stdlib/Pkg/src/API.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ add_or_develop(pkgs::Vector{PackageSpec}; kwargs...) = add_or_develop(Cont

function add_or_develop(ctx::Context, pkgs::Vector{PackageSpec}; mode::Symbol, kwargs...)
Context!(ctx; kwargs...)

# if julia is passed as a package the solver gets tricked;
# this catches the error early on
any(pkg->(pkg.name == "julia"), pkgs) &&
cmderror("Trying to $mode julia as a package")

ctx.preview && preview_info()
if mode == :develop
new_git = handle_repos_develop!(ctx, pkgs)
Expand All @@ -36,6 +42,10 @@ function add_or_develop(ctx::Context, pkgs::Vector{PackageSpec}; mode::Symbol, k
registry_resolve!(ctx.env, pkgs)
stdlib_resolve!(ctx, pkgs)
ensure_resolved(ctx.env, pkgs, registry=true)

any(pkg -> Types.collides_with_project(ctx.env, pkg), pkgs) &&
cmderror("Cannot $mode package with the same name or uuid as the project")

Operations.add_or_develop(ctx, pkgs; new_git=new_git)
ctx.preview && preview_info()
return
Expand Down
6 changes: 0 additions & 6 deletions stdlib/Pkg/src/Operations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1043,12 +1043,6 @@ function rm(ctx::Context, pkgs::Vector{PackageSpec})
end

function add_or_develop(ctx::Context, pkgs::Vector{PackageSpec}; new_git = UUID[])
# if julia is passed as a package the solver gets tricked;
# this catches the error early on
any(pkg->(pkg.uuid == uuid_julia), pkgs) &&
cmderror("Trying to add julia as a package")
any(pkg -> Types.collides_with_project(ctx.env, pkg), pkgs) &&
cmderror("Cannot add package with the same name or uuid as the project")
# copy added name/UUIDs into project
for pkg in pkgs
ctx.env.project["deps"][pkg.name] = string(pkg.uuid)
Expand Down
7 changes: 4 additions & 3 deletions stdlib/Pkg/src/REPLMode.jl
Original file line number Diff line number Diff line change
Expand Up @@ -562,9 +562,10 @@ end

function do_add_or_develop!(ctx::Context, tokens::Vector{Token}, cmd::CommandKind)
@assert cmd in (CMD_ADD, CMD_DEVELOP)
mode = cmd == CMD_ADD ? :add : :develop
# tokens: package names and/or uuids, optionally followed by version specs
isempty(tokens) &&
cmderror("`add` – list packages to add")
cmderror("`$mode` – list packages to $mode")
pkgs = PackageSpec[]
prev_token_was_package = false
while !isempty(tokens)
Expand All @@ -589,11 +590,11 @@ function do_add_or_develop!(ctx::Context, tokens::Vector{Token}, cmd::CommandKin
pkgs[end].repo.rev = token.rev
end
elseif token isa Option
cmderror("`add` doesn't take options: $token")
cmderror("`$mode` doesn't take options: $token")
end
prev_token_was_package = parsed_package
end
return API.add_or_develop(ctx, pkgs, mode=(cmd == CMD_ADD ? :add : :develop))
return API.add_or_develop(ctx, pkgs, mode=mode)
end

function do_up!(ctx::Context, tokens::Vector{Token})
Expand Down

0 comments on commit 165b9ec

Please sign in to comment.