Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make target dir self-ignoring #15060

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/cargo/core/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,9 +402,16 @@ impl<'gctx> Workspace<'gctx> {
}

pub fn target_dir(&self) -> Filesystem {
self.target_dir
let target_dir = self
.target_dir
.clone()
.unwrap_or_else(|| self.default_target_dir())
.unwrap_or_else(|| self.default_target_dir());

let path = target_dir.as_path_unlocked();
paths::create_dir_all(path).unwrap();
std::fs::write(path.join(".gitignore"), "*\n").unwrap();

target_dir
}

fn default_target_dir(&self) -> Filesystem {
Expand Down
4 changes: 4 additions & 0 deletions src/cargo/ops/cargo_new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,10 @@ fn write_ignore_file(base_path: &Path, list: &IgnoreList, vcs: VersionControl) -
}

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