@@ -30,7 +30,7 @@ class Submodule(NamedTuple):
3030
3131def get_git_version () -> tuple [str , str ]:
3232 """Get the name and version of git."""
33- result = run_on_cmdline (logger , "git --version" )
33+ result = run_on_cmdline (logger , [ "git" , " --version"] )
3434 tool , version = result .stdout .decode ().strip ().split ("version" , maxsplit = 1 )
3535 return (str (tool ), str (version ))
3636
@@ -48,7 +48,11 @@ def is_git(self) -> bool:
4848 return True
4949
5050 try :
51- run_on_cmdline (logger , f"git ls-remote --heads { self ._remote } " )
51+ run_on_cmdline (
52+ logger ,
53+ cmd = ["git" , "ls-remote" , "--heads" , self ._remote ],
54+ env = {"GIT_TERMINAL_PROMPT" : "0" },
55+ )
5256 return True
5357 except SubprocessCommandError as exc :
5458 if exc .returncode == 128 and "Could not resolve host" in exc .stdout :
@@ -82,7 +86,9 @@ def get_default_branch(self) -> str:
8286 """Try to get the default branch or fallback to master."""
8387 try :
8488 result = run_on_cmdline (
85- logger , f"git ls-remote --symref { self ._remote } HEAD"
89+ logger ,
90+ cmd = ["git" , "ls-remote" , "--symref" , self ._remote , "HEAD" ],
91+ env = {"GIT_TERMINAL_PROMPT" : "0" },
8692 ).stdout .decode ()
8793 except SubprocessCommandError :
8894 logger .debug (
@@ -101,7 +107,9 @@ def get_default_branch(self) -> str:
101107 @staticmethod
102108 def _ls_remote (remote : str ) -> dict [str , str ]:
103109 result = run_on_cmdline (
104- logger , f"git ls-remote --heads --tags { remote } "
110+ logger ,
111+ cmd = ["git" , "ls-remote" , "--heads" , "--tags" , remote ],
112+ env = {"GIT_TERMINAL_PROMPT" : "0" },
105113 ).stdout .decode ()
106114
107115 info : dict [str , str ] = {}
@@ -156,12 +164,14 @@ def check_version_exists(
156164 temp_dir = tempfile .mkdtemp ()
157165 exists = False
158166 with in_directory (temp_dir ):
159- run_on_cmdline (logger , "git init" )
160- run_on_cmdline (logger , f "git remote add origin { self ._remote } " )
161- run_on_cmdline (logger , "git checkout -b dfetch-local-branch" )
167+ run_on_cmdline (logger , [ "git" , " init"] )
168+ run_on_cmdline (logger , [ "git" , " remote" , " add" , " origin" , self ._remote ] )
169+ run_on_cmdline (logger , [ "git" , " checkout" , "-b" , " dfetch-local-branch"] )
162170 try :
163171 run_on_cmdline (
164- logger , f"git fetch --dry-run --depth 1 origin { version } "
172+ logger ,
173+ ["git" , "fetch" , "--dry-run" , "--depth" , "1" , "origin" , version ],
174+ env = {"GIT_TERMINAL_PROMPT" : "0" },
165175 )
166176 exists = True
167177 except SubprocessCommandError as exc :
@@ -185,7 +195,11 @@ def is_git(self) -> bool:
185195 """Check if is git."""
186196 try :
187197 with in_directory (self ._path ):
188- run_on_cmdline (logger , "git status" )
198+ run_on_cmdline (
199+ logger ,
200+ ["git" , "status" ],
201+ env = {"GIT_TERMINAL_PROMPT" : "0" },
202+ )
189203 return True
190204 except (SubprocessCommandError , RuntimeError ):
191205 return False
@@ -209,12 +223,12 @@ def checkout_version( # pylint: disable=too-many-arguments
209223 ignore (Optional[Sequence[str]]): Optional sequence of glob patterns to ignore (relative to src)
210224 """
211225 with in_directory (self ._path ):
212- run_on_cmdline (logger , "git init" )
213- run_on_cmdline (logger , f "git remote add origin { remote } " )
214- run_on_cmdline (logger , "git checkout -b dfetch-local-branch" )
226+ run_on_cmdline (logger , [ "git" , " init"] )
227+ run_on_cmdline (logger , [ "git" , " remote" , " add" , " origin" , remote ] )
228+ run_on_cmdline (logger , [ "git" , " checkout" , "-b" , " dfetch-local-branch"] )
215229
216230 if src or ignore :
217- run_on_cmdline (logger , "git config core.sparsecheckout true" )
231+ run_on_cmdline (logger , [ "git" , " config" , " core.sparsecheckout" , " true"] )
218232 with open (
219233 ".git/info/sparse-checkout" , "a" , encoding = "utf-8"
220234 ) as sparse_checkout_file :
@@ -228,11 +242,17 @@ def checkout_version( # pylint: disable=too-many-arguments
228242 sparse_checkout_file .write ("\n " )
229243 sparse_checkout_file .write ("\n " .join (ignore_abs_paths ))
230244
231- run_on_cmdline (logger , f"git fetch --depth 1 origin { version } " )
232- run_on_cmdline (logger , "git reset --hard FETCH_HEAD" )
245+ run_on_cmdline (
246+ logger ,
247+ ["git" , "fetch" , "--depth" , "1" , "origin" , version ],
248+ env = {"GIT_TERMINAL_PROMPT" : "0" },
249+ )
250+ run_on_cmdline (logger , ["git" , "reset" , "--hard" , "FETCH_HEAD" ])
233251
234252 current_sha = (
235- run_on_cmdline (logger , "git rev-parse HEAD" ).stdout .decode ().strip ()
253+ run_on_cmdline (logger , ["git" , "rev-parse" , "HEAD" ])
254+ .stdout .decode ()
255+ .strip ()
236256 )
237257
238258 if src :
@@ -305,10 +325,7 @@ def get_current_hash(self) -> str:
305325 def get_remote_url () -> str :
306326 """Get the url of the remote origin."""
307327 try :
308- result = run_on_cmdline (
309- logger ,
310- ["git" , "remote" , "get-url" , "origin" ],
311- )
328+ result = run_on_cmdline (logger , ["git" , "remote" , "get-url" , "origin" ])
312329 decoded_result = str (result .stdout .decode ())
313330 except SubprocessCommandError :
314331 decoded_result = ""
0 commit comments