Skip to content

Commit

Permalink
add test to run git2 on a gitoxide-fetched repository and vice-versa
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Byron committed Dec 26, 2022
1 parent 6553e54 commit 759c264
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/cargo/core/features.rs
Expand Up @@ -790,6 +790,9 @@ pub struct GitoxideFeatures {
/// Checkout git dependencies using `gitoxide` (submodules are still handled by git2 ATM, and filters
/// like linefeed conversions are unsupported).
pub checkout: bool,
/// A `gitoxide` feature which doesn't have any meaning except for forcing `always_test_gitoxide` builds
/// to not actually enabled `gitoxide`.
pub internal_use_git2: bool,
}

impl GitoxideFeatures {
Expand All @@ -799,6 +802,7 @@ impl GitoxideFeatures {
shallow_index: true,
checkout: true,
shallow_deps: true,
internal_use_git2: false,
}
}

Expand All @@ -810,6 +814,7 @@ impl GitoxideFeatures {
shallow_index: false,
checkout: true,
shallow_deps: false,
internal_use_git2: false,
}
}
}
Expand All @@ -823,6 +828,7 @@ fn parse_gitoxide(
shallow_index,
checkout,
shallow_deps,
internal_use_git2,
} = &mut out;

for e in it {
Expand All @@ -831,6 +837,7 @@ fn parse_gitoxide(
"shallow_index" => *shallow_index = true,
"shallow_deps" => *shallow_deps = true,
"checkout" => *checkout = true,
"internal_use_git2" => *internal_use_git2 = true,
_ => {
bail!("unstable 'gitoxide' only takes `fetch`, 'shallow_index', 'shallow_deps' and 'checkout' as valid inputs")
}
Expand Down
44 changes: 44 additions & 0 deletions tests/testsuite/git.rs
Expand Up @@ -1827,6 +1827,50 @@ fn fetch_downloads() {
p.cargo("fetch").with_stdout("").run();
}

#[cargo_test]
fn fetch_downloads_with_git2_first_then_with_gitoxide_and_vice_versa() {
let bar = git::new("bar", |project| {
project
.file("Cargo.toml", &basic_manifest("bar", "0.5.0"))
.file("src/lib.rs", "pub fn bar() -> i32 { 1 }")
});
let feature_configuration = if cfg!(always_test_gitoxide) {
// When we are always using `gitoxide` by default, create the registry with git2 as well as the download…
"-Zgitoxide=internal_use_git2"
} else {
// …otherwise create the registry and the git download with `gitoxide`.
"-Zgitoxide=fetch"
};

let p = project()
.file(
"Cargo.toml",
&format!(
r#"
[package]
name = "foo"
version = "0.5.0"
authors = []
[dependencies.bar]
git = '{}'
"#,
bar.url()
),
)
.file("src/main.rs", "fn main() {}")
.build();
p.cargo("fetch")
.arg(feature_configuration)
.masquerade_as_nightly_cargo(&["gitoxide must be available"])
.with_stderr(&format!(
"[UPDATING] git repository `{url}`",
url = bar.url()
))
.run();

p.cargo("fetch").with_stdout("").run();
}

#[cargo_test]
fn warnings_in_git_dep() {
let bar = git::new("bar", |project| {
Expand Down

0 comments on commit 759c264

Please sign in to comment.