Skip to content

Commit

Permalink
Allow gitignore of Cargo.lock with explicit include.
Browse files Browse the repository at this point in the history
  • Loading branch information
ehuss committed Sep 26, 2019
1 parent d5621be commit 36f01e6
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 36f01e6

Please sign in to comment.