diff --git a/tests/testsuite/lockfile_compat.rs b/tests/testsuite/lockfile_compat.rs index 0c8dfd4d35f..a22ce04f4e7 100644 --- a/tests/testsuite/lockfile_compat.rs +++ b/tests/testsuite/lockfile_compat.rs @@ -1058,3 +1058,91 @@ fn v3_and_git_url_encoded_tag() { fn v3_and_git_url_encoded_rev() { v3_and_git_url_encoded("rev", create_tag); } + +fn v4_and_git_url_encoded(ref_kind: &str, f: impl FnOnce(&git2::Repository, &str, git2::Oid)) { + let (git_project, repo) = git::new_repo("dep1", |project| { + project + .file("Cargo.toml", &basic_lib_manifest("dep1")) + .file("src/lib.rs", "") + }); + let url = git_project.url(); + let head_id = repo.head().unwrap().target().unwrap(); + // Ref name with special characters + let git_ref = "a-_+#$)"; + let encoded_ref = "a-_%2B%23%24%29"; + f(&repo, git_ref, head_id); + + let lockfile = format!( + r#"# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "dep1" +version = "0.5.0" +source = "git+{url}?{ref_kind}={encoded_ref}#{head_id}" + +[[package]] +name = "foo" +version = "0.0.1" +dependencies = [ + "dep1", +] +"#, + ); + + let p = project() + .file( + "Cargo.toml", + &format!( + r#" + [package] + name = "foo" + version = "0.0.1" + + [dependencies] + dep1 = {{ git = '{url}', {ref_kind} = '{git_ref}' }} + "#, + ), + ) + .file("src/lib.rs", "") + .file("Cargo.lock", "version = 4") + .build(); + + p.cargo("check -Znext-lockfile-bump") + .masquerade_as_nightly_cargo(&["-Znext-lockfile-bump"]) + .with_stderr(format!( + "\ +[UPDATING] git repository `{url}` +[CHECKING] dep1 v0.5.0 ({url}?{ref_kind}={git_ref}#[..]) +[CHECKING] foo v0.0.1 ([CWD]) +[FINISHED] dev [..] +" + )) + .run(); + + let lock = p.read_lockfile(); + assert_match_exact(&lockfile, &lock); + + // Unlike v3_and_git_url_encoded, v4 encodes URL parameters so no git + // repository re-clone happen. + p.cargo("check -Znext-lockfile-bump") + .masquerade_as_nightly_cargo(&["-Znext-lockfile-bump"]) + .with_stderr("[FINISHED] dev [..]") + .run(); +} + +#[cargo_test] +fn v4_and_git_url_encoded_branch() { + v4_and_git_url_encoded("branch", create_branch); +} + +#[cargo_test] +fn v4_and_git_url_encoded_tag() { + v4_and_git_url_encoded("tag", create_tag); +} + +#[cargo_test] +fn v4_and_git_url_encoded_rev() { + v4_and_git_url_encoded("rev", create_tag) +}