From 43ea97a2e5001e21c6ccb1f43ded8e22a9fa8b3b Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Thu, 2 Apr 2026 00:21:02 +0300 Subject: [PATCH] Fix license check triggering on worktree root entry changes (#52902) Had been seeing this for some time bad and the culprit turned out to be the fact that the regex matched empty strings. The fix changes the regex to ensure it stops matching empty strings, and patches the `log_err` callsite logic to avoid reading directories. Release Notes: - N/A --- .../edit_prediction/src/license_detection.rs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/crates/edit_prediction/src/license_detection.rs b/crates/edit_prediction/src/license_detection.rs index 6f701d13a9d4d915bbfbc2442ea5643afac30ef4..55635bcfd04cb6288f44907da051fa1f33d41922 100644 --- a/crates/edit_prediction/src/license_detection.rs +++ b/crates/edit_prediction/src/license_detection.rs @@ -21,14 +21,23 @@ use worktree::ChildEntriesOptions; static LICENSE_FILE_NAME_REGEX: LazyLock = LazyLock::new(|| { regex::bytes::RegexBuilder::new( "^ \ - (?: license | licence)? \ - (?: [\\-._]? \ + (?: \ + (?: license | licence) \ + (?: [\\-._]? \ + (?: apache (?: [\\-._] (?: 2.0 | 2 ))? | \ + 0? bsd (?: [\\-._] [0123])? (?: [\\-._] clause)? | \ + isc | \ + mit | \ + upl | \ + zlib))? \ + | \ (?: apache (?: [\\-._] (?: 2.0 | 2 ))? | \ 0? bsd (?: [\\-._] [0123])? (?: [\\-._] clause)? | \ isc | \ mit | \ upl | \ - zlib))? \ + zlib) \ + ) \ (?: [\\-._]? (?: license | licence))? \ (?: \\.txt | \\.md)? \ $", @@ -350,6 +359,9 @@ impl LicenseDetectionWatcher { return None; }; let metadata = fs.metadata(&abs_path).await.log_err()??; + if metadata.is_dir { + return None; + } if metadata.len > LICENSE_PATTERNS.approximate_max_length as u64 { log::debug!( "`{abs_path:?}` license file was skipped \ @@ -697,6 +709,7 @@ mod tests { assert!(LICENSE_FILE_NAME_REGEX.is_match(b"licence-upl.txt")); // Test non-matching patterns + assert!(!LICENSE_FILE_NAME_REGEX.is_match(b"")); assert!(!LICENSE_FILE_NAME_REGEX.is_match(b"COPYING")); assert!(!LICENSE_FILE_NAME_REGEX.is_match(b"LICENSE.html")); assert!(!LICENSE_FILE_NAME_REGEX.is_match(b"MYLICENSE"));