Allow file fetchers to opt into loading git submodules#5982
Conversation
Private methods were interspersed with protected methods under comment heading, 'INTERNAL METHODS (not for use by sub-classes)'. This change simply moves the protected methods above this heading.
jakecoffman
left a comment
There was a problem hiding this comment.
Makes sense to me, great work!
|
👋 hey friends! This broke our updates 😿 We build a Before this PR, dependabot worked great. Is there any way for us to disable this new functionality via configuration? |
| end | ||
|
|
||
| def recurse_submodules_when_cloning? | ||
| true |
There was a problem hiding this comment.
Something we can try here to mitigate the issue @thepwagner brought up is only install submodules if the initial dependency resolution step failed to run
We do something of that sorts for Terraform modules in
dependabot-core/terraform/lib/dependabot/terraform/file_updater.rb
Lines 242 to 253 in 95df3a4
There was a problem hiding this comment.
Another option might be we leave the submodule clone by default, but ignore any errors to attempt the update anyway? That way if it didn't matter then we still do the update.
Context
Closes #5975
Repos are always git-cloned with
--no-recurse-submodules. This can be problematic if a dependency lives in a git submodule and dependency resolution requires reading from it. For my use case, this is showing up when using go modules.What's Changing
This PR adds
#recurse_submodules_when_cloning?toDependabot::FileFetchers::Base. If it returns a truthy value, repos are git-cloned with--recurse-submodulesand--shallow-submodules; if it returns a falsy value,--no-recurse-submodulesis used (the current behavior).The default implementation of the method returns false, preserving the existing behavior for all file fetchers. Subclasses of
Dependabot::FileFetchers::Basemay override to opt into the behavior, and this PR does so for the go modules file fetcher.The change also extends the behavior to the git-fetch and git-reset operations if
source.commitis present (i.e., for testing). The relevant options used aregit fetch --recurse-submodules=on-demandandgit reset --recurse-submodules.How to Review
I recommend reviewing this PR by commit:
0b1f097: I noticed that
Dependabot::FileFetchers::Basedeclares some methods "private" (rubyprivate, prefixed with underscore) under a comment heading that says they should not be used by subclasses, but some "protected" (rubyprivate, no underscore) methods were mixed in with these under the same comment. This commit moves the protected methods above the comment, which makes the overall diff appear larger than what's actually changing.41bac21: adds
#recurse_submodules_when_cloning?and integrates it into#_clone_repo_contents.2f8a624: overrides
#recurse_submodules_when_cloning?for thego_modulesfile fetcher in order to opt into the behavior.