Skip to content

Commit 6cee10b

Browse files
author
Stefan Hoelzl
committed
variant with old behaviour but dotfiles can be included
1 parent 5c5d171 commit 6cee10b

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

src/cargo/sources/path.rs

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ impl<'cfg> PathSource<'cfg> {
147147
if let Some(result) = self.discover_git_and_list_files(pkg, root, &mut filter) {
148148
return result;
149149
}
150+
// no include option and not git repo discovered (see rust-lang/cargo#7183).
151+
return self.list_files_walk_except_dot_files_and_dirs(pkg, &mut filter);
150152
}
151153
self.list_files_walk(pkg, &mut filter)
152154
}
@@ -329,6 +331,29 @@ impl<'cfg> PathSource<'cfg> {
329331
}
330332
}
331333

334+
fn list_files_walk_except_dot_files_and_dirs(
335+
&self,
336+
pkg: &Package,
337+
filter: &mut dyn FnMut(&Path) -> CargoResult<bool>,
338+
) -> CargoResult<Vec<PathBuf>> {
339+
let root = pkg.root();
340+
let mut exclude_dot_files_dir_builder = GitignoreBuilder::new(root);
341+
exclude_dot_files_dir_builder.add_line(None, ".*")?;
342+
exclude_dot_files_dir_builder.add_line(None, "*/.*/*")?;
343+
let ignore_dot_files_and_dirs = exclude_dot_files_dir_builder.build()?;
344+
345+
let mut filter_ignore_dot_files_and_dirs = |path: &Path| -> CargoResult<bool> {
346+
let relative_path = path.strip_prefix(root)?;
347+
match ignore_dot_files_and_dirs
348+
.matched_path_or_any_parents(relative_path, /* is_dir */ false)
349+
{
350+
Match::Ignore(_) => Ok(false),
351+
_ => filter(path),
352+
}
353+
};
354+
self.list_files_walk(pkg, &mut filter_ignore_dot_files_and_dirs)
355+
}
356+
332357
fn list_files_walk(
333358
&self,
334359
pkg: &Package,
@@ -355,15 +380,6 @@ impl<'cfg> PathSource<'cfg> {
355380
if !is_root && fs::metadata(&path.join("Cargo.toml")).is_ok() {
356381
return Ok(());
357382
}
358-
// Skip dotfile directories.
359-
if path
360-
.file_name()
361-
.and_then(|s| s.to_str())
362-
.map(|s| s.starts_with('.'))
363-
== Some(true)
364-
{
365-
return Ok(());
366-
}
367383

368384
// For package integration tests, we need to sort the paths in a deterministic order to
369385
// be able to match stdout warnings in the same order.

0 commit comments

Comments
 (0)