Skip to content

Commit

Permalink
cargo vendor: Don't delete hidden top-level files.
Browse files Browse the repository at this point in the history
  • Loading branch information
ehuss committed Aug 13, 2019
1 parent 3c20a24 commit 492abb3
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/cargo/ops/vendor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,13 @@ fn sync(
if !opts.no_delete {
for entry in canonical_destination.read_dir()? {
let entry = entry?;
to_remove.insert(entry.path());
if !entry
.file_name()
.to_str()
.map_or(false, |s| s.starts_with('.'))
{
to_remove.insert(entry.path());
}
}
}

Expand Down
36 changes: 36 additions & 0 deletions tests/testsuite/vendor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -501,3 +501,39 @@ fn depend_on_vendor_dir_not_deleted() {
p.cargo("vendor --respect-source-config").run();
assert!(p.root().join("vendor/libc").is_dir());
}

#[cargo_test]
fn ignore_hidden() {
// Don't delete files starting with `.`
Package::new("bar", "0.1.0").publish();
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "1.0.0"
[dependencies]
bar = "0.1.0"
"#,
)
.file("src/lib.rs", "")
.build();
p.cargo("vendor --respect-source-config").run();
// Add a `.git` directory.
let repo = git::init(&p.root().join("vendor"));
git::add(&repo);
git::commit(&repo);
assert!(p.root().join("vendor/.git").exists());
// Vendor again, shouldn't change anything.
p.cargo("vendor --respect-source-config").run();
// .git should not be removed.
assert!(p.root().join("vendor/.git").exists());
// And just for good measure, make sure no files changed.
let mut opts = git2::StatusOptions::new();
assert!(repo
.statuses(Some(&mut opts))
.unwrap()
.iter()
.all(|status| status.status() == git2::Status::CURRENT));
}

0 comments on commit 492abb3

Please sign in to comment.