Skip to content

Commit

Permalink
Fix crash when printing resolver output for old lock files
Browse files Browse the repository at this point in the history
  • Loading branch information
ericmj committed Apr 18, 2018
1 parent 10112c1 commit e85bdb1
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 9 deletions.
16 changes: 8 additions & 8 deletions lib/hex/remote_converger.ex
Original file line number Diff line number Diff line change
Expand Up @@ -245,25 +245,25 @@ defmodule Hex.RemoteConverger do
end

defp group_dependency_changes(resolved, previously_locked_versions) do
state = %{new: [], eq: [], gt: [], lt: []}

resolved
|> Enum.sort()
|> Enum.reduce(%{new: [], eq: [], gt: [], lt: []}, fn {name, {repo, version}}, acc ->
|> Enum.reduce(state, fn {name, {repo, version}}, acc ->
previous_version =
previously_locked_versions
|> Map.get(String.to_atom(name))
|> Map.get(name)
|> version_string_or_nil()

change = categorize_dependency_change(previous_version, version)
Map.put(acc, change, acc[change] ++ [{name, repo, previous_version, version}])
end)
end

defp dep_info_from_lock({name, {_src, _app, version, _checksum, _build, _children, repo}}),
do: {name, {repo, version}}

defp dep_info_from_lock({name, {repo, _app, version, _checksum}}), do: {name, {repo, version}}

defp dep_info_from_lock({name, {repo, _app, version}}), do: {name, {repo, version}}
defp dep_info_from_lock({_app, info}) do
%{name: name, repo: repo, version: version} = Hex.Utils.lock(info)
{name, {repo, version}}
end

defp version_string_or_nil(nil), do: nil
defp version_string_or_nil({_repo, version_string}), do: version_string
Expand Down
42 changes: 41 additions & 1 deletion test/hex/mix_task_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ defmodule Hex.MixTaskTest do
])
end

test "deps.update locked dependency" do
test "deps.update locked dependency with minimal lock file" do
Mix.Project.push(EctoDep)

in_tmp(fn ->
Expand All @@ -338,6 +338,46 @@ defmodule Hex.MixTaskTest do
])
end

test "deps.update locked dependency with old lockfile" do
Mix.Project.push(EctoDep)

in_tmp(fn ->
Hex.State.put(:home, System.cwd!())

File.write!("mix.lock", ~s(%{"ecto": {:hex, :ecto, "0.2.0", "CHECKSUM", [:mix]}}))
Mix.Task.run("deps.update", ["ecto"])

assert_received {:mix_shell, :info, [" ecto 0.2.0 => 0.2.1"]}
end)
after
purge([
Ecto.NoConflict.MixProject,
Postgrex.NoConflict.MixProject,
Ex_doc.NoConflict.MixProject,
Sample.Fixture.MixProject
])
end

test "deps.update locked dependency with new lockfile" do
Mix.Project.push(EctoDep)

in_tmp(fn ->
Hex.State.put(:home, System.cwd!())

File.write!("mix.lock", ~s(%{"ecto": {:hex, :ecto, "0.2.0", "CHECKSUM", [:mix], [], "hexpm"}}))
Mix.Task.run("deps.update", ["ecto"])

assert_received {:mix_shell, :info, [" ecto 0.2.0 => 0.2.1"]}
end)
after
purge([
Ecto.NoConflict.MixProject,
Postgrex.NoConflict.MixProject,
Ex_doc.NoConflict.MixProject,
Sample.Fixture.MixProject
])
end

test "deps.get with override" do
Mix.Project.push(Override)

Expand Down

0 comments on commit e85bdb1

Please sign in to comment.