Skip to content

Commit 8bb9ef5

Browse files
authored
Show mix hex.package diff commands in hex.outdated output (#1137)
1 parent 022578d commit 8bb9ef5

2 files changed

Lines changed: 31 additions & 2 deletions

File tree

lib/mix/tasks/hex.outdated.ex

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ defmodule Mix.Tasks.Hex.Outdated do
3333
at the project's current set of dependency requirements and what version
3434
they are locked to. When `mix deps.update` is called multiple packages may
3535
be updated that in turn update their own dependencies, which may cause the
36-
package you want to update to not be able to update.
36+
package you want to update to not be able to update. If you want to force
37+
a dependency to be updated to a given version, you can directly update it
38+
in your `mix.exs`.
3739
3840
> In a project, this task must be invoked before any other tasks
3941
> that may load or start your application. Otherwise, you must
@@ -196,7 +198,8 @@ defmodule Mix.Tasks.Hex.Outdated do
196198

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

201204
outdated = outdated(versions)
202205
any_updatable? = any_possible_to_update?(outdated)
@@ -328,6 +331,12 @@ defmodule Mix.Tasks.Hex.Outdated do
328331
diff_link(diff_links)
329332
end
330333

334+
defp maybe_diff_command_message([]), do: ""
335+
336+
defp maybe_diff_command_message(_diff_links) do
337+
"\n\nTo view the diff of a specific update, run `mix hex.package diff APP FROM..TO`."
338+
end
339+
331340
defp diff_link(diff_links) do
332341
long_url = "https://diff.hex.pm/diffs?" <> Enum.join(diff_links, "&")
333342

test/mix/tasks/hex.outdated_test.exs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,26 @@ defmodule Mix.Tasks.Hex.OutdatedTest do
668668
end)
669669
end
670670

671+
test "outdated shows a generic diff command hint when updates are available" do
672+
Mix.Project.push(OutdatedDeps.MixProject)
673+
674+
in_tmp(fn ->
675+
set_home_tmp()
676+
Mix.Dep.Lock.write(%{bar: {:hex, :bar, "0.1.0"}, foo: {:hex, :foo, "0.1.0"}})
677+
678+
Mix.Task.run("deps.get")
679+
flush()
680+
681+
assert catch_throw(Mix.Task.run("hex.outdated", ["--all"])) == {:exit_code, 1}
682+
683+
lines = flush()
684+
output = Enum.map_join(lines, "\n", fn {_, _, [line]} -> line end)
685+
686+
assert output =~
687+
"To view the diff of a specific update, run `mix hex.package diff APP FROM..TO`."
688+
end)
689+
end
690+
671691
defp extract_statuses(lines) do
672692
Enum.flat_map(lines, fn {_, _, [line]} ->
673693
~r/Up-to-date|Update not possible|Update possible/

0 commit comments

Comments
 (0)