@@ -38,26 +38,26 @@ def _run_git(
3838 elif capture_output and echo_output : # pragma: no cover
3939 log .error (stderr )
4040 if not expect_stderr :
41- raise Exception (stderr )
41+ raise ChildProcessError (stderr )
4242
4343 if result .returncode < 0 :
44- raise Exception (result .stderr .decode ("utf-8" ))
44+ raise ChildProcessError (result .stderr .decode ("utf-8" ))
4545 return result
4646
4747
4848def clone (remote_repo : str , path : Path , shallow = False , tag : Optional [str ] = None ) -> bool :
49- "git clone [--depth 1] [--branch <tag_name>] <remote> <directory>"
49+ """ git clone [--depth 1] [--branch <tag_name>] <remote> <directory>"" "
5050 cmd = ["git" , "clone" ]
5151 if shallow :
5252 cmd += ["--depth" , "1" ]
5353 if tag in ("latest" , "master" ):
5454 tag = None
55- if not tag :
56- cmd += [remote_repo , str (path )]
57- else :
58- cmd += [remote_repo , "--branch" , tag , str (path )]
59- result = _run_git ( cmd , expect_stderr = True , capture_output = False )
60- if result :
55+ cmd += (
56+ [remote_repo , "--branch" , tag , str (path )]
57+ if tag
58+ else [remote_repo , str (path )]
59+ )
60+ if result := _run_git ( cmd , expect_stderr = True , capture_output = False ) :
6161 return result .returncode == 0
6262 else :
6363 return False
@@ -81,10 +81,11 @@ def get_tag(repo: Optional[Union[str, Path]] = None, abbreviate: bool = True) ->
8181 tag : str = result .stdout .decode ("utf-8" )
8282 tag = tag .replace ("\r " , "" ).replace ("\n " , "" )
8383 if abbreviate and "-" in tag :
84- # this may or not be the latest on the main branch
85- # result = _run_git(["git", "rev-parse", "--abbrev-ref", "HEAD"], repo=repo, expect_stderr=True)
86- result = _run_git (["git" , "status" , "--branch" ], repo = repo .as_posix (), expect_stderr = True )
87- if result :
84+ if result := _run_git (
85+ ["git" , "status" , "--branch" ],
86+ repo = repo .as_posix (),
87+ expect_stderr = True ,
88+ ):
8889 lines = result .stdout .decode ("utf-8" ).replace ("\r " , "" ).split ("\n " )
8990 if lines [0 ].startswith ("On branch" ):
9091 if lines [0 ].endswith ("master" ):
@@ -134,11 +135,11 @@ def synch_submodules(repo: Optional[Union[Path, str]] = None) -> bool:
134135 ["git" , "submodule" , "update" , "--quiet" ],
135136 ]
136137 for cmd in cmds :
137- result = _run_git (cmd , repo = repo , expect_stderr = True )
138- if not result :
138+ if result := _run_git (cmd , repo = repo , expect_stderr = True ):
139+ # actually a good result
140+ log .debug (result .stderr .decode ("utf-8" ))
141+ else :
139142 return False
140- # actually a good result
141- log .debug (result .stderr .decode ("utf-8" ))
142143 return True
143144
144145
@@ -203,9 +204,7 @@ def fetch(repo: Union[Path, str]) -> bool:
203204
204205 cmd = ["git" , "fetch" , "--all" , "--tags" , "--quiet" ]
205206 result = _run_git (cmd , repo = repo , echo_output = False )
206- if not result :
207- return False
208- return result .returncode == 0
207+ return result .returncode == 0 if result else False
209208
210209
211210def pull (repo : Union [Path , str ], branch = "main" ) -> bool :
0 commit comments