Skip to content

Commit d0ca92a

Browse files
author
José Valim
committed
Fix a bug where mix deps.get was not retrieving nested dependencies
1 parent ca25049 commit d0ca92a

File tree

6 files changed

+137
-57
lines changed

6 files changed

+137
-57
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* enhancements
44

55
* bug fix
6+
* [Mix] Fix a bug where `mix deps.get` was not retrieving nested dependencies
67

78
* deprecations
89

lib/mix/lib/mix/deps/retriever.ex

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,15 @@ defmodule Mix.Deps.Retriever do
2727
Enum.map_reduce children, rest, fn (dep, rest) ->
2828
{ dep, rest } = callback.(dep, rest)
2929

30-
if Mix.Deps.available?(dep) and Mix.Deps.mix?(dep) do
31-
{ dep, rest } = Mix.Deps.in_dependency dep, post_config, fn _ ->
30+
if Mix.Deps.available?(dep) and mixfile?(dep) do
31+
{ dep, rest } = Mix.Deps.in_dependency dep, post_config, fn project ->
3232
{ deps, rest } = all(rest, callback)
33-
{ dep.deps(deps), rest }
33+
34+
# We need to call with_mix_project once again
35+
# here in case the dependency was not available
36+
# the first time and the callback hook just
37+
# happened to fetch it.
38+
{ with_mix_project(dep, project).deps(deps), rest }
3439
end
3540
end
3641

@@ -50,18 +55,13 @@ defmodule Mix.Deps.Retriever do
5055
Enum.map deps, fn dep ->
5156
dep = with_scm_and_status(dep, scms)
5257

53-
# Set properties if dependency is a mix project
5458
if Mix.Deps.available?(dep) and mixfile?(dep) do
55-
dep = Mix.Deps.in_dependency dep, fn project ->
56-
if match?({ :noappfile, _ }, dep.status) and Mix.Project.umbrella? do
57-
dep = dep.update_opts(Keyword.put(&1, :app, false))
58-
.status({ :ok, nil })
59-
end
60-
dep.project(project)
59+
Mix.Deps.in_dependency dep, fn project ->
60+
with_mix_project(dep, project)
6161
end
62+
else
63+
dep
6264
end
63-
64-
dep
6565
end
6666
end
6767

@@ -74,6 +74,16 @@ defmodule Mix.Deps.Retriever do
7474

7575
## Helpers
7676

77+
defp with_mix_project(Mix.Dep[project: nil] = dep, project) do
78+
if match?({ :noappfile, _ }, dep.status) and Mix.Project.umbrella? do
79+
dep = dep.update_opts(Keyword.put(&1, :app, false))
80+
.status({ :ok, nil })
81+
end
82+
dep.project(project)
83+
end
84+
85+
defp with_mix_project(dep, _project), do: dep
86+
7787
defp with_scm_and_status({ app, opts }, scms) when is_atom(app) and is_list(opts) do
7888
with_scm_and_status({ app, nil, opts }, scms)
7989
end

lib/mix/test/fixtures/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
git_repo
1+
git_repo
2+
deps_on_git_repo

lib/mix/test/mix/tasks/deps.git_test.exs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@ Code.require_file "../../test_helper.exs", __DIR__
33
defmodule Mix.Tasks.DepsGitTest do
44
use MixTest.Case
55

