Skip to content

Commit

Permalink
Make sure Buck2 ignores applies to directories as well as files
Browse files Browse the repository at this point in the history
Summary: Buck2 checks each ancestor when dealing with ignore configurations. Emulate that in BTD.

Reviewed By: andrewjcg

Differential Revision: D61937937

fbshipit-source-id: 5be9f60c4ddf2381058b54edf5d64caaf4b90da9
  • Loading branch information
ndmitchell authored and facebook-github-bot committed Aug 29, 2024
1 parent f1f79da commit 76df690
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion btd/src/buck/ignore_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ impl IgnoreSet {
///
/// We don't follow the implicit ignoring of buck-out, since we don't expect to see
/// any committed files in buck-out.
///
/// Differences from Buck2:
///
/// In Buck2, each directory along the path is matched, along with the file itself.
/// In BTD we only match the file itself. To map over this difference, we change
/// $X to {$X,$X/**} which will trigger the same behavior.
///
/// Buck2 actually does that for literals, even though it doesn't need to.
pub fn new_result(spec: &str) -> anyhow::Result<Self> {
let mut patterns_builder = GlobSetBuilder::new();
for val in spec.split(',') {
Expand All @@ -53,7 +61,7 @@ impl IgnoreSet {

if GLOB_CHARS.is_match(val) {
patterns_builder.add(
globset::GlobBuilder::new(val)
globset::GlobBuilder::new(&format!("{{{},{}/**}}", val, val))
.literal_separator(true)
.build()?,
);
Expand Down Expand Up @@ -85,4 +93,13 @@ mod tests {
assert!(set.is_match("extra/bar/baz/foo.txt"));
assert!(set.is_match("hello/world/file.pyc"));
}

#[test]
fn test_ignore_directory_ignore_files() {
let set = IgnoreSet::new("foo/, bar/baz/**/tests, qux/*/test");
assert!(set.is_match("bar/baz/magic/tests/file.c"));
assert!(!set.is_match("bar/baz/magic/test/file.c"));
assert!(set.is_match("qux/file/test"));
assert!(set.is_match("qux/file/test/file.c"));
}
}

0 comments on commit 76df690

Please sign in to comment.