Respect submodule update=none strategy in .gitmodules#10717
Merged
bors merged 1 commit intorust-lang:masterfrom Jun 7, 2022
Merged
Respect submodule update=none strategy in .gitmodules#10717bors merged 1 commit intorust-lang:masterfrom
bors merged 1 commit intorust-lang:masterfrom
Conversation
|
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @ehuss (or someone else) soon. Please see the contribution instructions for more information. |
Muscraft
reviewed
May 31, 2022
src/cargo/sources/git/utils.rs
Outdated
Member
Contributor
Author
There was a problem hiding this comment.
Thanks for the pointers @Muscraft. Let me do that.
7de931d to
a05107a
Compare
Contributor
Author
|
v2:
PTAL |
Muscraft
reviewed
Jun 6, 2022
Git lets users define the default update/checkout strategy for a submodule
by setting the `submodule.<name>.update` key in `.gitmodules` file.
If the update strategy is `none`, the submodule will be skipped during
update. It will not be fetched and checked out:
1. *foo* is a big git repo
```
/tmp $ git init foo
Initialized empty Git repository in /tmp/foo/.git/
/tmp $ dd if=/dev/zero of=foo/big bs=1000M count=1
1+0 records in
1+0 records out
1048576000 bytes (1.0 GB, 1000 MiB) copied, 0.482087 s, 2.2 GB/s
/tmp $ git -C foo add big
/tmp $ git -C foo commit -m 'I am big'
[main (root-commit) 84fb533] I am big
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 big
```
2. *bar* is a repo with a big submodule with `update=none`
```
/tmp $ git init bar
Initialized empty Git repository in /tmp/bar/.git/
/tmp $ git -C bar submodule add file:///tmp/foo foo
Cloning into '/tmp/bar/foo'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 1 (delta 0), pack-reused 0
Receiving objects: 100% (3/3), 995.50 KiB | 338.00 KiB/s, done.
/tmp $ git -C bar config --file .gitmodules submodule.foo.update none
/tmp $ cat bar/.gitmodules
[submodule "foo"]
path = foo
url = file:///tmp/foo
update = none
/tmp $ git -C bar commit --all -m 'I have a big submodule with update=none'
[main (root-commit) 6c355ea] I have a big submodule not updated by default
2 files changed, 4 insertions(+)
create mode 100644 .gitmodules
create mode 160000 foo
```
3. *baz* is a clone of *bar*, notice *foo* submodule gets skipped
```
/tmp $ git clone --recurse-submodules file:///tmp/bar baz
Cloning into 'baz'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (3/3), done.
Submodule 'foo' (file:///tmp/foo) registered for path 'foo'
Skipping submodule 'foo'
/tmp $ git -C baz submodule update --init
Skipping submodule 'foo'
/tmp $
```
Cargo, on the other hand, ignores the submodule update strategy set in
`.gitmodules` properties when updating dependencies. Such behavior can
be considered against the wish of the crate publisher.
4. *bar* is now a lib with a big submodule with update disabled
```
/tmp $ cargo init --lib bar
Created library package
/tmp $ git -C bar add .
/tmp $ git -C bar commit -m 'I am a lib with a big submodule but update=none'
[main eb07cf7] I am a lib with a big submodule but update=none
3 files changed, 18 insertions(+)
create mode 100644 .gitignore
create mode 100644 Cargo.toml
create mode 100644 src/lib.rs
/tmp $
```
5. *qux* depends on *bar*, notice *bar*'s submodules are fetched
```
/tmp $ cargo init qux && cd qux
Created binary (application) package
/tmp/qux $ echo -e '[dependencies.bar]\ngit = "file:///tmp/bar"' >> Cargo.toml
/tmp/qux $ time cargo update
Updating git repository `file:///tmp/bar`
Updating git submodule `file:///tmp/foo`
real 0m22.182s
user 0m20.402s
sys 0m1.714s
/tmp/qux $
```
Fix it by checking if a Git repository submodule should be updated when
cargo processes dependencies.
6. With the change applied, submodules with `update=none` are skipped
```
/tmp/qux $ cargo cache -a > /dev/null
/tmp/qux $ time ~/src/cargo/target/debug/cargo update
Updating git repository `file:///tmp/bar`
Skipping git submodule `file:///tmp/foo`
real 0m0.029s
user 0m0.021s
sys 0m0.008s
/tmp/qux $
```
Fixes rust-lang#4247.
Signed-off-by: Jakub Sitnicki <jakub@cloudflare.com>
a05107a to
26031b9
Compare
Contributor
Author
|
v3:
|
Contributor
|
Thanks! @bors r+ |
Contributor
|
📌 Commit 26031b9 has been approved by |
Contributor
Contributor
|
☀️ Test successful - checks-actions |
bors
added a commit
to rust-lang-ci/rust
that referenced
this pull request
Jun 8, 2022
Update cargo 7 commits in 38472bc19f2f76e245eba54a6e97ee6821b3c1db..85e457e158db216a2938d51bc3b617a5a7fe6015 2022-05-31 02:03:24 +0000 to 2022-06-07 21:57:52 +0000 - Make -Z http-registry use index.crates.io when accessing crates-io (rust-lang/cargo#10725) - Respect submodule update=none strategy in .gitmodules (rust-lang/cargo#10717) - Expose rust-version through env var (rust-lang/cargo#10713) - add validation for string "true"/"false" in lto profile (rust-lang/cargo#10676) - Enhance documentation of testing (rust-lang/cargo#10726) - Clear disk space on CI. (rust-lang/cargo#10724) - Enforce to use tar v0.4.38 (rust-lang/cargo#10720)
13 tasks
max-heller
added a commit
to max-heller/mdbook-pandoc
that referenced
this pull request
Jan 18, 2025
This ensures that `cargo` doesn't try to fetch submodules during `cargo update` or checkout submodules during `cargo install --git`. See rust-lang/cargo#10717
max-heller
added a commit
to max-heller/mdbook-pandoc
that referenced
this pull request
Jan 18, 2025
This ensures that `cargo` doesn't try to fetch submodules during `cargo update` or checkout submodules during `cargo install --git`. See rust-lang/cargo#10717
max-heller
added a commit
to max-heller/mdbook-pandoc
that referenced
this pull request
Jan 18, 2025
This ensures that `cargo` doesn't try to fetch submodules during `cargo update` or checkout submodules during `cargo install --git`. See rust-lang/cargo#10717
max-heller
added a commit
to max-heller/mdbook-pandoc
that referenced
this pull request
Jan 18, 2025
Ensures `cargo install --git` doesn't checkout the submodules, which are only used in tests. See rust-lang/cargo#10717
richardscollin
added a commit
to richardscollin/c2rust
that referenced
this pull request
Mar 28, 2025
This prevents cargo from fetching examples submodules when the git repo is used as a dependency url. rust-lang/cargo#10717
kkysen
added a commit
to immunant/c2rust
that referenced
this pull request
Jan 27, 2026
…ncies don't clone them `cargo` always recursively clones git dependencies, even though c2rust git dependencies don't need any of the big submodules here used just for testing. Setting `update = none` is workaround (see <rust-lang/cargo#10717>). However, other users need to explicitly update submodules now.
kkysen
added a commit
to immunant/c2rust
that referenced
this pull request
Jan 27, 2026
…ncies don't clone them `cargo` always recursively clones git dependencies, even though c2rust git dependencies don't need any of the big submodules here used just for testing. Setting `update = none` is workaround (see <rust-lang/cargo#10717>). However, other users need to explicitly update submodules now. With this change, it takes ~6 s to resolve a `c2rust-bitfields` git dependency, vs. many minutes before with all of the large submodules.
kkysen
added a commit
to immunant/c2rust
that referenced
this pull request
Jan 27, 2026
…ncies don't clone them `cargo` always recursively clones git dependencies, even though c2rust git dependencies don't need any of the big submodules here used just for testing. Setting `update = none` is workaround (see <rust-lang/cargo#10717>). However, other users need to explicitly update submodules now. With this change, it takes ~6 s to resolve a `c2rust-bitfields` git dependency, vs. many minutes before with all of the large submodules.
kkysen
added a commit
to immunant/c2rust
that referenced
this pull request
Jan 27, 2026
…ncies don't clone them `cargo` always recursively clones git dependencies, even though c2rust git dependencies don't need any of the big submodules here used just for testing. Setting `update = none` is workaround (see <rust-lang/cargo#10717>). However, other users need to explicitly update submodules now. With this change, it takes ~6 s to resolve a `c2rust-bitfields` git dependency, vs. many minutes before with all of the large submodules.
kkysen
added a commit
to immunant/c2rust
that referenced
this pull request
Feb 2, 2026
…ncies don't clone them (#1574) * `c2rust`-side fix for the git dependency version of GaloisInc/Tractor-Crisp#46. `cargo` always recursively clones git dependencies, even though c2rust git dependencies don't need any of the big submodules here used just for testing. Setting `update = none` is workaround (see <rust-lang/cargo#10717>). However, other users need to explicitly update submodules now. With this change, it takes ~6 s to resolve a `c2rust-bitfields` git dependency, vs. many minutes before with all of the large submodules.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Git lets users define the default update/checkout strategy for a submodule
by setting the
submodule.<name>.updatekey in.gitmodulesfile.If the update strategy is
none, the submodule will be skipped duringupdate. It will not be fetched and checked out:
update=noneCargo, on the other hand, ignores the submodule update strategy set in
.gitmodulesproperties when updating dependencies. Such behavior canbe considered against the wish of the crate publisher.
Fix it by checking if a Git repository submodule should be updated when
cargo processes dependencies.
update=noneare skippedFixes #4247.