6+
defmodule DepsOnGitApp do
7+
def project do
8+
[ app: :deps_on_git_app,
9+
version: "0.1.0",
10+
deps: [
11+
{ :deps_on_git_repo, "0.1.0", git: MixTest.Case.fixture_path("deps_on_git_repo") }
12+
] ]
13+
end
14+
end
15+
616
defmodule GitApp do
717
def project do
818
[ app: :git_app,
@@ -64,6 +74,29 @@ defmodule Mix.Tasks.DepsGitTest do
6474
Mix.Project.pop
6575
end
6676

77+
test "gets many levels deep dependencies" do
78+
Mix.Project.push DepsOnGitApp
79+
80+
in_fixture "no_mixfile", fn ->
81+
Mix.Tasks.Deps.Get.run []
82+
83+
message = "* Getting git_repo [git: #{inspect fixture_path("git_repo")}]"
84+
assert_received { :mix_shell, :info, [^message] }
85+
assert_received { :mix_shell, :info, ["* Compiling git_repo"] }
86+
87+
88+
message = "* Getting deps_on_git_repo [git: #{inspect fixture_path("deps_on_git_repo")}]"
89+
assert_received { :mix_shell, :info, [^message] }
90+
assert_received { :mix_shell, :info, ["* Compiling deps_on_git_repo"] }
91+
92+
assert File.exists?("deps/deps_on_git_repo/mix.exs")
93+
assert File.exists?("deps/git_repo/mix.exs")
94+
end
95+
after
96+
purge [GitRepo, GitRepo.Mix, DepsOnGitRepo.Mix]
97+
Mix.Project.pop
98+
end
99+
67100
test "does not check if repo information changes" do
68101
Mix.Project.push GitApp
69102

lib/mix/test/mix/tasks/run_test.exs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ defmodule Mix.Tasks.RunTest do
1616
test "run command with dependencies" do
1717
Mix.Project.push GetApp
1818

19-
in_fixture "only_mixfile", fn ->
19+
in_fixture "no_mixfile", fn ->
2020
Mix.Tasks.Deps.Get.run []
2121
Mix.Tasks.Run.run ["Mix.shell.info", "GitRepo.hello"]
2222
assert_received { :mix_shell, :info, ["World"] }
2323
end
2424
after
25-
purge [GitRepo, GitRepo.Mix]
25+
purge [GitRepo, GitRepo.Mix, A, B, C]
2626
Mix.Project.pop
2727
end
2828

@@ -37,6 +37,6 @@ defmodule Mix.Tasks.RunTest do
3737
assert_received { :mix_shell, :info, ["World"] }
3838
end
3939
after
40-
purge [GitRepo, A, B, C]
40+
purge [GitRepo, GitRepo.Mix, A, B, C]
4141
end
4242
end

lib/mix/test/test_helper.exs

Lines changed: 76 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,47 +4,6 @@ Mix.shell(Mix.Shell.Process)
44
ExUnit.start []
55
System.put_env("EXUNIT_CONFIG", "none")
66

7-
target = Path.expand("../fixtures/git_repo", __FILE__)
8-
9-
unless File.dir?(target) do
10-
File.mkdir_p!(Path.join(target, "lib"))
11-
12-
File.write!(Path.join(target, "mix.exs"), """)
13-
defmodule GitRepo.Mix do
14-
use Mix.Project
15-
16-
def project do
17-
[app: :git_repo, version: "0.1.0"]
18-
end
19-
end
20-
"""
21-
22-
File.cd! target, fn ->
23-
System.cmd("git init")
24-
System.cmd("git config user.email \"[email protected]\"")
25-
System.cmd("git config user.name \"Mix Repo\"")
26-
System.cmd("git add .")
27-
System.cmd("git commit -m \"ok\"")
28-
end
29-
30-
File.write!(Path.join(target, "lib/git_repo.ex"), """)
31-
defmodule GitRepo do
32-
def hello do
33-
"World"
34-
end
35-
end
36-
"""
37-
38-
File.cd! target, fn ->
39-
System.cmd("git add .")
40-
System.cmd("git commit -m \"lib\"")
41-
end
42-
end
43-
44-
Enum.each [:invalidapp, :invalidvsn, :noappfile, :ok], fn(dep) ->
45-
File.mkdir_p! Path.expand("../fixtures/deps_status/deps/#{dep}/.git", __FILE__)
46-
end
47-
487
defmodule MixTest.Case do
498
use ExUnit.CaseTemplate
509

@@ -130,6 +89,8 @@ defmodule MixTest.Case do
13089
end
13190
end
13291

92+
## Some tasks fixtures
93+
13394
defmodule Mix.Tasks.Hello do
13495
use Mix.Task
13596
@shortdoc "This is short documentation, see"
@@ -145,3 +106,77 @@ end
145106

146107
defmodule Mix.Tasks.Invalid do
147108
end
109+
110+
## Generate git repo fixtures
111+
112+
# Git repo
113+
target = Path.expand("../fixtures/git_repo", __FILE__)
114+
115+
unless File.dir?(target) do
116+
File.mkdir_p!(Path.join(target, "lib"))
117+
118+
File.write!(Path.join(target, "mix.exs"), """)
119+
## Auto-generated fixture
120+
defmodule GitRepo.Mix do
121+
use Mix.Project
122+
123+
def project do
124+
[app: :git_repo, version: "0.1.0"]
125+
end
126+
end
127+
"""
128+
129+
File.cd! target, fn ->
130+
System.cmd("git init")
131+
System.cmd("git config user.email \"[email protected]\"")
132+
System.cmd("git config user.name \"Mix Repo\"")
133+
System.cmd("git add .")
134+
System.cmd("git commit -m \"ok\"")
135+
end
136+
137+
File.write!(Path.join(target, "lib/git_repo.ex"), """)
138+
## Auto-generated fixture
139+
defmodule GitRepo do
140+
def hello do
141+
"World"
142+
end
143+
end
144+
"""
145+
146+
File.cd! target, fn ->
147+
System.cmd("git add .")
148+
System.cmd("git commit -m \"lib\"")
149+
end
150+
end
151+
152+
# Deps on git repo
153+
target = Path.expand("../fixtures/deps_on_git_repo", __FILE__)
154+
155+
unless File.dir?(target) do
156+
File.mkdir_p!(Path.join(target, "lib"))
157+
158+
File.write!(Path.join(target, "mix.exs"), """)
159+
## Auto-generated fixture
160+
defmodule DepsOnGitRepo.Mix do
161+
use Mix.Project
162+
163+
def project do
164+
[ app: :deps_on_git_repo,
165+
version: "0.2.0",
166+
deps: [{ :git_repo, git: MixTest.Case.fixture_path("git_repo") }] ]
167+
end
168+
end
169+
"""
170+
171+
File.cd! target, fn ->
172+
System.cmd("git init")
173+
System.cmd("git config user.email \"[email protected]\"")
174+
System.cmd("git config user.name \"Mix Repo\"")
175+
System.cmd("git add .")
176+
System.cmd("git commit -m \"ok\"")
177+
end
178+
end
179+
180+
Enum.each [:invalidapp, :invalidvsn, :noappfile, :ok], fn(dep) ->
181+
File.mkdir_p! Path.expand("../fixtures/deps_status/deps/#{dep}/.git", __FILE__)
182+
end

0 commit comments

Comments
 (0)