Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Fix license check triggering on worktree root entry changes (#52902)

Kirill Bulatov43ea97a2e500
diff --git a/crates/edit_prediction/src/license_detection.rs b/crates/edit_prediction/src/license_detection.rs
index 6f701d13a9d..55635bcfd04 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<regex::bytes::Regex> = 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"));