mirror of
https://github.com/rust-lang/cargo.git
synced 2025-10-01 11:30:39 +00:00
Fix .gitignore of Cargo.lock in a subdirectory.
This commit is contained in:
parent
7059559d71
commit
3cedb8e33c
@ -299,7 +299,9 @@ fn check_repo_state(
|
|||||||
if let Ok(status) = repo.status_file(relative) {
|
if let Ok(status) = repo.status_file(relative) {
|
||||||
if status == git2::Status::CURRENT {
|
if status == git2::Status::CURRENT {
|
||||||
false
|
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.
|
// It is OK to include this file even if it is ignored.
|
||||||
status != git2::Status::IGNORED
|
status != git2::Status::IGNORED
|
||||||
} else {
|
} else {
|
||||||
|
@ -404,24 +404,18 @@ fn ignore_lockfile() {
|
|||||||
// With an explicit `include` list, but Cargo.lock in .gitignore, don't
|
// With an explicit `include` list, but Cargo.lock in .gitignore, don't
|
||||||
// complain about `Cargo.lock` being ignored. Note that it is still
|
// complain about `Cargo.lock` being ignored. Note that it is still
|
||||||
// included in the packaged regardless.
|
// included in the packaged regardless.
|
||||||
let (p, _r) = git::new_repo("foo", |p| {
|
let p = git::new("foo", |p| {
|
||||||
p.file(
|
p.file(
|
||||||
"Cargo.toml",
|
"Cargo.toml",
|
||||||
r#"
|
&pl_manifest(
|
||||||
[package]
|
"foo",
|
||||||
name = "foo"
|
"0.0.1",
|
||||||
version = "0.0.1"
|
r#"
|
||||||
authors = []
|
|
||||||
license = "MIT"
|
|
||||||
description = "foo"
|
|
||||||
documentation = "foo"
|
|
||||||
homepage = "foo"
|
|
||||||
repository = "foo"
|
|
||||||
|
|
||||||
include = [
|
include = [
|
||||||
"src/main.rs"
|
"src/main.rs"
|
||||||
]
|
]
|
||||||
"#,
|
"#,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
.file("src/main.rs", "fn main() {}")
|
.file("src/main.rs", "fn main() {}")
|
||||||
.file(".gitignore", "Cargo.lock")
|
.file(".gitignore", "Cargo.lock")
|
||||||
@ -453,3 +447,27 @@ src/main.rs
|
|||||||
)
|
)
|
||||||
.run();
|
.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();
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user