Skip to content

Commit aba387c

Browse files
author
José Valim
committed
Ensure git scm does not take lock into account when comparing deps, closes #1992
1 parent 36d8e1c commit aba387c

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

lib/mix/lib/mix/scm/git.ex

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ defmodule Mix.SCM.Git do
6060
end
6161

6262
def equal?(opts1, opts2) do
63-
get_lock(opts1, false) == get_lock(opts2, false)
63+
opts1[:git] == opts2[:git] &&
64+
get_lock_opts(opts1) == get_lock_opts(opts2)
6465
end
6566

6667
def checkout(opts) do
@@ -108,17 +109,12 @@ defmodule Mix.SCM.Git do
108109
run_cmd_or_raise "git submodule update --init --recursive"
109110
end
110111

111-
get_lock(opts, true)
112+
get_lock(opts)
112113
end
113114

114-
defp get_lock(opts, fresh) do
115-
lock = if fresh do
116-
rev_info = get_rev_info
117-
rev_info[:rev]
118-
else
119-
get_lock_rev(opts[:lock])
120-
end
121-
{ :git, opts[:git], lock, get_lock_opts(opts) }
115+
defp get_lock(opts) do
116+
rev_info = get_rev_info
117+
{ :git, opts[:git], rev_info[:rev], get_lock_opts(opts) }
122118
end
123119

124120
defp get_lock_rev({ :git, _repo, lock, _opts }) when is_binary(lock), do: lock

lib/mix/test/mix/scm/git_test.exs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Code.require_file "../../test_helper.exs", __DIR__
22

33
defmodule Mix.SCM.GitTest do
4-
use MixTest.Case
4+
use MixTest.Case, async: true
55

66
test "formats the lock" do
77
assert Mix.SCM.Git.format_lock(lock()) == "abcdef0"
@@ -10,6 +10,18 @@ defmodule Mix.SCM.GitTest do
1010
assert Mix.SCM.Git.format_lock(lock(ref: "abcdef0")) == "abcdef0 (ref)"
1111
end
1212

13+
test "considers to dep equals if the have the same git and the same opts" do
14+
assert Mix.SCM.Git.equal?([git: "foo"], [git: "foo"])
15+
refute Mix.SCM.Git.equal?([git: "foo"], [git: "bar"])
16+
17+
assert Mix.SCM.Git.equal?([git: "foo", branch: "master"], [git: "foo", branch: "master"])
18+
refute Mix.SCM.Git.equal?([git: "foo", branch: "master"], [git: "foo", branch: "other"])
19+
end
20+
21+
test "lock should not be taken into account when considering deps equal as the lock is shared" do
22+
assert Mix.SCM.Git.equal?([git: "foo", lock: 1], [git: "foo", lock: 2])
23+
end
24+
1325
defp lock(opts // []) do
1426
[lock: { :git, "/repo", "abcdef0123456789", opts }]
1527
end

0 commit comments

Comments
 (0)