Skip to content

Commit 1d855b7

Browse files
committed
submodule: option to update without fetching
1 parent 7609492 commit 1d855b7

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

git/objects/submodule/base.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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 attempted 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,8 @@ 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("Missing module at %r but fetching is disabled" % self.path) from None
916928
if self.url.startswith("."):
917929
url = urllib.parse.urljoin(self.repo.remotes.origin.url + "/", self.url)
918930
else:
@@ -1061,6 +1073,7 @@ def fetch_remotes(module_repo: "Repo") -> None:
10611073
dry_run=dry_run,
10621074
force=force,
10631075
keep_going=keep_going,
1076+
no_fetch=no_fetch,
10641077
)
10651078
# END handle recursive update
10661079
# END handle dry run

git/objects/submodule/root.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ def update( # type: ignore[override]
8787
dry_run: bool = False,
8888
force_reset: bool = False,
8989
keep_going: bool = False,
90+
no_fetch: bool = False,
9091
) -> "RootModule":
9192
"""Update the submodules of this repository to the current HEAD commit.
9293
@@ -146,6 +147,10 @@ def update( # type: ignore[override]
146147
In conjunction with `dry_run`, this can be useful to anticipate all errors
147148
when updating submodules.
148149
150+
:param no_fetch:
151+
If ``True``, submodule updating will be attempted without fetching
152+
new changes from remotes.
153+
149154
:return:
150155
self
151156
"""
@@ -274,7 +279,8 @@ def update( # type: ignore[override]
274279
if not dry_run:
275280
assert nn not in [r.name for r in rmts]
276281
smr = smm.create_remote(nn, sm.url)
277-
smr.fetch(progress=progress)
282+
if not no_fetch:
283+
smr.fetch(progress=progress)
278284

279285
# If we have a tracking branch, it should be available
280286
# in the new remote as well.
@@ -433,6 +439,7 @@ def update( # type: ignore[override]
433439
dry_run=dry_run,
434440
force=force_reset,
435441
keep_going=keep_going,
442+
no_fetch=no_fetch,
436443
)
437444

438445
# Update recursively depth first - question is which inconsistent state will

0 commit comments

Comments
 (0)