Skip to content

Commit 53f4488

Browse files
committed
feat: add .gitignore support to fix duplicate package detection
Replace walkdir with ignore crate to respect .gitignore patterns when scanning for package manifests. This fixes the issue where packages would appear multiple times when found in both the source and target directories. Changes: - Add ignore crate dependency - Replace WalkDir with WalkBuilder in discover_members() - Configure walker to respect .gitignore, global git ignore, and .git/info/exclude - Remove unused walkdir dependency - Fix clippy warning about unnecessary map_or Fixes duplicate entries like: elf-magic: 0.2.7 elf-magic: 0.2.7 <- from target/ Now correctly shows: elf-magic: 0.2.7
1 parent 4d97c00 commit 53f4488

3 files changed

Lines changed: 116 additions & 4 deletions

File tree

Cargo.lock

Lines changed: 97 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ path = "src/bin/odo.rs"
3535
[dependencies]
3636
anyhow = "1.0.98"
3737
clap = { version = "4.5", features = ["derive"] }
38+
ignore = "0.4"
3839
json-patch = "4.0.0"
3940
semver = "1.0.26"
4041
serde = { version = "1.0", features = ["derive"] }
4142
serde_json = "1.0"
4243
toml_edit = "0.22.27"
43-
walkdir = "2.5.0"
4444

4545
[features]
4646
fixture-tests = []

src/io/mod.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ mod package_json;
33

44
use crate::domain::{Workspace, WorkspaceMember};
55
use anyhow::{Context, Result};
6+
use ignore::WalkBuilder;
67
use std::path::Path;
7-
use walkdir::WalkDir;
88

99
/// Load the current workspace from the file system
1010
///
@@ -51,8 +51,24 @@ where
5151
}
5252

5353
let mut members = Vec::new();
54-
for entry in WalkDir::new(root).into_iter().filter_map(Result::ok) {
54+
55+
// Use WalkBuilder to respect .gitignore files
56+
for result in WalkBuilder::new(root)
57+
.hidden(false) // Don't ignore hidden files by default
58+
.git_ignore(true) // Respect .gitignore files
59+
.git_global(true) // Respect global git ignore
60+
.git_exclude(true) // Respect .git/info/exclude
61+
.build()
62+
{
63+
let entry = result.with_context(|| "Failed to walk directory tree")?;
5564
let path = entry.path();
65+
66+
// Skip directories - we only care about files
67+
if entry.file_type().is_some_and(|ft| ft.is_dir()) {
68+
continue;
69+
}
70+
71+
// Apply custom ignore filter
5672
if ignore(path) {
5773
continue;
5874
}

0 commit comments

Comments
 (0)