@@ -729,6 +729,7 @@ def update(
729729 clone_multi_options : Union [Sequence [TBD ], None ] = None ,
730730 allow_unsafe_options : bool = False ,
731731 allow_unsafe_protocols : bool = False ,
732+ no_fetch : bool = False ,
732733 ) -> "Submodule" :
733734 """Update the repository of this submodule to point to the checkout we point at
734735 with the binsha of this instance.
@@ -791,6 +792,10 @@ def update(
791792 :param allow_unsafe_options:
792793 Allow unsafe options to be used, like ``--upload-pack``.
793794
795+ :param no_fetch:
796+ If ``True``, submodule updating will be attempted without fetching
797+ new changes from remotes.
798+
794799 :note:
795800 Does nothing in bare repositories.
796801
@@ -853,7 +858,8 @@ def fetch_remotes(module_repo: "Repo") -> None:
853858 #######################################
854859 try :
855860 mrepo = self .module ()
856- fetch_remotes (mrepo )
861+ if not no_fetch :
862+ fetch_remotes (mrepo )
857863 except InvalidGitRepositoryError :
858864 mrepo = None
859865 if not init :
@@ -880,6 +886,10 @@ def fetch_remotes(module_repo: "Repo") -> None:
880886 raise OSError (
881887 "Module directory at %r does already exist and is non-empty" % checkout_module_abspath
882888 )
889+ elif no_fetch :
890+ raise ValueError (
891+ "Module directory at %r is empty but fetching is disabled" % checkout_module_abspath
892+ )
883893 os .makedirs (checkout_module_abspath , exist_ok = True )
884894 self ._write_git_file_and_module_config (checkout_module_abspath , module_abspath )
885895 mrepo = git .Repo (checkout_module_abspath )
@@ -909,6 +919,8 @@ def fetch_remotes(module_repo: "Repo") -> None:
909919 + "Cloning url '%s' to '%s' in submodule %r" % (self .url , checkout_module_abspath , self .name ),
910920 )
911921 if not dry_run :
922+ if no_fetch :
923+ raise ValueError ("Missing module at %r but fetching is disabled" % self .path ) from None
912924 if self .url .startswith ("." ):
913925 url = urllib .parse .urljoin (self .repo .remotes .origin .url + "/" , self .url )
914926 else :
@@ -1057,6 +1069,7 @@ def fetch_remotes(module_repo: "Repo") -> None:
10571069 dry_run = dry_run ,
10581070 force = force ,
10591071 keep_going = keep_going ,
1072+ no_fetch = no_fetch ,
10601073 )
10611074 # END handle recursive update
10621075 # END handle dry run
0 commit comments