Skip to content

Commit

Permalink
Add tests for using worktrees and sparse checkouts
Browse files Browse the repository at this point in the history
  • Loading branch information
LuuuXXX committed Mar 10, 2024
1 parent 6b27055 commit 8954c6d
Showing 1 changed file with 90 additions and 1 deletion.
91 changes: 90 additions & 1 deletion tests/testsuite/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ use std::thread;
use cargo_test_support::git::cargo_uses_gitoxide;
use cargo_test_support::paths::{self, CargoPathExt};
use cargo_test_support::registry::Package;
use cargo_test_support::{basic_lib_manifest, basic_manifest, git, main_file, path2url, project};
use cargo_test_support::{
basic_lib_manifest, basic_manifest, git, git_process, main_file, path2url, project,
};
use cargo_test_support::{sleep_ms, t, Project};

#[cargo_test]
Expand Down Expand Up @@ -3760,3 +3762,90 @@ fn different_user_relative_submodules() {

assert!(project.bin("foo").is_file());
}

#[cargo_test(requires_git)]
fn cargo_package_with_new_worktree() {
let project = project().build();
let git_project = git::new("foo", |project| {
project.file("src/lib.rs", "").file("README.md", "").file(
"Cargo.toml",
&format!(
r#"[package]
name = "foo"
version = "0.1.0"
edition = "2015"
authors = []
license = "MIR OR Apache-2.0"
description = "A test!"
homepage = "https://example.org"
documentation = ""
repository = "https://example.org"
readme = "./README.md"
"#,
),
)
});

let repo = git2::Repository::open(&git_project.root()).unwrap();
let repo_root = repo.workdir().unwrap().parent().unwrap();
let opts = git2::WorktreeAddOptions::new();
let wt = repo
.worktree("bar", &repo_root.join("bar"), Some(&opts))
.unwrap();

project
.cargo("package --list")
.cwd(wt.path())
.with_stdout(
"\
.cargo_vcs_info.json
Cargo.toml
Cargo.toml.orig
README.md
src/lib.rs
",
)
.run();
}

#[cargo_test(requires_git)]
fn cargo_check_with_sparse_checkouts() {
let git_project = git::new("foo", |project| {
project.file("src/lib.rs", "").file(
"Cargo.toml",
&format!(
r#"
[package]
name = "foo"
version = "0.5.0"
edition = "2015"
authors = []
"#,
),
)
});

let path = git_project.root();
git_process("sparse-checkout init")
.cwd(&path)
.exec()
.unwrap();
let output = git_process("config core.sparseCheckout")
.cwd(&path)
.exec_with_output()
.unwrap();
assert!(output.stdout.starts_with(b"true"));
git_process("sparse-checkout add src")
.cwd(&path)
.exec()
.unwrap();
git_project
.cargo("check")
.with_stderr(&format!(
"[CHECKING] foo v0.5.0 ([CWD])\n\
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) \
in [..]\n"
))
.run();
}
\

0 comments on commit 8954c6d

Please sign in to comment.