Skip to content

Commit 738e940

Browse files
jeffro256Byron
authored andcommitted
feat(submodule): option to update without fetching
1 parent dafafff commit 738e940

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
@@ -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

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)