Skip to content

Commit ca6b8d3

Browse files
author
José Valim
committed
No longer clean or unlock deps unless --all is given
1 parent 178b937 commit ca6b8d3

File tree

7 files changed

+43
-27
lines changed

7 files changed

+43
-27
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
* [Kernel] Fix a bug where warnings were not being generated when imported macros conflicted with local functions or macros
2828
* [Kernel] Document that `on_definition` can only be a function as it is evaluated inside the function context
2929
* [Kernel] Ensure `%w` sigils with no interpolation are fully expanded at compile time
30-
* [Mix] `mix deps.update` no longer updates all dependencies unless `--all` is given
30+
* [Mix] `mix deps.update`, `mix deps.clean` and `mix deps.unlock` no longer change all dependencies unless `--all` is given
3131
* [Mix] Always run ` mix loadpaths` on `mix app.start`, even if `--no-compile` is given
3232
* [OptionParser] Do not add boolean flags to the end result if they were not given
3333
* [OptionParser] Do not parse non-boolean flags as booleans when true or false are given

lib/mix/lib/mix/tasks/deps.clean.ex

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,31 @@
11
defmodule Mix.Tasks.Deps.Clean do
22
use Mix.Task
33

4-
@shortdoc "Remove dependencies' files"
4+
@shortdoc "Remove the given dependencies' files"
55
@recursive :both
66

77
@moduledoc """
8-
Clean dependencies.
8+
Remove the given dependencies' files.
99
10-
By default, cleans all dependencies. A list of dependencies can
11-
be given to clean specific ones. Clean does not unlock
12-
the repositories, unless `--unlock` is given.
10+
Since this is a destructive action, cleaning of all dependencies
11+
can only happen by passing the `--all` command line option.
12+
13+
Clean does not unlock the repositories, unless `--unlock` is given.
1314
"""
1415

1516
import Mix.Deps, only: [all: 0, by_name: 1, format_dep: 1]
1617

1718
def run(args) do
18-
case OptionParser.parse(args, switches: [unlock: :boolean]) do
19-
{ opts, [] } -> do_clean all, opts
20-
{ opts, args } -> do_clean by_name(args), opts
19+
{ opts, args } = OptionParser.parse(args, switches: [unlock: :boolean, all: :boolean])
20+
21+
cond do
22+
opts[:all] ->
23+
do_clean all, opts
24+
args != [] ->
25+
do_clean by_name(args), opts
26+
true ->
27+
raise Mix.Error, message: "mix deps.clean expects dependencies as arguments or " <>
28+
"the --all option to clean all dependencies"
2129
end
2230
end
2331

lib/mix/lib/mix/tasks/deps.unlock.ex

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,29 @@ defmodule Mix.Tasks.Deps.Unlock do
55
@recursive :both
66

77
@moduledoc """
8-
Unlock the given dependencies. If no dependencies
9-
are given, unlock all.
10-
"""
8+
Unlock the given dependencies.
119
12-
def run([]) do
13-
Mix.Deps.Lock.write([])
14-
end
10+
Since this is a destructive action, unlocking of all dependencies
11+
can only happen by passing the `--all` command line option.
12+
"""
1513

1614
def run(args) do
17-
lock =
18-
Enum.reduce args, Mix.Deps.Lock.read, fn(arg, lock) ->
19-
if is_binary(arg), do: arg = binary_to_atom(arg)
20-
Keyword.delete(lock, arg)
21-
end
15+
{ opts, args } = OptionParser.parse(args, switches: [unlock: :boolean, all: :boolean])
16+
17+
cond do
18+
opts[:all] ->
19+
Mix.Deps.Lock.write([])
20+
args != [] ->
21+
lock =
22+
Enum.reduce args, Mix.Deps.Lock.read, fn(arg, lock) ->
23+
if is_binary(arg), do: arg = binary_to_atom(arg)
24+
Keyword.delete(lock, arg)
25+
end
2226

23-
Mix.Deps.Lock.write(lock)
27+
Mix.Deps.Lock.write(lock)
28+
true ->
29+
raise Mix.Error, message: "mix deps.unlock expects dependencies as arguments or " <>
30+
"the --all option to unlock all dependencies"
31+
end
2432
end
2533
end

lib/mix/lib/mix/tasks/deps.update.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ defmodule Mix.Tasks.Deps.Update do
77
@moduledoc """
88
Update the given dependencies.
99
10-
Since this is a "dangerous" operation, update of all dependencies
10+
Since this is a destructive action, update of all dependencies
1111
can only happen by passing the `--all` command line option.
1212
1313
All dependencies are automatically recompiled after update.

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ defmodule Mix.Tasks.DepsGitTest do
6464
assert_received { :mix_shell, :info, ["* Compiling git_repo"] }
6565
assert_received { :mix_shell, :info, ["Compiled lib/git_repo.ex"] }
6666

67-
Mix.Tasks.Deps.Clean.run []
67+
Mix.Tasks.Deps.Clean.run ["--all"]
6868
message = "* Cleaning git_repo (0.1.0) [git: #{inspect fixture_path("git_repo")}]"
6969
assert_received { :mix_shell, :info, [^message] }
7070
refute File.exists?("deps/git_repo/ebin/Elixir.Git.Repo.beam")
@@ -224,11 +224,11 @@ defmodule Mix.Tasks.DepsGitTest do
224224
assert File.exists?("deps/git_repo/lib/git_repo.ex")
225225
assert File.read!("mix.lock") =~ last
226226

227-
Mix.Tasks.Deps.Clean.run []
227+
Mix.Tasks.Deps.Clean.run ["--all"]
228228
refute File.exists?("deps/git_repo/ebin/Elixir.Git.Repo.beam")
229229
assert File.read!("mix.lock") =~ last
230230

231-
Mix.Tasks.Deps.Clean.run ["--unlock"]
231+
Mix.Tasks.Deps.Clean.run ["--unlock", "--all"]
232232
refute File.read!("mix.lock") =~ last
233233
end
234234
after

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ defmodule Mix.Tasks.DepsPathTest do
2525
assert_received { :mix_shell, :info, ["Generated raw_repo.app"] }
2626
assert File.exists?("custom/raw_repo/ebin/Elixir.RawRepo.beam")
2727

28-
Mix.Tasks.Deps.Clean.run []
28+
Mix.Tasks.Deps.Clean.run ["--all"]
2929
assert_received { :mix_shell, :info, ["* Cleaning raw_repo (0.1.0) [path: \"custom/raw_repo\"]"] }
3030
assert_received { :mix_shell, :info, [" custom/raw_repo is a path dependency, it was not cleaned"] }
3131
end

lib/mix/test/mix/tasks/deps_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ defmodule Mix.Tasks.DepsTest do
140140
in_fixture "no_mixfile", fn ->
141141
Mix.Deps.Lock.write [git_repo: "abcdef"]
142142
assert Mix.Deps.Lock.read == [git_repo: "abcdef"]
143-
Mix.Tasks.Deps.Unlock.run []
143+
Mix.Tasks.Deps.Unlock.run ["--all"]
144144
assert Mix.Deps.Lock.read == []
145145
end
146146
end

0 commit comments

Comments
 (0)