Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions lib/mix/tasks/hex.outdated.ex
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ defmodule Mix.Tasks.Hex.Outdated do
at the project's current set of dependency requirements and what version
they are locked to. When `mix deps.update` is called multiple packages may
be updated that in turn update their own dependencies, which may cause the
package you want to update to not be able to update.
package you want to update to not be able to update. If you want to force
a dependency to be updated to a given version, you can directly update it
in your `mix.exs`.

> In a project, this task must be invoked before any other tasks
> that may load or start your application. Otherwise, you must
Expand Down Expand Up @@ -196,7 +198,8 @@ defmodule Mix.Tasks.Hex.Outdated do

base_message = "Run `mix hex.outdated APP` to see requirements for a specific dependency."
diff_message = maybe_diff_message(diff_links)
Hex.Shell.info(["\n", base_message, diff_message])
diff_command_message = maybe_diff_command_message(diff_links)
Hex.Shell.info(["\n", base_message, diff_message, diff_command_message])

outdated = outdated(versions)
any_updatable? = any_possible_to_update?(outdated)
Expand Down Expand Up @@ -328,6 +331,12 @@ defmodule Mix.Tasks.Hex.Outdated do
diff_link(diff_links)
end

defp maybe_diff_command_message([]), do: ""

defp maybe_diff_command_message(_diff_links) do
"\n\nTo view the diff of a specific update, run `mix hex.package diff APP FROM..TO`."
end

defp diff_link(diff_links) do
long_url = "https://diff.hex.pm/diffs?" <> Enum.join(diff_links, "&")

Expand Down
20 changes: 20 additions & 0 deletions test/mix/tasks/hex.outdated_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,26 @@ defmodule Mix.Tasks.Hex.OutdatedTest do
end)
end

test "outdated shows a generic diff command hint when updates are available" do
Mix.Project.push(OutdatedDeps.MixProject)

in_tmp(fn ->
set_home_tmp()
Mix.Dep.Lock.write(%{bar: {:hex, :bar, "0.1.0"}, foo: {:hex, :foo, "0.1.0"}})

Mix.Task.run("deps.get")
flush()

assert catch_throw(Mix.Task.run("hex.outdated", ["--all"])) == {:exit_code, 1}

lines = flush()
output = Enum.map_join(lines, "\n", fn {_, _, [line]} -> line end)

assert output =~
"To view the diff of a specific update, run `mix hex.package diff APP FROM..TO`."
end)
end

defp extract_statuses(lines) do
Enum.flat_map(lines, fn {_, _, [line]} ->
~r/Up-to-date|Update not possible|Update possible/
Expand Down
Loading