Skip to content

Commit ec61016

Browse files
weihangloepage
andcommitted
test(git): extract setting -Zgit=shallow-index to a method
Co-authored-by: Ed Page <[email protected]>
1 parent 8120df7 commit ec61016

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

tests/testsuite/git_shallow.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ impl RepoMode {
4040
RepoMode::Shallow => "-Zgit=shallow-deps",
4141
}
4242
}
43+
44+
fn to_index_arg(&self) -> &'static str {
45+
match self {
46+
RepoMode::Complete => "",
47+
RepoMode::Shallow => "-Zgit=shallow-index",
48+
}
49+
}
4350
}
4451

4552
#[cargo_test]
@@ -335,7 +342,7 @@ fn fetch_shallow_index_then_fetch_complete(
335342
.build();
336343
p.cargo("fetch")
337344
.arg_line(backend_1st.to_arg())
338-
.arg("-Zgit=shallow-index")
345+
.arg(RepoMode::Shallow.to_index_arg())
339346
.env("__CARGO_USE_GITOXIDE_INSTEAD_OF_GIT2", "0")
340347
.masquerade_as_nightly_cargo(&["gitoxide=fetch", "git=shallow-index"])
341348
.env("CARGO_LOG", "git-fetch=debug")
@@ -583,7 +590,7 @@ fn fetch_shallow_index_then_preserve_shallow(backend: Backend) -> anyhow::Result
583590
.build();
584591
p.cargo("fetch")
585592
.arg_line(backend.to_arg())
586-
.arg("-Zgit=shallow-index")
593+
.arg(RepoMode::Shallow.to_index_arg())
587594
.env("__CARGO_USE_GITOXIDE_INSTEAD_OF_GIT2", "0")
588595
.masquerade_as_nightly_cargo(&["gitoxide=fetch", "git=shallow-index"])
589596
.env("CARGO_LOG", "git-fetch=debug")
@@ -604,7 +611,7 @@ fn fetch_shallow_index_then_preserve_shallow(backend: Backend) -> anyhow::Result
604611
Package::new("bar", "1.1.0").publish();
605612
p.cargo("update")
606613
.arg_line(backend.to_arg())
607-
.arg("-Zgit=shallow-index") // NOTE: the flag needs to be consistent or else a different index is created
614+
.arg(RepoMode::Shallow.to_index_arg()) // NOTE: the flag needs to be consistent or else a different index is created
608615
.env("__CARGO_USE_GITOXIDE_INSTEAD_OF_GIT2", "0")
609616
.masquerade_as_nightly_cargo(&["gitoxide=fetch", "git=shallow-index"])
610617
.env("CARGO_LOG", "git-fetch=debug")
@@ -625,7 +632,7 @@ fn fetch_shallow_index_then_preserve_shallow(backend: Backend) -> anyhow::Result
625632
Package::new("bar", "1.3.0").publish();
626633
p.cargo("update")
627634
.arg_line(backend.to_arg())
628-
.arg("-Zgit=shallow-index")
635+
.arg(RepoMode::Shallow.to_index_arg())
629636
.env("__CARGO_USE_GITOXIDE_INSTEAD_OF_GIT2", "0")
630637
.masquerade_as_nightly_cargo(&["gitoxide=fetch", "git=shallow-index"])
631638
.env("CARGO_LOG", "git-fetch=debug")
@@ -694,7 +701,7 @@ fn fetch_complete_index_then_shallow(backend: Backend) -> anyhow::Result<()> {
694701
Package::new("bar", "1.1.0").publish();
695702
p.cargo("update")
696703
.arg_line(backend.to_arg())
697-
.arg("-Zgit=shallow-index")
704+
.arg(RepoMode::Shallow.to_index_arg())
698705
.env("__CARGO_USE_GITOXIDE_INSTEAD_OF_GIT2", "0")
699706
.masquerade_as_nightly_cargo(&["gitoxide=fetch", "git=shallow-index"])
700707
.env("CARGO_LOG", "git-fetch=debug")
@@ -720,7 +727,7 @@ fn fetch_complete_index_then_shallow(backend: Backend) -> anyhow::Result<()> {
720727
Package::new("bar", "1.3.0").publish();
721728
p.cargo("update")
722729
.arg_line(backend.to_arg())
723-
.arg("-Zgit=shallow-index")
730+
.arg(RepoMode::Shallow.to_index_arg())
724731
.env("__CARGO_USE_GITOXIDE_INSTEAD_OF_GIT2", "0")
725732
.masquerade_as_nightly_cargo(&["gitoxide=fetch", "git=shallow-index"])
726733
.env("CARGO_LOG", "git-fetch=debug")
@@ -800,7 +807,7 @@ fn fetch_shallow_index_then_abort_and_update(backend: Backend) -> anyhow::Result
800807
.build();
801808
p.cargo("fetch")
802809
.arg_line(backend.to_arg())
803-
.arg("-Zgit=shallow-index")
810+
.arg(RepoMode::Shallow.to_index_arg())
804811
.env("__CARGO_USE_GITOXIDE_INSTEAD_OF_GIT2", "0")
805812
.masquerade_as_nightly_cargo(&["gitoxide=fetch", "git=shallow-index"])
806813
.env("CARGO_LOG", "git-fetch=debug")
@@ -826,7 +833,7 @@ fn fetch_shallow_index_then_abort_and_update(backend: Backend) -> anyhow::Result
826833
Package::new("bar", "1.1.0").publish();
827834
p.cargo("update")
828835
.arg_line(backend.to_arg())
829-
.arg("-Zgit=shallow-index")
836+
.arg(RepoMode::Shallow.to_index_arg())
830837
.env("__CARGO_USE_GITOXIDE_INSTEAD_OF_GIT2", "0")
831838
.masquerade_as_nightly_cargo(&["gitoxide=fetch", "git=shallow-index"])
832839
.env("CARGO_LOG", "git-fetch=debug")

0 commit comments

Comments
 (0)