@@ -75,15 +75,13 @@ defmodule Mix.SCM.Git do
7575
7676 cond do
7777 lock_rev = get_lock_rev ( lock , opts ) ->
78- File . cd! ( opts [ :checkout ] , fn ->
79- % { origin: origin , rev: rev } = get_rev_info ( )
78+ % { origin: origin , rev: rev } = get_rev_info ( opts [ :checkout ] )
8079
81- if get_lock_repo ( lock ) == origin and lock_rev == rev do
82- :ok
83- else
84- :mismatch
85- end
86- end )
80+ if get_lock_repo ( lock ) == origin and lock_rev == rev do
81+ :ok
82+ else
83+ :mismatch
84+ end
8785
8886 is_nil ( lock ) ->
8987 :mismatch
@@ -333,11 +331,11 @@ defmodule Mix.SCM.Git do
333331 end
334332 end
335333
336- defp get_rev_info do
334+ defp get_rev_info ( dir \\ nil ) do
337335 # These commands can fail and we don't want to raise.
338336 origin_command = [ "--git-dir=.git" , "config" , "remote.origin.url" ]
339337 rev_command = [ "--git-dir=.git" , "rev-parse" , "--verify" , "--quiet" , "HEAD" ]
340- opts = cmd_opts ( [ ] )
338+ opts = if dir , do: cmd_opts ( cd: dir ) , else: cmd_opts ( [ ] )
341339
342340 with { origin , 0 } <- System . cmd ( "git" , origin_command , opts ) ,
343341 { rev , 0 } <- System . cmd ( "git" , rev_command , opts ) do
@@ -391,13 +389,17 @@ defmodule Mix.SCM.Git do
391389 end
392390 end
393391
394- # Attempt to set the current working directory by default.
395- # This addresses an issue changing the working directory when executing from
396- # within a secondary node since file I/O is done through the main node.
397392 defp cmd_opts ( opts ) do
398- case File . cwd ( ) do
399- { :ok , cwd } -> Keyword . put ( opts , :cd , cwd )
400- _ -> opts
393+ if Keyword . has_key? ( opts , :cd ) do
394+ opts
395+ else
396+ # Attempt to set the current working directory by default.
397+ # This addresses an issue changing the working directory when executing from
398+ # within a secondary node since file I/O is done through the main node.
399+ case File . cwd ( ) do
400+ { :ok , cwd } -> Keyword . put ( opts , :cd , cwd )
401+ _ -> opts
402+ end
401403 end
402404 end
403405
0 commit comments