@@ -9,7 +9,7 @@ defmodule Mix.SCM.Git do
9
9
10
10
@ impl true
11
11
def format ( opts ) do
12
- if rev = get_opts_rev ( opts ) do
12
+ if rev = opts [ :ref ] || opts [ :branch ] || opts [ :tag ] do
13
13
"#{ redact_uri ( opts [ :git ] ) } - #{ rev } "
14
14
else
15
15
redact_uri ( opts [ :git ] )
@@ -22,7 +22,7 @@ defmodule Mix.SCM.Git do
22
22
{ :git , _ , lock_rev , lock_opts } ->
23
23
lock = String . slice ( lock_rev , 0 , 7 )
24
24
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
26
26
{ :ref , _ } -> lock <> " (ref)"
27
27
{ key , val } -> lock <> " (#{ key } : #{ val } )"
28
28
nil -> lock
@@ -125,18 +125,18 @@ defmodule Mix.SCM.Git do
125
125
sparse_toggle ( opts )
126
126
update_origin ( opts [ :git ] )
127
127
128
- rev = get_lock_rev ( opts [ :lock ] , opts ) || get_opts_rev ( opts )
129
-
130
128
# Fetch external data
129
+ branch_or_tag = opts [ :branch ] || opts [ :tag ]
130
+
131
131
[ "--git-dir=.git" , "fetch" , "--force" , "--quiet" ]
132
132
|> Kernel . ++ ( progress_switch ( git_version ( ) ) )
133
133
|> Kernel . ++ ( tags_switch ( opts [ :tag ] ) )
134
134
|> 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: [ ] )
136
136
|> git! ( )
137
137
138
138
# Migrate the Git repo
139
- rev = rev || default_branch ( )
139
+ rev = get_lock_rev ( opts [ :lock ] , opts ) || opts [ :ref ] || branch_or_tag || default_branch ( )
140
140
git! ( [ "--git-dir=.git" , "checkout" , "--quiet" , rev ] )
141
141
142
142
if opts [ :submodules ] do
@@ -250,18 +250,24 @@ defmodule Mix.SCM.Git do
250
250
end
251
251
252
252
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
+ )
256
259
257
- [ { : depth, depth } ] when is_integer ( depth ) and depth > 0 ->
260
+ [ depth: depth ] when is_integer ( depth ) and depth > 0 ->
258
261
opts
259
262
260
- invalid_depth ->
263
+ [ depth: invalid_depth ] ->
261
264
Mix . raise (
262
265
"The depth must be a positive integer, and be specified only once, got: #{ inspect ( invalid_depth ) } . " <>
263
266
"Error on Git dependency: #{ redact_uri ( opts [ :git ] ) } "
264
267
)
268
+
269
+ _ ->
270
+ opts
265
271
end
266
272
end
267
273
@@ -290,10 +296,6 @@ defmodule Mix.SCM.Git do
290
296
end
291
297
end
292
298
293
- defp get_opts_rev ( opts ) do
294
- opts [ :branch ] || opts [ :ref ] || opts [ :tag ]
295
- end
296
-
297
299
defp redact_uri ( git ) do
298
300
case URI . parse ( git ) do
299
301
% { userinfo: nil } -> git
0 commit comments