Skip to content

Commit 85a52ce

Browse files
committed
Auto merge of #7242 - ehuss:vendor-ignore-dot, r=alexcrichton
`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.)
2 parents c3b8d1e + 492abb3 commit 85a52ce

15 files changed

+152
-210
lines changed

src/cargo/ops/vendor.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,13 @@ fn sync(
8080
if !opts.no_delete {
8181
for entry in canonical_destination.read_dir()? {
8282
let entry = entry?;
83-
to_remove.insert(entry.path());
83+
if !entry
84+
.file_name()
85+
.to_str()
86+
.map_or(false, |s| s.starts_with('.'))
87+
{
88+
to_remove.insert(entry.path());
89+
}
8490
}
8591
}
8692

tests/testsuite/clean.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,7 @@ fn clean_git() {
212212
project
213213
.file("Cargo.toml", &basic_manifest("dep", "0.5.0"))
214214
.file("src/lib.rs", "")
215-
})
216-
.unwrap();
215+
});
217216

218217
let p = project()
219218
.file(

tests/testsuite/concurrent.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,7 @@ fn git_same_repo_different_tags() {
191191
project
192192
.file("Cargo.toml", &basic_manifest("dep", "0.5.0"))
193193
.file("src/lib.rs", "pub fn tag1() {}")
194-
})
195-
.unwrap();
194+
});
196195

197196
let repo = git2::Repository::open(&a.root()).unwrap();
198197
git::tag(&repo, "tag1");
@@ -269,8 +268,7 @@ fn git_same_branch_different_revs() {
269268
project
270269
.file("Cargo.toml", &basic_manifest("dep", "0.5.0"))
271270
.file("src/lib.rs", "pub fn f1() {}")
272-
})
273-
.unwrap();
271+
});
274272

275273
let p = project()
276274
.no_manifest()
@@ -476,15 +474,13 @@ fn no_deadlock_with_git_dependencies() {
476474
project
477475
.file("Cargo.toml", &basic_manifest("dep1", "0.5.0"))
478476
.file("src/lib.rs", "")
479-
})
480-
.unwrap();
477+
});
481478

482479
let dep2 = git::new("dep2", |project| {
483480
project
484481
.file("Cargo.toml", &basic_manifest("dep2", "0.5.0"))
485482
.file("src/lib.rs", "")
486-
})
487-
.unwrap();
483+
});
488484

489485
let p = project()
490486
.file(

tests/testsuite/corrupt_git.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ fn deleting_database_files() {
1212
project
1313
.file("Cargo.toml", &basic_manifest("bar", "0.5.0"))
1414
.file("src/lib.rs", "")
15-
})
16-
.unwrap();
15+
});
1716

1817
let project = project
1918
.file(
@@ -71,8 +70,7 @@ fn deleting_checkout_files() {
7170
project
7271
.file("Cargo.toml", &basic_manifest("bar", "0.5.0"))
7372
.file("src/lib.rs", "")
74-
})
75-
.unwrap();
73+
});
7674

7775
let project = project
7876
.file(

tests/testsuite/directory.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -545,8 +545,7 @@ fn git_lock_file_doesnt_change() {
545545
let git = git::new("git", |p| {
546546
p.file("Cargo.toml", &basic_manifest("git", "0.5.0"))
547547
.file("src/lib.rs", "")
548-
})
549-
.unwrap();
548+
});
550549

551550
VendorPackage::new("git")
552551
.file("Cargo.toml", &basic_manifest("git", "0.5.0"))

tests/testsuite/doc.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1275,8 +1275,7 @@ fn doc_cap_lints() {
12751275
let a = git::new("a", |p| {
12761276
p.file("Cargo.toml", &basic_lib_manifest("a"))
12771277
.file("src/lib.rs", BAD_INTRA_LINK_LIB)
1278-
})
1279-
.unwrap();
1278+
});
12801279

12811280
let p = project()
12821281
.file(

tests/testsuite/fix.rs

+8-41
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
use std::fs::File;
22

3-
use git2;
4-
53
use crate::support::git;
64
use crate::support::{basic_manifest, clippy_is_available, is_nightly, project};
75

@@ -710,15 +708,8 @@ fn warns_if_no_vcs_detected() {
710708

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

715-
let repo = git2::Repository::init(&p.root()).unwrap();
716-
let mut cfg = t!(repo.config());
717-
t!(cfg.set_str("user.email", "[email protected]"));
718-
t!(cfg.set_str("user.name", "Foo Bar"));
719-
drop(cfg);
720-
git::add(&repo);
721-
git::commit(&repo);
722713
File::create(p.root().join("src/lib.rs")).unwrap();
723714

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

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

746-
let repo = git2::Repository::init(&p.root()).unwrap();
747-
let mut cfg = t!(repo.config());
748-
t!(cfg.set_str("user.email", "[email protected]"));
749-
t!(cfg.set_str("user.name", "Foo Bar"));
750-
drop(cfg);
751-
git::add(&repo);
752-
git::commit(&repo);
753737
File::create(&p.root().join("src/lib.rs"))
754738
.unwrap()
755739
.write_all("pub fn bar() {}".to_string().as_bytes())
@@ -776,33 +760,17 @@ commit the changes to these files:
776760

777761
#[cargo_test]
778762
fn does_not_warn_about_clean_working_directory() {
779-
let p = project().file("src/lib.rs", "pub fn foo() {}").build();
780-
781-
let repo = git2::Repository::init(&p.root()).unwrap();
782-
let mut cfg = t!(repo.config());
783-
t!(cfg.set_str("user.email", "[email protected]"));
784-
t!(cfg.set_str("user.name", "Foo Bar"));
785-
drop(cfg);
786-
git::add(&repo);
787-
git::commit(&repo);
788-
763+
let p = git::new("foo", |p| p.file("src/lib.rs", "pub fn foo() {}"));
789764
p.cargo("fix").run();
790765
}
791766

792767
#[cargo_test]
793768
fn does_not_warn_about_dirty_ignored_files() {
794-
let p = project()
795-
.file("src/lib.rs", "pub fn foo() {}")
796-
.file(".gitignore", "bar\n")
797-
.build();
769+
let p = git::new("foo", |p| {
770+
p.file("src/lib.rs", "pub fn foo() {}")
771+
.file(".gitignore", "bar\n")
772+
});
798773

799-
let repo = git2::Repository::init(&p.root()).unwrap();
800-
let mut cfg = t!(repo.config());
801-
t!(cfg.set_str("user.email", "[email protected]"));
802-
t!(cfg.set_str("user.name", "Foo Bar"));
803-
drop(cfg);
804-
git::add(&repo);
805-
git::commit(&repo);
806774
File::create(p.root().join("bar")).unwrap();
807775

808776
p.cargo("fix").run();
@@ -1267,8 +1235,7 @@ fn fix_in_existing_repo_weird_ignore() {
12671235
.file("src/lib.rs", "")
12681236
.file(".gitignore", "foo\ninner\n")
12691237
.file("inner/file", "")
1270-
})
1271-
.unwrap();
1238+
});
12721239

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

0 commit comments

Comments
 (0)