Skip to content

Commit c2c1ebd

Browse files
author
José Valim
committed
Check for the hex version on CLI start
1 parent 6f50980 commit c2c1ebd

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

lib/mix/lib/mix/cli.ex

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,32 @@ defmodule Mix.CLI do
2626
run_task(task, args)
2727
end
2828

29+
@hex_requirement ">= 0.1.0-dev"
30+
2931
defp load_remote do
30-
try do
31-
Code.ensure_loaded?(Hex) and Hex.start
32-
catch
33-
kind, reason ->
34-
stacktrace = System.stacktrace
35-
Mix.shell.error "Could not start Hex. Try fetching a new version with " <>
36-
"`mix local.hex` or uninstalling it with `mix local.uninstall hex`"
37-
:erlang.raise(kind, reason, stacktrace)
32+
if Code.ensure_loaded?(Hex) do
33+
unless Version.match?(Hex.version, @hex_requirement) do
34+
update_hex()
35+
end
36+
37+
try do
38+
Hex.start
39+
catch
40+
kind, reason ->
41+
stacktrace = System.stacktrace
42+
Mix.shell.error "Could not start Hex. Try fetching a new version with " <>
43+
"`mix local.hex` or uninstalling it with `mix local.uninstall hex`"
44+
:erlang.raise(kind, reason, stacktrace)
45+
end
46+
end
47+
end
48+
49+
defp update_hex do
50+
Mix.shell.info "Mix requires hex #{@hex_requirement} but you have #{Hex.version}"
51+
52+
if Mix.shell.yes?("Shall I abort the current command and update hex?") do
53+
Mix.Tasks.Local.Hex.run ["--force"]
54+
exit(0)
3855
end
3956
end
4057

lib/mix/lib/mix/dep/converger.ex

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,6 @@ defmodule Mix.Dep.Converger do
6363
# Run remote converger if one is available and rerun mix's
6464
# converger with the new information
6565
if converger do
66-
Code.ensure_loaded?(converger)
67-
68-
unless function_exported?(converger, :deps, 2) do
69-
raise Mix.Error, message: "Update Hex to the latest version"
70-
end
71-
7266
# If there is a lock, it means we are doing a get/update
7367
# and we need to hit the remote converger which do external
7468
# requests and what not. In case of deps.check, deps and so

0 commit comments

Comments
 (0)