File tree Expand file tree Collapse file tree 2 files changed +26
-16
lines changed Expand file tree Collapse file tree 2 files changed +26
-16
lines changed Original file line number Diff line number Diff line change @@ -44,11 +44,11 @@ defmodule Mix.Project do
44
44
# Push a project onto the project stack.
45
45
# Only the top of the stack can be accessed.
46
46
@ doc false
47
- def push ( atom , file \\ nil ) when is_atom ( atom ) do
47
+ def push ( atom , file \\ nil , app \\ nil ) when is_atom ( atom ) do
48
48
file = file ||
49
49
( atom && List . to_string ( atom . __info__ ( :compile ) [ :source ] ) )
50
50
51
- config = default_config
51
+ config = ( [ app: app ] ++ default_config )
52
52
|> Keyword . merge ( get_project_config ( atom ) )
53
53
|> Keyword . drop ( @ private_config )
54
54
@@ -335,23 +335,24 @@ defmodule Mix.Project do
335
335
336
336
if cached = Mix.ProjectStack . read_cache ( app ) do
337
337
{ project , file } = cached
338
- push ( project , file )
338
+ push ( project , file , app )
339
339
project
340
340
else
341
341
file = Path . expand ( "mix.exs" )
342
- old_proj = get
343
-
344
- _ = if File . regular? ( file ) do
345
- Code . load_file ( file )
346
- end
347
-
348
- new_proj = get
349
-
350
- if old_proj == new_proj do
351
- file = "nofile"
352
- new_proj = nil
353
- push new_proj , file
354
- end
342
+ old_proj = get ( )
343
+
344
+ new_proj =
345
+ if File . regular? ( file ) do
346
+ _ = Code . load_file ( file )
347
+ case get ( ) do
348
+ ^ old_proj -> Mix . raise "Could not find a Mix project at #{ file } "
349
+ new_proj -> new_proj
350
+ end
351
+ else
352
+ file = "nofile"
353
+ push ( nil , file , app )
354
+ nil
355
+ end
355
356
356
357
Mix.ProjectStack . write_cache ( app , { new_proj , file } )
357
358
new_proj
Original file line number Diff line number Diff line change @@ -79,6 +79,15 @@ defmodule Mix.ProjectTest do
79
79
end
80
80
end
81
81
82
+ test "in_project pushes given configuration" do
83
+ in_fixture "no_mixfile" , fn ->
84
+ Mix.Project . in_project :foo , "." , [ hello: :world ] , fn _ ->
85
+ assert Mix.Project . config [ :app ] == :foo
86
+ assert Mix.Project . config [ :hello ] == :world
87
+ end
88
+ end
89
+ end
90
+
82
91
test "config_files" do
83
92
Mix.Project . push ( SampleProject )
84
93
You can’t perform that action at this time.
0 commit comments