Skip to content

Commit

Permalink
Fix .gitignore of Cargo.lock in a subdirectory.
Browse files Browse the repository at this point in the history
  • Loading branch information
ehuss committed Jan 8, 2020
1 parent 7059559 commit 3cedb8e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 14 deletions.
4 changes: 3 additions & 1 deletion src/cargo/ops/cargo_package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,9 @@ fn check_repo_state(
if let Ok(status) = repo.status_file(relative) {
if status == git2::Status::CURRENT {
false
} else if relative.to_str().unwrap_or("") == "Cargo.lock" {
} else if relative.file_name().and_then(|s| s.to_str()).unwrap_or("")
== "Cargo.lock"
{
// It is OK to include this file even if it is ignored.
status != git2::Status::IGNORED
} else {
Expand Down
44 changes: 31 additions & 13 deletions tests/testsuite/publish_lockfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,24 +404,18 @@ 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| {
let p = git::new("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"
&pl_manifest(
"foo",
"0.0.1",
r#"
include = [
"src/main.rs"
]
"#,
"#,
),
)
.file("src/main.rs", "fn main() {}")
.file(".gitignore", "Cargo.lock")
Expand Down Expand Up @@ -453,3 +447,27 @@ src/main.rs
)
.run();
}

#[cargo_test]
fn ignore_lockfile_inner() {
// Ignore `Cargo.lock` if in .gitignore in a git subdirectory.
let p = git::new("foo", |p| {
p.no_manifest()
.file("bar/Cargo.toml", &pl_manifest("bar", "0.0.1", ""))
.file("bar/src/main.rs", "fn main() {}")
.file("bar/.gitignore", "Cargo.lock")
});
p.cargo("generate-lockfile").cwd("bar").run();
p.cargo("package -v --no-verify")
.cwd("bar")
.with_stderr(
"\
[PACKAGING] bar v0.0.1 ([..])
[ARCHIVING] Cargo.toml
[ARCHIVING] src/main.rs
[ARCHIVING] .cargo_vcs_info.json
[ARCHIVING] Cargo.lock
",
)
.run();
}

0 comments on commit 3cedb8e

Please sign in to comment.