Skip to content

Commit 5c340e4

Browse files
committed
Migrate the git repo against the origin branch, closes #14163
1 parent defef37 commit 5c340e4

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,17 +126,17 @@ defmodule Mix.SCM.Git do
126126
update_origin(opts[:git])
127127

128128
# Fetch external data
129-
rev = get_lock_rev(opts[:lock], opts) || get_opts_rev(opts)
129+
lock_rev = get_lock_rev(opts[:lock], opts)
130130

131131
["--git-dir=.git", "fetch", "--force", "--quiet"]
132132
|> Kernel.++(progress_switch(git_version()))
133133
|> Kernel.++(tags_switch(opts[:tag]))
134134
|> Kernel.++(depth_switch(opts[:depth]))
135-
|> Kernel.++(refspec_switch(opts, rev))
135+
|> Kernel.++(refspec_switch(opts, lock_rev || get_opts_rev(opts)))
136136
|> git!()
137137

138138
# Migrate the Git repo
139-
rev = rev || default_branch()
139+
rev = lock_rev || get_origin_opts_rev(opts) || default_branch()
140140
git!(["--git-dir=.git", "checkout", "--quiet", rev])
141141

142142
if opts[:submodules] do
@@ -314,6 +314,14 @@ defmodule Mix.SCM.Git do
314314
opts[:branch] || opts[:ref] || opts[:tag]
315315
end
316316

317+
defp get_origin_opts_rev(opts) do
318+
if branch = opts[:branch] do
319+
"origin/#{branch}"
320+
else
321+
opts[:ref] || opts[:tag]
322+
end
323+
end
324+
317325
defp redact_uri(git) do
318326
case URI.parse(git) do
319327
%{userinfo: nil} -> git

0 commit comments

Comments
 (0)