@@ -42,13 +42,13 @@ def confirm_tag_in_repo(repo_path: str, tag: str, repo_name: str) -> Optional[st
4242 exist.
4343 """
4444
45- tag_exists = Git .capture (
46- repo_path , ["ls-remote" , "--tags" , "origin" , tag ], echo = False
45+ tag_exists , _ , _ = Git .run (
46+ repo_path , ["ls-remote" , "--tags" , "origin" , tag ], fatal = True
4747 )
4848 if not tag_exists :
4949 print ("Tag '" + tag + "' does not exist for '" +
5050 repo_name + "', just updating regularly" )
51- tag = None
51+ return None
5252 return tag
5353
5454
@@ -61,7 +61,7 @@ def find_rev_by_timestamp(repo_path: str, timestamp: str, repo_name: str, refspe
6161 args = ["log" , "-1" , "--format=%H" , "--first-parent" , "--before=" + timestamp ]
6262 if refspec_exists :
6363 args .append (refspec )
64- rev = Git .capture (repo_path , args ). strip ( )
64+ rev , _ , _ = Git .run (repo_path , args , fatal = True )
6565 if rev :
6666 return rev
6767 else :
@@ -98,7 +98,7 @@ def get_branch_for_repo(repo_path, config, repo_name, scheme_name, scheme_map,
9898 pr_id = cross_repos_pr [remote_repo_id ]
9999 repo_branch = "ci_pr_{0}" .format (pr_id )
100100 Git .run (repo_path , ["checkout" , scheme_branch ], echo = True )
101- Git .capture (repo_path , ["branch" , "-D" , repo_branch ], echo = True , allow_non_zero_exit = True )
101+ Git .run (repo_path , ["branch" , "-D" , repo_branch ], echo = True , allow_non_zero_exit = True , fatal = True )
102102 Git .run (repo_path , ["fetch" , "origin" , "pull/{0}/merge:{1}" .format (pr_id , repo_branch ), "--tags" ], echo = True )
103103 return repo_branch , cross_repo
104104
@@ -172,7 +172,7 @@ def run_for_repo_and_each_submodule_rec(args: List[str]):
172172 pass
173173
174174 if checkout_target :
175- Git .run (repo_path , ['status' , '--porcelain' , '-uno' ], echo = False )
175+ Git .run (repo_path , ['status' , '--porcelain' , '-uno' ])
176176
177177 # Some of the projects switch branches/tags when they
178178 # are updated. Local checkout might not have that tag/branch
@@ -199,8 +199,7 @@ def run_for_repo_and_each_submodule_rec(args: List[str]):
199199 )
200200 except Exception :
201201 try :
202- result = Git .run (repo_path , ["rev-parse" , checkout_target ])
203- revision = result [0 ].strip ()
202+ revision , _ , _ = Git .run (repo_path , ["rev-parse" , checkout_target ])
204203 Git .run (
205204 repo_path , ["checkout" , revision ], echo = verbose , prefix = prefix
206205 )
@@ -233,7 +232,7 @@ def run_for_repo_and_each_submodule_rec(args: List[str]):
233232 # This git command returns error code 1 if HEAD is detached.
234233 # Otherwise there was some other error, and we need to handle
235234 # it like other command errors.
236- Git .run (repo_path , ["symbolic-ref" , "-q" , "HEAD" ], echo = False )
235+ Git .run (repo_path , ["symbolic-ref" , "-q" , "HEAD" ])
237236 except Exception as e :
238237 if e .ret == 1 :
239238 detached_head = True
@@ -286,9 +285,8 @@ def get_timestamp_to_match(match_timestamp, source_root):
286285 if not match_timestamp :
287286 return None
288287 swift_repo_path = os .path .join (source_root , "swift" )
289- return Git .capture (
290- swift_repo_path , ["log" , "-1" , "--format=%cI" ], echo = False
291- ).strip ()
288+ output , _ , _ = Git .run (swift_repo_path , ["log" , "-1" , "--format=%cI" ], fatal = True )
289+ return output
292290
293291
294292def get_scheme_map (config , scheme_name ):
@@ -410,35 +408,31 @@ def obtain_additional_swift_sources(pool_args: AdditionalSwiftSourcesArguments):
410408 print ("Cloning '" + pool_args .repo_name + "'" )
411409
412410 if pool_args .skip_history :
413- Git .run (None , ['clone' , '--recursive' , '--depth' , '1' ,
411+ Git .run (args . source_root , ['clone' , '--recursive' , '--depth' , '1' ,
414412 '--branch' , repo_branch , remote , repo_name ] +
415413 (['--no-tags' ] if skip_tags else []),
416- cwd = args .source_root ,
417414 env = env ,
418415 echo = verbose )
419416 elif pool_args .use_submodules :
420- Git .run (None , ['submodule' , 'add' , remote , repo_name ] +
417+ Git .run (args . source_root , ['submodule' , 'add' , remote , repo_name ] +
421418 (['--no-tags' ] if skip_tags else []),
422- cwd = args .source_root ,
423419 env = env ,
424420 echo = verbose )
425421 else :
426- Git .run (None , ['clone' , '--recursive' , remote , repo_name ] +
422+ Git .run (args . source_root , ['clone' , '--recursive' , remote , repo_name ] +
427423 (['--no-tags' ] if skip_tags else []),
428- cwd = args .source_root ,
429424 env = env ,
430425 echo = verbose )
431426
432427 repo_path = os .path .join (args .source_root , repo_name )
433428 if pool_args .scheme_name :
434429 src_path = os .path .join (repo_path , ".git" )
435430 Git .run (
436- None ,
431+ args . source_root ,
437432 ["--git-dir" , src_path , "--work-tree" , repo_path , "checkout" , repo_branch ],
438433 env = env ,
439- echo = False ,
440434 )
441- Git .run (repo_path , ["submodule" , "update" , "--recursive" ], env = env , echo = False )
435+ Git .run (repo_path , ["submodule" , "update" , "--recursive" ], env = env )
442436
443437
444438def obtain_all_additional_swift_sources (args , config , with_ssh , scheme_name ,
@@ -455,8 +449,7 @@ def obtain_all_additional_swift_sources(args, config, with_ssh, scheme_name,
455449
456450 if use_submodules :
457451 repo_exists = False
458- submodules_status = Git .capture (repo_path , ['submodule' , 'status' ],
459- echo = False )
452+ submodules_status , _ , _ = Git .run (repo_path , ['submodule' , 'status' ], fatal = True )
460453 if submodules_status :
461454 for line in submodules_status .splitlines ():
462455 if line [0 ].endswith (repo_name ):
@@ -557,7 +550,7 @@ def repo_hashes(args, config):
557550 for repo_name , _ in sorted (config ['repos' ].items (), key = lambda x : x [0 ]):
558551 repo_path = os .path .join (args .source_root , repo_name )
559552 if os .path .exists (repo_path ):
560- h = Git .capture (repo_path , ["rev-parse" , "HEAD" ], echo = False ). strip ( )
553+ h , _ , _ = Git .run (repo_path , ["rev-parse" , "HEAD" ], fatal = True )
561554 else :
562555 h = "skip"
563556 repos [repo_name ] = str (h )
@@ -633,11 +626,12 @@ def validate_config(config: Dict[str, Any]):
633626
634627
635628def full_target_name (repo_path , repository , target ):
636- tag = Git .capture (repo_path , ["tag" , "-l" , target ], echo = False ). strip ( )
629+ tag , _ , _ = Git .run (repo_path , ["tag" , "-l" , target ], fatal = True )
637630 if tag == target :
638631 return tag
639632
640- branch = Git .capture (repo_path , ["branch" , "--list" , target ], echo = False ).strip ().replace ("* " , "" )
633+ branch , _ , _ = Git .run (repo_path , ["branch" , "--list" , target ], fatal = True )
634+ branch = branch .replace ("* " , "" )
641635 if branch == target :
642636 name = "%s/%s" % (repository , target )
643637 return name
0 commit comments