Skip to content

Commit 42a9f08

Browse files
committed
Make target dir self-ignoring
1 parent f15df8f commit 42a9f08

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/cargo/core/workspace.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -402,9 +402,16 @@ impl<'gctx> Workspace<'gctx> {
402402
}
403403

404404
pub fn target_dir(&self) -> Filesystem {
405-
self.target_dir
405+
let target_dir = self
406+
.target_dir
406407
.clone()
407-
.unwrap_or_else(|| self.default_target_dir())
408+
.unwrap_or_else(|| self.default_target_dir());
409+
410+
let path = target_dir.as_path_unlocked();
411+
paths::create_dir_all(path).unwrap();
412+
std::fs::write(path.join(".gitignore"), "*\n").unwrap();
413+
414+
target_dir
408415
}
409416

410417
fn default_target_dir(&self) -> Filesystem {

src/cargo/ops/cargo_new.rs

+4
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,10 @@ fn write_ignore_file(base_path: &Path, list: &IgnoreList, vcs: VersionControl) -
680680
}
681681

682682
for fp_ignore in match vcs {
683+
// TODO: Stop writing the .gitignore file by default once enough
684+
// time has passed. The target directory generated by cargo is now
685+
// self-ignoring, but the .gitignore file should still be generated
686+
// while people are still using older toolchains.
683687
VersionControl::Git => vec![base_path.join(".gitignore")],
684688
VersionControl::Hg => vec![base_path.join(".hgignore")],
685689
VersionControl::Pijul => vec![base_path.join(".ignore")],

0 commit comments

Comments
 (0)