diff --git a/lib/mix/tasks/hex.outdated.ex b/lib/mix/tasks/hex.outdated.ex index c2b9a966..a8d34ac1 100644 --- a/lib/mix/tasks/hex.outdated.ex +++ b/lib/mix/tasks/hex.outdated.ex @@ -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 @@ -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) @@ -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, "&") diff --git a/test/mix/tasks/hex.outdated_test.exs b/test/mix/tasks/hex.outdated_test.exs index c98eff79..e31ad577 100644 --- a/test/mix/tasks/hex.outdated_test.exs +++ b/test/mix/tasks/hex.outdated_test.exs @@ -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/