Skip to content

Commit

Permalink
Auto merge of #7448 - ehuss:gitignore-lockfile, r=alexcrichton
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Sep 27, 2019
2 parents d5621be + 36f01e6 commit d096a86
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/cargo/ops/cargo_package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
55 changes: 55 additions & 0 deletions tests/testsuite/publish_lockfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

0 comments on commit d096a86

Please sign in to comment.