@@ -733,6 +733,7 @@ def update(
733733 clone_multi_options : Union [Sequence [TBD ], None ] = None ,
734734 allow_unsafe_options : bool = False ,
735735 allow_unsafe_protocols : bool = False ,
736+ no_fetch : bool = False ,
736737 ) -> "Submodule" :
737738 """Update the repository of this submodule to point to the checkout we point at
738739 with the binsha of this instance.
@@ -795,6 +796,10 @@ def update(
795796 :param allow_unsafe_options:
796797 Allow unsafe options to be used, like ``--upload-pack``.
797798
799+ :param no_fetch:
800+ If ``True``, submodule updating will be attemped without fetching
801+ new changes from remotes.
802+
798803 :note:
799804 Does nothing in bare repositories.
800805
@@ -857,7 +862,8 @@ def fetch_remotes(module_repo: "Repo") -> None:
857862 #######################################
858863 try :
859864 mrepo = self .module ()
860- fetch_remotes (mrepo )
865+ if not no_fetch :
866+ fetch_remotes (mrepo )
861867 except InvalidGitRepositoryError :
862868 mrepo = None
863869 if not init :
@@ -884,6 +890,10 @@ def fetch_remotes(module_repo: "Repo") -> None:
884890 raise OSError (
885891 "Module directory at %r does already exist and is non-empty" % checkout_module_abspath
886892 )
893+ elif no_fetch :
894+ raise ValueError (
895+ "Module directory at %r is empty but fetching is disabled" % checkout_module_abspath
896+ )
887897 os .makedirs (checkout_module_abspath , exist_ok = True )
888898 self ._write_git_file_and_module_config (checkout_module_abspath , module_abspath )
889899 mrepo = git .Repo (checkout_module_abspath )
@@ -913,6 +923,10 @@ def fetch_remotes(module_repo: "Repo") -> None:
913923 + "Cloning url '%s' to '%s' in submodule %r" % (self .url , checkout_module_abspath , self .name ),
914924 )
915925 if not dry_run :
926+ if no_fetch :
927+ raise ValueError (
928+ "Missing module at %r but fetching is disabled" % self .path
929+ )
916930 if self .url .startswith ("." ):
917931 url = urllib .parse .urljoin (self .repo .remotes .origin .url + "/" , self .url )
918932 else :
@@ -1061,6 +1075,7 @@ def fetch_remotes(module_repo: "Repo") -> None:
10611075 dry_run = dry_run ,
10621076 force = force ,
10631077 keep_going = keep_going ,
1078+ no_fetch = no_fetch ,
10641079 )
10651080 # END handle recursive update
10661081 # END handle dry run
0 commit comments