-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support shallow fetch through net.git-fetch-with-cli
#15315
base: master
Are you sure you want to change the base?
Conversation
@@ -1084,6 +1086,28 @@ fn fetch_with_cli( | |||
} else { | |||
cmd.arg("--no-tags"); | |||
} | |||
|
|||
match shallow { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we are using variants other than NoChange
/DepthAtRemote
. We might just leave then unimplmented!(…)
.
cargo/src/cargo/sources/git/mod.rs
Lines 35 to 57 in 611b7c4
pub(crate) fn to_shallow_setting( | |
&self, | |
repo_is_shallow: bool, | |
gctx: &GlobalContext, | |
) -> gix::remote::fetch::Shallow { | |
let has_feature = |cb: &dyn Fn(GitFeatures) -> bool| { | |
gctx.cli_unstable() | |
.git | |
.map_or(false, |features| cb(features)) | |
}; | |
// maintain shallow-ness and keep downloading single commits, or see if we can do shallow clones | |
if !repo_is_shallow { | |
match self { | |
RemoteKind::GitDependency if has_feature(&|features| features.shallow_deps) => { | |
} | |
RemoteKind::Registry if has_feature(&|features| features.shallow_index) => {} | |
_ => return gix::remote::fetch::Shallow::NoChange, | |
} | |
}; | |
gix::remote::fetch::Shallow::DepthAtRemote(1.try_into().expect("non-zero")) | |
} |
tests/testsuite/git_shallow.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For test, adding one simple backend test should be good.
cargo/tests/testsuite/git_shallow.rs
Lines 40 to 43 in 3e96f1a
#[cargo_test] | |
fn git2_fetch_complete_dep_two_revs() { | |
fetch_dep_two_revs(Backend::Git2, RepoMode::Complete) | |
} |
I would also encourage to try if we can have cover more gitoxide tests for git CLI with the same switch backend trick.
Also, I'd like to see a test like:
- First using gix to fetch
- Compiles.
- Add a new commit
- Use git cli to fetch
- Can still compile.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, I tried that with:
It does not work.
test git_shallow::git_cli_fetch_complete_dep_two_revs ... FAILED
successes:
successes:
failures:
---- git_shallow::git_cli_fetch_complete_dep_two_revs stdout ----
running `C:\projects\cargo\target\debug\cargo.exe check -v -Zgit=shallow-deps`
thread 'git_shallow::git_cli_fetch_complete_dep_two_revs' panicked at tests\testsuite\git_shallow.rs:135:10:
test failed running `C:\projects\cargo\target\debug\cargo.exe check -v -Zgit=shallow-deps`
error: process exited with code 101 (expected 0)
--- stdout
--- stderr
warning: no edition set: defaulting to the 2015 edition while the latest is 2024
Updating git repository `file:///C:/projects/cargo/target/tmp/cit/t0/meta-dep`
warning: spurious network error (3 tries remaining): shallow fetch is not supported by the local transport; class=Net (12)
warning: spurious network error (2 tries remaining): shallow fetch is not supported by the local transport; class=Net (12)
warning: spurious network error (1 tries remaining): shallow fetch is not supported by the local transport; class=Net (12)
error: failed to get `bar` as a dependency of package `foo v0.0.0 (C:\projects\cargo\target\tmp\cit\t0\foo)`
Caused by:
failed to load source for dependency `bar`
Caused by:
Unable to update file:///C:/projects/cargo/target/tmp/cit/t0/meta-dep?rev=a3e80bc72d40dc21a921742d9f808e7be2b3302f
Caused by:
failed to clone into: C:\projects\cargo\target\tmp\cit\t0\home\.cargo\git\db\meta-dep-356a1674513a4a27-shallow
Caused by:
network failure seems to have happened
if a proxy or similar is necessary `net.git-fetch-with-cli` may help here
https://doc.rust-lang.org/cargo/reference/config.html#netgit-fetch-with-cli
Caused by:
shallow fetch is not supported by the local transport; class=Net (12)
stack backtrace:
0: std::panicking::begin_panic_handler
at /rustc/4d91de4e48198da2e33413efdcd9cd2cc0c46688/library\std\src\panicking.rs:692
1: core::panicking::panic_fmt
at /rustc/4d91de4e48198da2e33413efdcd9cd2cc0c46688/library\core\src\panicking.rs:75
2: cargo_test_support::panic_error::pe
at .\crates\cargo-test-support\src\lib.rs:99
3: cargo_test_support::panic_error<anyhow::Error>
at .\crates\cargo-test-support\src\lib.rs:91
4: cargo_test_support::Execs::run
at .\crates\cargo-test-support\src\lib.rs:1061
5: testsuite::git_shallow::fetch_dep_two_revs
at .\tests\testsuite\git_shallow.rs:130
6: testsuite::git_shallow::git_cli_fetch_complete_dep_two_revs
at .\tests\testsuite\git_shallow.rs:49
7: testsuite::git_shallow::git_cli_fetch_complete_dep_two_revs::closure$0
at .\tests\testsuite\git_shallow.rs:48
8: core::ops::function::FnOnce::call_once<testsuite::git_shallow::git_cli_fetch_complete_dep_two_revs::closure_env$0,tuple$<> >
at C:\Users\~~~~~~\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\ops\function.rs:250
9: core::ops::function::FnOnce::call_once
at /rustc/4d91de4e48198da2e33413efdcd9cd2cc0c46688/library\core\src\ops\function.rs:250
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
Should I set the netgit-fetch-with-cli
parameter somewhere as well. I'm not sure how the tests work. Is there a guide or something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See the https://doc.crates.io/contrib/tests/index.html and cargo-test-support doc.
You can read how other test works (not limited to git-related tests).
You can also check how switching backend works in git tests. --config
override should be able to help set the net.git-fetch-with-cli option.
What does this PR try to resolve?
Fixes #14956
How should we test and review this PR?
Additional information