mirror of
https://github.com/watchexec/watchexec.git
synced 2024-09-08 04:21:29 +02:00
Previously, when importing multiple nested ignore files, some info from the parent—notably the "root" path—would be inherited. This lead to some problems with matching of "pseudo-absolute" rules (those with a leading slash) in nested ignore files (see #745 for more details). To fix this, we now fully isolate each path of the tree during the import process. This leads to more accurate, though unfortunately slightly less performant, rule matching. The only time a builder is reused now is if two input files have the same `applies_in` value, in which case they are merged together. I have added tests to ensure correctness and prevent a regression. I also was careful to make sure no previous tests broke in any way (all changes to existing tests were made in isolation, and thus are not affected by the logic changes). As far as I can tell, the only behavior change is that now some previously-ignored rules will now be applied, which could, in very rare configurations, lead to files being unintentionally ignored. However, due to the aforementioned logic bug, those files were all ignored by git already, so I suspect the number of people actually caught off guard by this change to be extremely low, likely zero. Fixes #745.
70 lines
2.2 KiB
Rust
70 lines
2.2 KiB
Rust
mod helpers;
|
|
|
|
use helpers::ignore_tests::*;
|
|
|
|
#[tokio::test]
|
|
async fn globals() {
|
|
let filter = filt(
|
|
"tree",
|
|
&[
|
|
file("global/first").applies_globally(),
|
|
file("global/second").applies_globally(),
|
|
],
|
|
)
|
|
.await;
|
|
|
|
// Both ignores should be loaded as global
|
|
filter.agnostic_fail("/apples");
|
|
filter.agnostic_fail("/oranges");
|
|
|
|
// Sanity check
|
|
filter.agnostic_pass("/kiwi");
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn tree() {
|
|
let filter = filt("tree", &[file("tree/base"), file("tree/branch/inner")]).await;
|
|
|
|
// "oranges" is not ignored at any level
|
|
filter.agnostic_pass("tree/oranges");
|
|
filter.agnostic_pass("tree/branch/oranges");
|
|
filter.agnostic_pass("tree/branch/inner/oranges");
|
|
filter.agnostic_pass("tree/other/oranges");
|
|
|
|
// "apples" should only be ignored at the root
|
|
filter.agnostic_fail("tree/apples");
|
|
filter.agnostic_pass("tree/branch/apples");
|
|
filter.agnostic_pass("tree/branch/inner/apples");
|
|
filter.agnostic_pass("tree/other/apples");
|
|
|
|
// "carrots" should be ignored at any level
|
|
filter.agnostic_fail("tree/carrots");
|
|
filter.agnostic_fail("tree/branch/carrots");
|
|
filter.agnostic_fail("tree/branch/inner/carrots");
|
|
filter.agnostic_fail("tree/other/carrots");
|
|
|
|
// "pineapples/grapes" should only be ignored at the root
|
|
filter.agnostic_fail("tree/pineapples/grapes");
|
|
filter.agnostic_pass("tree/branch/pineapples/grapes");
|
|
filter.agnostic_pass("tree/branch/inner/pineapples/grapes");
|
|
filter.agnostic_pass("tree/other/pineapples/grapes");
|
|
|
|
// "cauliflowers" should only be ignored at the root of "branch/"
|
|
filter.agnostic_pass("tree/cauliflowers");
|
|
filter.agnostic_fail("tree/branch/cauliflowers");
|
|
filter.agnostic_pass("tree/branch/inner/cauliflowers");
|
|
filter.agnostic_pass("tree/other/cauliflowers");
|
|
|
|
// "artichokes" should be ignored anywhere inside of "branch/"
|
|
filter.agnostic_pass("tree/artichokes");
|
|
filter.agnostic_fail("tree/branch/artichokes");
|
|
filter.agnostic_fail("tree/branch/inner/artichokes");
|
|
filter.agnostic_pass("tree/other/artichokes");
|
|
|
|
// "bananas/pears" should only be ignored at the root of "branch/"
|
|
filter.agnostic_pass("tree/bananas/pears");
|
|
filter.agnostic_fail("tree/branch/bananas/pears");
|
|
filter.agnostic_pass("tree/branch/inner/bananas/pears");
|
|
filter.agnostic_pass("tree/other/bananas/pears");
|
|
}
|