Skip to content

Commit

Permalink
Auto merge of #7242 - ehuss:vendor-ignore-dot, r=alexcrichton
Browse files Browse the repository at this point in the history
 `cargo vendor`: Don't delete hidden top-level files.

`cargo vendor` (without `--no-delete`) will delete all files in the `vendor/` directory when it starts. This changes it so that it will skip any entries starting with a dot. This allows one to track the vendor directory with a source control system like git.

Closes #7109

(Note: two commits, one is a test change.)
  • Loading branch information
bors committed Aug 13, 2019
2 parents c3b8d1e + 492abb3 commit 85a52ce
Show file tree
Hide file tree
Showing 15 changed files with 152 additions and 210 deletions.
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
3 changes: 1 addition & 2 deletions tests/testsuite/clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,7 @@ fn clean_git() {
project
.file("Cargo.toml", &basic_manifest("dep", "0.5.0"))
.file("src/lib.rs", "")
})
.unwrap();
});

let p = project()
.file(
Expand Down
12 changes: 4 additions & 8 deletions tests/testsuite/concurrent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,7 @@ fn git_same_repo_different_tags() {
project
.file("Cargo.toml", &basic_manifest("dep", "0.5.0"))
.file("src/lib.rs", "pub fn tag1() {}")
})
.unwrap();
});

let repo = git2::Repository::open(&a.root()).unwrap();
git::tag(&repo, "tag1");
Expand Down Expand Up @@ -269,8 +268,7 @@ fn git_same_branch_different_revs() {
project
.file("Cargo.toml", &basic_manifest("dep", "0.5.0"))
.file("src/lib.rs", "pub fn f1() {}")
})
.unwrap();
});

let p = project()
.no_manifest()
Expand Down Expand Up @@ -476,15 +474,13 @@ fn no_deadlock_with_git_dependencies() {
project
.file("Cargo.toml", &basic_manifest("dep1", "0.5.0"))
.file("src/lib.rs", "")
})
.unwrap();
});

let dep2 = git::new("dep2", |project| {
project
.file("Cargo.toml", &basic_manifest("dep2", "0.5.0"))
.file("src/lib.rs", "")
})
.unwrap();
});

let p = project()
.file(
Expand Down
6 changes: 2 additions & 4 deletions tests/testsuite/corrupt_git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ fn deleting_database_files() {
project
.file("Cargo.toml", &basic_manifest("bar", "0.5.0"))
.file("src/lib.rs", "")
})
.unwrap();
});

let project = project
.file(
Expand Down Expand Up @@ -71,8 +70,7 @@ fn deleting_checkout_files() {
project
.file("Cargo.toml", &basic_manifest("bar", "0.5.0"))
.file("src/lib.rs", "")
})
.unwrap();
});

let project = project
.file(
Expand Down
3 changes: 1 addition & 2 deletions tests/testsuite/directory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -545,8 +545,7 @@ fn git_lock_file_doesnt_change() {
let git = git::new("git", |p| {
p.file("Cargo.toml", &basic_manifest("git", "0.5.0"))
.file("src/lib.rs", "")
})
.unwrap();
});

VendorPackage::new("git")
.file("Cargo.toml", &basic_manifest("git", "0.5.0"))
Expand Down
3 changes: 1 addition & 2 deletions tests/testsuite/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1275,8 +1275,7 @@ fn doc_cap_lints() {
let a = git::new("a", |p| {
p.file("Cargo.toml", &basic_lib_manifest("a"))
.file("src/lib.rs", BAD_INTRA_LINK_LIB)
})
.unwrap();
});

let p = project()
.file(
Expand Down
49 changes: 8 additions & 41 deletions tests/testsuite/fix.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use std::fs::File;

use git2;

use crate::support::git;
use crate::support::{basic_manifest, clippy_is_available, is_nightly, project};

Expand Down Expand Up @@ -710,15 +708,8 @@ fn warns_if_no_vcs_detected() {

#[cargo_test]
fn warns_about_dirty_working_directory() {
let p = project().file("src/lib.rs", "pub fn foo() {}").build();
let p = git::new("foo", |p| p.file("src/lib.rs", "pub fn foo() {}"));

let repo = git2::Repository::init(&p.root()).unwrap();
let mut cfg = t!(repo.config());
t!(cfg.set_str("user.email", "foo@bar.com"));
t!(cfg.set_str("user.name", "Foo Bar"));
drop(cfg);
git::add(&repo);
git::commit(&repo);
File::create(p.root().join("src/lib.rs")).unwrap();

p.cargo("fix")
Expand All @@ -741,15 +732,8 @@ commit the changes to these files:

#[cargo_test]
fn warns_about_staged_working_directory() {
let p = project().file("src/lib.rs", "pub fn foo() {}").build();
let (p, repo) = git::new_repo("foo", |p| p.file("src/lib.rs", "pub fn foo() {}"));

let repo = git2::Repository::init(&p.root()).unwrap();
let mut cfg = t!(repo.config());
t!(cfg.set_str("user.email", "foo@bar.com"));
t!(cfg.set_str("user.name", "Foo Bar"));
drop(cfg);
git::add(&repo);
git::commit(&repo);
File::create(&p.root().join("src/lib.rs"))
.unwrap()
.write_all("pub fn bar() {}".to_string().as_bytes())
Expand All @@ -776,33 +760,17 @@ commit the changes to these files:

#[cargo_test]
fn does_not_warn_about_clean_working_directory() {
let p = project().file("src/lib.rs", "pub fn foo() {}").build();

let repo = git2::Repository::init(&p.root()).unwrap();
let mut cfg = t!(repo.config());
t!(cfg.set_str("user.email", "foo@bar.com"));
t!(cfg.set_str("user.name", "Foo Bar"));
drop(cfg);
git::add(&repo);
git::commit(&repo);

let p = git::new("foo", |p| p.file("src/lib.rs", "pub fn foo() {}"));
p.cargo("fix").run();
}

#[cargo_test]
fn does_not_warn_about_dirty_ignored_files() {
let p = project()
.file("src/lib.rs", "pub fn foo() {}")
.file(".gitignore", "bar\n")
.build();
let p = git::new("foo", |p| {
p.file("src/lib.rs", "pub fn foo() {}")
.file(".gitignore", "bar\n")
});

let repo = git2::Repository::init(&p.root()).unwrap();
let mut cfg = t!(repo.config());
t!(cfg.set_str("user.email", "foo@bar.com"));
t!(cfg.set_str("user.name", "Foo Bar"));
drop(cfg);
git::add(&repo);
git::commit(&repo);
File::create(p.root().join("bar")).unwrap();

p.cargo("fix").run();
Expand Down Expand Up @@ -1267,8 +1235,7 @@ fn fix_in_existing_repo_weird_ignore() {
.file("src/lib.rs", "")
.file(".gitignore", "foo\ninner\n")
.file("inner/file", "")
})
.unwrap();
});

p.cargo("fix").run();
// This is questionable about whether it is the right behavior. It should
Expand Down
Loading

0 comments on commit 85a52ce

Please sign in to comment.