Skip to content

Commit 08d61e4

Browse files
author
José Valim
committed
Merge pull request #1954 from bitwalker/mix
Ensure deps.get updates origin if lock origin and dep origin do not match.
2 parents 9c9d8e8 + 4176480 commit 08d61e4

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

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

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@ defmodule Mix.SCM.Git do
2929
case opts[:lock] do
3030
{ :git, lock_repo, lock_rev, lock_opts } ->
3131
File.cd!(opts[:dest], fn ->
32+
rev_info = get_rev_info
3233
cond do
33-
lock_repo != opts[:git] -> :outdated
34+
lock_repo != opts[:git] -> :outdated
3435
lock_opts != get_lock_opts(opts) -> :outdated
35-
lock_rev != get_rev -> :mismatch
36+
lock_rev != rev_info[:rev] -> :mismatch
37+
lock_repo != rev_info[:origin] -> :outdated
3638
true -> :ok
3739
end
3840
end)
@@ -58,6 +60,10 @@ defmodule Mix.SCM.Git do
5860

5961
def update(opts) do
6062
File.cd! opts[:dest], fn ->
63+
# Ensures origin is set the lock repo
64+
location = location(opts[:git])
65+
update_origin(location)
66+
6167
command = "git fetch --force --progress"
6268
if opts[:tag] do
6369
command = command <> " --tags"
@@ -92,7 +98,12 @@ defmodule Mix.SCM.Git do
9298
end
9399

94100
defp get_lock(opts, fresh) do
95-
lock = if fresh, do: get_rev, else: get_lock_rev(opts[:lock])
101+
lock = if fresh do
102+
rev_info = get_rev_info
103+
rev_info[:rev]
104+
else
105+
get_lock_rev(opts[:lock])
106+
end
96107
{ :git, opts[:git], lock, get_lock_opts(opts) }
97108
end
98109

@@ -117,23 +128,15 @@ defmodule Mix.SCM.Git do
117128
end
118129
end
119130

120-
defp get_rev do
121-
check_rev System.cmd('git rev-parse --verify --quiet HEAD')
122-
end
123-
124-
defp check_rev([]), do: nil
125-
defp check_rev(list), do: check_rev(list, [])
126-
127-
defp check_rev([h|t], acc) when h in ?a..?f or h in ?0..?9 do
128-
check_rev(t, [h|acc])
129-
end
130-
131-
defp check_rev(fin, acc) when fin == [?\n] or fin == [] do
132-
Enum.reverse(acc) |> iolist_to_binary
131+
defp get_rev_info do
132+
[origin, rev] = System.cmd('git config remote.origin.url && git rev-parse --verify --quiet HEAD')
133+
|> iolist_to_binary
134+
|> String.split("\n", trim: true)
135+
[ origin: origin, rev: rev ]
133136
end
134137

135-
defp check_rev(_, _) do
136-
nil
138+
defp update_origin(location) do
139+
System.cmd('git config remote.origin.url #{location}')
137140
end
138141

139142
defp run_cmd_or_raise(command) do

0 commit comments

Comments
 (0)