Skip to content

Commit 0c80905

Browse files
committed
Preserve correct order when deps are overriding
1 parent 7aeb1b6 commit 0c80905

File tree

2 files changed

+40
-12
lines changed

2 files changed

+40
-12
lines changed

lib/mix/lib/mix/deps/converger.ex

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ defmodule Mix.Deps.Converger do
8383

8484
# Look for an overriding dep in the upper breadths, if
8585
# found return a new acc without the overriden dep and
86-
# with the proper status set on the overrider
86+
# with the proper status set on the overrider. The
87+
# overrider is moved to the front of the accumulator to
88+
# preserve the position of the removed dep.
8789
defp overriden_deps(acc, upper_breadths, dep) do
8890
overriden = Enum.any?(upper_breadths, fn(other) ->
8991
other.app == dep.app
@@ -92,18 +94,21 @@ defmodule Mix.Deps.Converger do
9294
if overriden do
9395
Mix.Dep[app: app] = dep
9496

95-
Enum.map(acc, fn other ->
96-
Mix.Dep[app: other_app, opts: other_opts] = other
97+
{ overrider, acc } =
98+
Enum.reduce(acc, { nil , [] }, fn other, { overrider, acc } ->
99+
Mix.Dep[app: other_app, opts: other_opts] = other
97100

98-
cond do
99-
app == other_app && (other_opts[:override] || converge?(dep, other)) ->
100-
other
101-
app == other_app ->
102-
other.status({ :overriden, dep })
103-
true ->
104-
other
105-
end
106-
end)
101+
cond do
102+
app == other_app && (other_opts[:override] || converge?(dep, other)) ->
103+
{ other, acc }
104+
app == other_app ->
105+
{ other.status({ :overriden, dep }), acc }
106+
true ->
107+
{ overrider, [other|acc] }
108+
end
109+
end)
110+
111+
[ overrider | Enum.reverse(acc) ]
107112
end
108113
end
109114

lib/mix/test/mix/deps_test.exs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,27 @@ defmodule Mix.DepsTest do
4848
after
4949
Mix.Project.pop
5050
end
51+
52+
defmodule ConvergedDepsApp do
53+
def project do
54+
[
55+
app: :raw_sample,
56+
version: "0.1.0",
57+
deps: [
58+
{ :deps_repo, "0.1.0", path: "custom/deps_repo" },
59+
{ :git_repo, "0.1.0", git: MixTest.Case.fixture_path("git_repo") }
60+
]
61+
]
62+
end
63+
end
64+
65+
test "correctly order overriden deps" do
66+
Mix.Project.push ConvergedDepsApp
67+
68+
in_fixture "deps_status", fn ->
69+
assert [:git_repo, :deps_repo] == Enum.map(Mix.Deps.all, &(&1.app))
70+
end
71+
after
72+
Mix.Project.pop
73+
end
5174
end

0 commit comments

Comments
 (0)