Fix .gitignore of Cargo.lock in a subdirectory.

This commit is contained in:
Eric Huss 2020-01-08 10:40:17 -08:00
parent 7059559d71
commit 3cedb8e33c
2 changed files with 34 additions and 14 deletions

View File

@ -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 {

View File

@ -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")
@ -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();
}