2929from libvcs .cmd .git import Git
3030from libvcs .sync .base import (
3131 BaseSync ,
32+ SyncResult ,
3233 VCSLocation ,
3334 convert_pip_url as base_convert_pip_url ,
3435)
@@ -380,17 +381,22 @@ def update_repo(
380381 set_remotes : bool = False ,
381382 * args : t .Any ,
382383 ** kwargs : t .Any ,
383- ) -> None :
384+ ) -> SyncResult :
384385 """Pull latest changes from git remote."""
386+ result = SyncResult ()
385387 self .ensure_dir ()
386388
387389 if not pathlib .Path (self .path / ".git" ).is_dir ():
388390 self .obtain ()
389- self .update_repo (set_remotes = set_remotes )
390- return
391+ return self .update_repo (set_remotes = set_remotes )
391392
392393 if set_remotes :
393- self .set_remotes (overwrite = True )
394+ try :
395+ self .set_remotes (overwrite = True )
396+ except exc .CommandError as e :
397+ self .log .exception ("Failed to set remotes" )
398+ result .add_error ("set-remotes" , str (e ), exception = e )
399+ return result
394400
395401 # Get requested revision or tag
396402 url , git_tag = self .url , getattr (self , "rev" , None )
@@ -412,7 +418,7 @@ def update_repo(
412418 )
413419 except exc .CommandError :
414420 self .log .exception ("Failed to get the hash for HEAD" )
415- return
421+ return result
416422
417423 self .log .debug ("head_sha: %s" , head_sha )
418424
@@ -460,21 +466,23 @@ def update_repo(
460466 somethings_up = (error_code , is_remote_ref , tag_sha != head_sha )
461467 if all (not x for x in somethings_up ):
462468 self .log .info ("Already up-to-date." )
463- return
469+ return result
464470
465471 try :
466472 process = self .cmd .fetch (log_in_real_time = True , check_returncode = True )
467- except exc .CommandError :
473+ except exc .CommandError as e :
468474 self .log .exception ("Failed to fetch repository '%s'" , url )
469- return
475+ result .add_error ("fetch" , str (e ), exception = e )
476+ return result
470477
471478 if is_remote_ref :
472479 # Check if stash is needed
473480 try :
474481 process = self .cmd .status (porcelain = True , untracked_files = "no" )
475- except exc .CommandError :
482+ except exc .CommandError as e :
476483 self .log .exception ("Failed to get the status" )
477- return
484+ result .add_error ("status" , str (e ), exception = e )
485+ return result
478486 need_stash = len (process ) > 0
479487
480488 # If not in clean state, stash changes in order to be able
@@ -484,22 +492,25 @@ def update_repo(
484492 git_stash_save_options = "--quiet"
485493 try :
486494 process = self .cmd .stash .save (message = git_stash_save_options )
487- except exc .CommandError :
495+ except exc .CommandError as e :
488496 self .log .exception ("Failed to stash changes" )
497+ result .add_error ("stash-save" , str (e ), exception = e )
489498
490499 # Checkout the remote branch
491500 try :
492501 process = self .cmd .checkout (branch = git_tag )
493- except exc .CommandError :
502+ except exc .CommandError as e :
494503 self .log .exception ("Failed to checkout tag: '%s'" , git_tag )
495- return
504+ result .add_error ("checkout" , str (e ), exception = e )
505+ return result
496506
497507 # Rebase changes from the remote branch
498508 try :
499509 process = self .cmd .rebase (upstream = git_remote_name + "/" + git_tag )
500510 except exc .CommandError as e :
501511 if any (msg in str (e ) for msg in ["invalid_upstream" , "Aborting" ]):
502512 self .log .exception ("Invalid upstream remote. Rebase aborted." )
513+ result .add_error ("rebase" , str (e ), exception = e )
503514 else :
504515 # Rebase failed: Restore previous state.
505516 self .cmd .rebase (abort = True )
@@ -510,7 +521,8 @@ def update_repo(
510521 f"\n Failed to rebase in: '{ self .path } '.\n "
511522 "You will have to resolve the conflicts manually" ,
512523 )
513- return
524+ result .add_error ("rebase" , str (e ), exception = e )
525+ return result
514526
515527 if need_stash :
516528 try :
@@ -520,7 +532,7 @@ def update_repo(
520532 self .cmd .reset (hard = True , quiet = True )
521533 try :
522534 process = self .cmd .stash .pop (quiet = True )
523- except exc .CommandError :
535+ except exc .CommandError as e :
524536 # Stash pop failed: Restore previous state.
525537 self .cmd .reset (pathspec = head_sha , hard = True , quiet = True )
526538 self .cmd .stash .pop (index = True , quiet = True )
@@ -529,16 +541,19 @@ def update_repo(
529541 "You will have to resolve the "
530542 "conflicts manually" ,
531543 )
532- return
544+ result .add_error ("stash-pop" , str (e ), exception = e )
545+ return result
533546
534547 else :
535548 try :
536549 process = self .cmd .checkout (branch = git_tag )
537- except exc .CommandError :
550+ except exc .CommandError as e :
538551 self .log .exception ("Failed to checkout tag: '%s'" , git_tag )
539- return
552+ result .add_error ("checkout" , str (e ), exception = e )
553+ return result
540554
541555 self .cmd .submodule .update (recursive = True , init = True , log_in_real_time = True )
556+ return result
542557
543558 def remotes (self ) -> GitSyncRemoteDict :
544559 """Return remotes like git remote -v.
0 commit comments