@@ -9,7 +9,7 @@ defmodule Mix.SCM.Git do
99
1010 @ impl true
1111 def format ( opts ) do
12- if rev = get_opts_rev ( opts ) do
12+ if rev = opts [ :ref ] || opts [ :branch ] || opts [ :tag ] do
1313 "#{ redact_uri ( opts [ :git ] ) } - #{ rev } "
1414 else
1515 redact_uri ( opts [ :git ] )
@@ -22,7 +22,7 @@ defmodule Mix.SCM.Git do
2222 { :git , _ , lock_rev , lock_opts } ->
2323 lock = String . slice ( lock_rev , 0 , 7 )
2424
25- case Enum . find_value ( [ :branch , :ref , :tag ] , & List . keyfind ( lock_opts , & 1 , 0 ) ) do
25+ case Enum . find_value ( [ :ref , :branch , :tag ] , & List . keyfind ( lock_opts , & 1 , 0 ) ) do
2626 { :ref , _ } -> lock <> " (ref)"
2727 { key , val } -> lock <> " (#{ key } : #{ val } )"
2828 nil -> lock
@@ -125,18 +125,18 @@ defmodule Mix.SCM.Git do
125125 sparse_toggle ( opts )
126126 update_origin ( opts [ :git ] )
127127
128- rev = get_lock_rev ( opts [ :lock ] , opts ) || get_opts_rev ( opts )
129-
130128 # Fetch external data
129+ branch_or_tag = opts [ :branch ] || opts [ :tag ]
130+
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 . ++ ( if rev , do: [ "origin" , rev ] , else: [ ] )
135+ |> Kernel . ++ ( if branch_or_tag , do: [ "origin" , branch_or_tag ] , else: [ ] )
136136 |> git! ( )
137137
138138 # Migrate the Git repo
139- rev = rev || default_branch ( )
139+ rev = get_lock_rev ( opts [ :lock ] , opts ) || opts [ :ref ] || branch_or_tag || default_branch ( )
140140 git! ( [ "--git-dir=.git" , "checkout" , "--quiet" , rev ] )
141141
142142 if opts [ :submodules ] do
@@ -250,18 +250,24 @@ defmodule Mix.SCM.Git do
250250 end
251251
252252 defp validate_depth ( opts ) do
253- case Keyword . take ( opts , [ :depth ] ) do
254- [ ] ->
255- opts
253+ case Keyword . take ( opts , [ :depth , :ref ] ) do
254+ [ _ , _ ] ->
255+ Mix . raise (
256+ "Cannot specify :depth and :ref at the same time. " <>
257+ "Error on Git dependency: #{ redact_uri ( opts [ :git ] ) } "
258+ )
256259
257- [ { : depth, depth } ] when is_integer ( depth ) and depth > 0 ->
260+ [ depth: depth ] when is_integer ( depth ) and depth > 0 ->
258261 opts
259262
260- invalid_depth ->
263+ [ depth: invalid_depth ] ->
261264 Mix . raise (
262265 "The depth must be a positive integer, and be specified only once, got: #{ inspect ( invalid_depth ) } . " <>
263266 "Error on Git dependency: #{ redact_uri ( opts [ :git ] ) } "
264267 )
268+
269+ _ ->
270+ opts
265271 end
266272 end
267273
@@ -290,10 +296,6 @@ defmodule Mix.SCM.Git do
290296 end
291297 end
292298
293- defp get_opts_rev ( opts ) do
294- opts [ :branch ] || opts [ :ref ] || opts [ :tag ]
295- end
296-
297299 defp redact_uri ( git ) do
298300 case URI . parse ( git ) do
299301 % { userinfo: nil } -> git
0 commit comments