Skip to content

Commit 759c264

Browse files
committed
add test to run git2 on a gitoxide-fetched repository and vice-versa
We do that on both the crates-io clone as well as on the clone for a git dependency. The first `cargo` invocation is configured to use whatever wouldn't be the default, whereas the second one will use whatever is the default, effectively mixing the implementations. That way we should assure that users can switch back and forth between implementations without issues with their local state.
1 parent 6553e54 commit 759c264

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

src/cargo/core/features.rs

+7
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,9 @@ pub struct GitoxideFeatures {
790790
/// Checkout git dependencies using `gitoxide` (submodules are still handled by git2 ATM, and filters
791791
/// like linefeed conversions are unsupported).
792792
pub checkout: bool,
793+
/// A `gitoxide` feature which doesn't have any meaning except for forcing `always_test_gitoxide` builds
794+
/// to not actually enabled `gitoxide`.
795+
pub internal_use_git2: bool,
793796
}
794797

795798
impl GitoxideFeatures {
@@ -799,6 +802,7 @@ impl GitoxideFeatures {
799802
shallow_index: true,
800803
checkout: true,
801804
shallow_deps: true,
805+
internal_use_git2: false,
802806
}
803807
}
804808

@@ -810,6 +814,7 @@ impl GitoxideFeatures {
810814
shallow_index: false,
811815
checkout: true,
812816
shallow_deps: false,
817+
internal_use_git2: false,
813818
}
814819
}
815820
}
@@ -823,6 +828,7 @@ fn parse_gitoxide(
823828
shallow_index,
824829
checkout,
825830
shallow_deps,
831+
internal_use_git2,
826832
} = &mut out;
827833

828834
for e in it {
@@ -831,6 +837,7 @@ fn parse_gitoxide(
831837
"shallow_index" => *shallow_index = true,
832838
"shallow_deps" => *shallow_deps = true,
833839
"checkout" => *checkout = true,
840+
"internal_use_git2" => *internal_use_git2 = true,
834841
_ => {
835842
bail!("unstable 'gitoxide' only takes `fetch`, 'shallow_index', 'shallow_deps' and 'checkout' as valid inputs")
836843
}

tests/testsuite/git.rs

+44
Original file line numberDiff line numberDiff line change
@@ -1827,6 +1827,50 @@ fn fetch_downloads() {
18271827
p.cargo("fetch").with_stdout("").run();
18281828
}
18291829

1830+
#[cargo_test]
1831+
fn fetch_downloads_with_git2_first_then_with_gitoxide_and_vice_versa() {
1832+
let bar = git::new("bar", |project| {
1833+
project
1834+
.file("Cargo.toml", &basic_manifest("bar", "0.5.0"))
1835+
.file("src/lib.rs", "pub fn bar() -> i32 { 1 }")
1836+
});
1837+
let feature_configuration = if cfg!(always_test_gitoxide) {
1838+
// When we are always using `gitoxide` by default, create the registry with git2 as well as the download…
1839+
"-Zgitoxide=internal_use_git2"
1840+
} else {
1841+
// …otherwise create the registry and the git download with `gitoxide`.
1842+
"-Zgitoxide=fetch"
1843+
};
1844+
1845+
let p = project()
1846+
.file(
1847+
"Cargo.toml",
1848+
&format!(
1849+
r#"
1850+
[package]
1851+
name = "foo"
1852+
version = "0.5.0"
1853+
authors = []
1854+
[dependencies.bar]
1855+
git = '{}'
1856+
"#,
1857+
bar.url()
1858+
),
1859+
)
1860+
.file("src/main.rs", "fn main() {}")
1861+
.build();
1862+
p.cargo("fetch")
1863+
.arg(feature_configuration)
1864+
.masquerade_as_nightly_cargo(&["gitoxide must be available"])
1865+
.with_stderr(&format!(
1866+
"[UPDATING] git repository `{url}`",
1867+
url = bar.url()
1868+
))
1869+
.run();
1870+
1871+
p.cargo("fetch").with_stdout("").run();
1872+
}
1873+
18301874
#[cargo_test]
18311875
fn warnings_in_git_dep() {
18321876
let bar = git::new("bar", |project| {

0 commit comments

Comments
 (0)