mirror of
https://github.com/rust-lang/cargo
synced 2024-10-02 14:04:23 +00:00
Auto merge of #7448 - ehuss:gitignore-lockfile, r=alexcrichton
Allow gitignore of Cargo.lock with explicit `include`. If a package has an `include` list, but `Cargo.lock` is in `.gitignore`, then Cargo would complain that `Cargo.lock` is "dirty". This changes it so that ignored `Cargo.lock` is allowed, even though it is still packaged. This is under the presumption that `Cargo.lock` is machine generated, so it is not critical. This was also an unexpected regression. If you don't have an `include` list, then there is no complaint about `Cargo.lock` being dirty because Cargo uses git to deduce the file list, and `Cargo.lock` would be skipped for the dirty check (but still included in the package). Closes #7319
This commit is contained in:
commit
d096a86b22
|
@ -290,7 +290,16 @@ fn check_repo_state(
|
|||
.filter(|file| {
|
||||
let relative = file.strip_prefix(workdir).unwrap();
|
||||
if let Ok(status) = repo.status_file(relative) {
|
||||
status != git2::Status::CURRENT
|
||||
if status == git2::Status::CURRENT {
|
||||
false
|
||||
} else {
|
||||
if relative.to_str().unwrap_or("") == "Cargo.lock" {
|
||||
// It is OK to include this file even if it is ignored.
|
||||
status != git2::Status::IGNORED
|
||||
} else {
|
||||
true
|
||||
}
|
||||
}
|
||||
} else {
|
||||
submodule_dirty(file)
|
||||
}
|
||||
|
|
|
@ -396,3 +396,58 @@ dependencies = [
|
|||
)
|
||||
.run();
|
||||
}
|
||||
|
||||
#[cargo_test]
|
||||
fn ignore_lockfile() {
|
||||
// With an explicit `include` list, but Cargo.lock in .gitignore, don't
|
||||
// complain about `Cargo.lock` being ignored. Note that it is still
|
||||
// included in the packaged regardless.
|
||||
let (p, _r) = git::new_repo("foo", |p| {
|
||||
p.file(
|
||||
"Cargo.toml",
|
||||
r#"
|
||||
[package]
|
||||
name = "foo"
|
||||
version = "0.0.1"
|
||||
authors = []
|
||||
license = "MIT"
|
||||
description = "foo"
|
||||
documentation = "foo"
|
||||
homepage = "foo"
|
||||
repository = "foo"
|
||||
|
||||
include = [
|
||||
"src/main.rs"
|
||||
]
|
||||
"#,
|
||||
)
|
||||
.file("src/main.rs", "fn main() {}")
|
||||
.file(".gitignore", "Cargo.lock")
|
||||
});
|
||||
p.cargo("package -l")
|
||||
.with_stdout(
|
||||
"\
|
||||
.cargo_vcs_info.json
|
||||
Cargo.lock
|
||||
Cargo.toml
|
||||
src/main.rs
|
||||
",
|
||||
)
|
||||
.run();
|
||||
p.cargo("generate-lockfile").run();
|
||||
p.cargo("package -v")
|
||||
.with_stderr(
|
||||
"\
|
||||
[PACKAGING] foo v0.0.1 ([..])
|
||||
[ARCHIVING] Cargo.toml
|
||||
[ARCHIVING] src/main.rs
|
||||
[ARCHIVING] .cargo_vcs_info.json
|
||||
[ARCHIVING] Cargo.lock
|
||||
[VERIFYING] foo v0.0.1 ([..])
|
||||
[COMPILING] foo v0.0.1 ([..])
|
||||
[RUNNING] `rustc --crate-name foo src/main.rs [..]
|
||||
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
||||
",
|
||||
)
|
||||
.run();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue