Skip to content

Commit 565b914

Browse files
committed
test(git): trace every fetch backend
Make sure each backend is actually used
1 parent fb8bfec commit 565b914

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

src/cargo/sources/git/utils.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1030,6 +1030,7 @@ pub fn fetch(
10301030
}
10311031
}
10321032

1033+
debug!("doing a fetch for {remote_url}");
10331034
let result = if let Some(true) = gctx.net_config()?.git_fetch_with_cli {
10341035
fetch_with_cli(repo, remote_url, &refspecs, tags, gctx)
10351036
} else if gctx.cli_unstable().gitoxide.map_or(false, |git| git.fetch) {
@@ -1077,6 +1078,8 @@ fn fetch_with_cli(
10771078
tags: bool,
10781079
gctx: &GlobalContext,
10791080
) -> CargoResult<()> {
1081+
debug!(target: "git-fetch", backend = "git-cli");
1082+
10801083
let mut cmd = ProcessBuilder::new("git");
10811084
cmd.arg("fetch");
10821085
if tags {
@@ -1126,6 +1129,8 @@ fn fetch_with_gitoxide(
11261129
shallow: gix::remote::fetch::Shallow,
11271130
gctx: &GlobalContext,
11281131
) -> CargoResult<()> {
1132+
debug!(target: "git-fetch", backend = "gitoxide");
1133+
11291134
let git2_repo = repo;
11301135
let config_overrides = cargo_config_to_gitoxide_overrides(gctx)?;
11311136
let repo_reinitialized = AtomicBool::default();
@@ -1234,7 +1239,8 @@ fn fetch_with_libgit2(
12341239
shallow: gix::remote::fetch::Shallow,
12351240
gctx: &GlobalContext,
12361241
) -> CargoResult<()> {
1237-
debug!("doing a fetch for {remote_url}");
1242+
debug!(target: "git-fetch", backend = "libgit2");
1243+
12381244
let git_config = git2::Config::open_default()?;
12391245
with_fetch_options(&git_config, remote_url, gctx, &mut |mut opts| {
12401246
if tags {

tests/testsuite/git_shallow.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ impl Backend {
1616
Backend::Gitoxide => "-Zgitoxide=fetch",
1717
}
1818
}
19+
20+
fn to_trace_log(&self) -> &str {
21+
match self {
22+
Backend::Git2 => r#"[..]git-fetch: backend="libgit2"[..]"#,
23+
Backend::Gitoxide => r#"[..]git-fetch: backend="gitoxide"[..]"#,
24+
Backend::GitCli => r#"[..]git-fetch: backend="git-cli"[..]"#,
25+
}
26+
}
1927
}
2028

2129
enum RepoMode {
@@ -120,6 +128,8 @@ fn fetch_dep_two_revs(backend: Backend) {
120128
.arg_line(RepoMode::Shallow.to_deps_arg())
121129
.env("__CARGO_USE_GITOXIDE_INSTEAD_OF_GIT2", "0") // respect `backend`
122130
.masquerade_as_nightly_cargo(&["gitoxide=fetch", "git=shallow-deps"])
131+
.env("CARGO_LOG", "git-fetch=debug")
132+
.with_stderr_contains(backend.to_trace_log())
123133
.run();
124134
}
125135

@@ -167,6 +177,8 @@ fn fetch_shallow_dep_branch_and_rev(backend: Backend) -> anyhow::Result<()> {
167177
.arg_line(RepoMode::Shallow.to_deps_arg())
168178
.env("__CARGO_USE_GITOXIDE_INSTEAD_OF_GIT2", "0")
169179
.masquerade_as_nightly_cargo(&["gitoxide=fetch", "git=shallow-deps"])
180+
.env("CARGO_LOG", "git-fetch=debug")
181+
.with_stderr_contains(backend.to_trace_log())
170182
.run();
171183

172184
let db_paths = glob::glob(paths::home().join(".cargo/git/db/bar-*").to_str().unwrap())?
@@ -229,6 +241,8 @@ fn fetch_shallow_dep_branch_to_rev(backend: Backend) -> anyhow::Result<()> {
229241
.arg_line(RepoMode::Shallow.to_deps_arg())
230242
.env("__CARGO_USE_GITOXIDE_INSTEAD_OF_GIT2", "0")
231243
.masquerade_as_nightly_cargo(&["gitoxide=fetch", "git=shallow-deps"])
244+
.env("CARGO_LOG", "git-fetch=debug")
245+
.with_stderr_contains(backend.to_trace_log())
232246
.run();
233247

234248
let db_clone = gix::open_opts(
@@ -261,6 +275,8 @@ fn fetch_shallow_dep_branch_to_rev(backend: Backend) -> anyhow::Result<()> {
261275
.arg_line(RepoMode::Shallow.to_deps_arg())
262276
.env("__CARGO_USE_GITOXIDE_INSTEAD_OF_GIT2", "0")
263277
.masquerade_as_nightly_cargo(&["gitoxide=fetch", "git=shallow-deps"])
278+
.env("CARGO_LOG", "git-fetch=debug")
279+
.with_stderr_contains(backend.to_trace_log())
264280
.run();
265281

266282
assert!(
@@ -300,6 +316,8 @@ fn fetch_shallow_index_then_fetch_complete(
300316
.arg("-Zgit=shallow-index")
301317
.env("__CARGO_USE_GITOXIDE_INSTEAD_OF_GIT2", "0")
302318
.masquerade_as_nightly_cargo(&["gitoxide=fetch", "git=shallow-index"])
319+
.env("CARGO_LOG", "git-fetch=debug")
320+
.with_stderr_contains(backend_1st.to_trace_log())
303321
.run();
304322

305323
let shallow_repo = gix::open_opts(find_index(), gix::open::Options::isolated())?;
@@ -319,6 +337,8 @@ fn fetch_shallow_index_then_fetch_complete(
319337
.arg_line(backend_2nd.to_arg())
320338
.env("__CARGO_USE_GITOXIDE_INSTEAD_OF_GIT2", "0")
321339
.masquerade_as_nightly_cargo(&["gitoxide=fetch"])
340+
.env("CARGO_LOG", "git-fetch=debug")
341+
.with_stderr_contains(backend_2nd.to_trace_log())
322342
.run();
323343

324344
let repo = gix::open_opts(
@@ -395,6 +415,8 @@ fn fetch_shallow_dep_then_fetch_complete(
395415
.arg_line(RepoMode::Shallow.to_deps_arg())
396416
.env("__CARGO_USE_GITOXIDE_INSTEAD_OF_GIT2", "0")
397417
.masquerade_as_nightly_cargo(&["gitoxide=fetch", "git=shallow-deps"])
418+
.env("CARGO_LOG", "git-fetch=debug")
419+
.with_stderr_contains(backend_1st.to_trace_log())
398420
.run();
399421

400422
let db_clone = gix::open_opts(
@@ -440,6 +462,8 @@ fn fetch_shallow_dep_then_fetch_complete(
440462
.arg_line(backend_2nd.to_arg())
441463
.env("__CARGO_USE_GITOXIDE_INSTEAD_OF_GIT2", "0")
442464
.masquerade_as_nightly_cargo(&["gitoxide=fetch"])
465+
.env("CARGO_LOG", "git-fetch=debug")
466+
.with_stderr_contains(backend_2nd.to_trace_log())
443467
.run();
444468

445469
let db_clone = gix::open_opts(
@@ -515,6 +539,8 @@ fn fetch_shallow_index_then_preserve_shallow(backend: Backend) -> anyhow::Result
515539
.arg("-Zgit=shallow-index")
516540
.env("__CARGO_USE_GITOXIDE_INSTEAD_OF_GIT2", "0")
517541
.masquerade_as_nightly_cargo(&["gitoxide=fetch", "git=shallow-index"])
542+
.env("CARGO_LOG", "git-fetch=debug")
543+
.with_stderr_contains(backend.to_trace_log())
518544
.run();
519545

520546
let repo = gix::open_opts(find_index(), gix::open::Options::isolated())?;
@@ -534,6 +560,8 @@ fn fetch_shallow_index_then_preserve_shallow(backend: Backend) -> anyhow::Result
534560
.arg("-Zgit=shallow-index") // NOTE: the flag needs to be consistent or else a different index is created
535561
.env("__CARGO_USE_GITOXIDE_INSTEAD_OF_GIT2", "0")
536562
.masquerade_as_nightly_cargo(&["gitoxide=fetch", "git=shallow-index"])
563+
.env("CARGO_LOG", "git-fetch=debug")
564+
.with_stderr_contains(backend.to_trace_log())
537565
.run();
538566

539567
assert_eq!(
@@ -553,6 +581,8 @@ fn fetch_shallow_index_then_preserve_shallow(backend: Backend) -> anyhow::Result
553581
.arg("-Zgit=shallow-index")
554582
.env("__CARGO_USE_GITOXIDE_INSTEAD_OF_GIT2", "0")
555583
.masquerade_as_nightly_cargo(&["gitoxide=fetch", "git=shallow-index"])
584+
.env("CARGO_LOG", "git-fetch=debug")
585+
.with_stderr_contains(backend.to_trace_log())
556586
.run();
557587

558588
assert_eq!(
@@ -594,6 +624,8 @@ fn fetch_complete_index_then_shallow(backend: Backend) -> anyhow::Result<()> {
594624
.arg_line(backend.to_arg())
595625
.env("__CARGO_USE_GITOXIDE_INSTEAD_OF_GIT2", "0")
596626
.masquerade_as_nightly_cargo(&["gitoxide=fetch"])
627+
.env("CARGO_LOG", "git-fetch=debug")
628+
.with_stderr_contains(backend.to_trace_log())
597629
.run();
598630

599631
let repo = gix::open_opts(find_index(), gix::open::Options::isolated())?;
@@ -613,6 +645,8 @@ fn fetch_complete_index_then_shallow(backend: Backend) -> anyhow::Result<()> {
613645
.arg("-Zgit=shallow-index")
614646
.env("__CARGO_USE_GITOXIDE_INSTEAD_OF_GIT2", "0")
615647
.masquerade_as_nightly_cargo(&["gitoxide=fetch", "git=shallow-index"])
648+
.env("CARGO_LOG", "git-fetch=debug")
649+
.with_stderr_contains(backend.to_trace_log())
616650
.run();
617651

618652
let shallow_repo = gix::open_opts(
@@ -637,6 +671,8 @@ fn fetch_complete_index_then_shallow(backend: Backend) -> anyhow::Result<()> {
637671
.arg("-Zgit=shallow-index")
638672
.env("__CARGO_USE_GITOXIDE_INSTEAD_OF_GIT2", "0")
639673
.masquerade_as_nightly_cargo(&["gitoxide=fetch", "git=shallow-index"])
674+
.env("CARGO_LOG", "git-fetch=debug")
675+
.with_stderr_contains(backend.to_trace_log())
640676
.run();
641677

642678
assert_eq!(
@@ -654,6 +690,8 @@ fn fetch_complete_index_then_shallow(backend: Backend) -> anyhow::Result<()> {
654690
.arg_line(backend.to_arg())
655691
.env("__CARGO_USE_GITOXIDE_INSTEAD_OF_GIT2", "0")
656692
.masquerade_as_nightly_cargo(&["gitoxide=fetch"])
693+
.env("CARGO_LOG", "git-fetch=debug")
694+
.with_stderr_contains(backend.to_trace_log())
657695
.run();
658696

659697
assert_eq!(
@@ -694,6 +732,8 @@ fn fetch_shallow_index_then_abort_and_update(backend: Backend) -> anyhow::Result
694732
.arg("-Zgit=shallow-index")
695733
.env("__CARGO_USE_GITOXIDE_INSTEAD_OF_GIT2", "0")
696734
.masquerade_as_nightly_cargo(&["gitoxide=fetch", "git=shallow-index"])
735+
.env("CARGO_LOG", "git-fetch=debug")
736+
.with_stderr_contains(backend.to_trace_log())
697737
.run();
698738

699739
let repo = gix::open_opts(find_index(), gix::open::Options::isolated())?;
@@ -718,6 +758,8 @@ fn fetch_shallow_index_then_abort_and_update(backend: Backend) -> anyhow::Result
718758
.arg("-Zgit=shallow-index")
719759
.env("__CARGO_USE_GITOXIDE_INSTEAD_OF_GIT2", "0")
720760
.masquerade_as_nightly_cargo(&["gitoxide=fetch", "git=shallow-index"])
761+
.env("CARGO_LOG", "git-fetch=debug")
762+
.with_stderr_contains(backend.to_trace_log())
721763
.run();
722764

723765
assert!(!shallow_lock.is_file(), "the repository was re-initialized");

0 commit comments

Comments
 (0)