From 3fba2671d53866c9e9e12ae7d35c9f6734427964 Mon Sep 17 00:00:00 2001 From: ashokram-si <347905169+ashokram-si@users.noreply.github.com> Date: Sun, 25 Oct 2026 23:45:47 +0530 Subject: [PATCH 1/2] fix(cli): don't ignore own directory in .taurignore Closes #9163. Prevents `IgnoreMatcher` from treating `.taurignore`'s root directory as ignored when using `/*`, matching standard `.gitignore` behavior. Includes unit tests. --- .changes/fix-taurignore-root.md | 6 ++++++ crates/tauri-cli/src/interface/rust.rs | 24 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 .changes/fix-taurignore-root.md diff --git a/.changes/fix-taurignore-root.md b/.changes/fix-taurignore-root.md new file mode 100644 index 000000000000..dee6c905e26c --- /dev/null +++ b/.changes/fix-taurignore-root.md @@ -0,0 +1,6 @@ +--- +"tauri-cli": "patch:bug" +"@tauri-apps/cli": "patch:bug" +--- + +Fix `tauri dev` not watching the app at all when its `.taurignore` contains a pattern like `/*` that matches every entry at the top level, even if other entries are re-included with `!` negations. A `.taurignore` no longer ignores the directory it is in, which matches how `.gitignore` works. diff --git a/crates/tauri-cli/src/interface/rust.rs b/crates/tauri-cli/src/interface/rust.rs index b7def14b99f0..eeafae7d8df6 100644 --- a/crates/tauri-cli/src/interface/rust.rs +++ b/crates/tauri-cli/src/interface/rust.rs @@ -329,7 +329,10 @@ struct IgnoreMatcher(Vec); impl IgnoreMatcher { fn is_ignore(&self, path: &Path, is_dir: bool) -> bool { for gitignore in &self.0 { + // like git, an ignore file never ignores the directory it lives in, + // otherwise a pattern like `/*` would match the root itself if path.starts_with(gitignore.path()) + && path != gitignore.path() && gitignore .matched_path_or_any_parents(path, is_dir) .is_ignore() @@ -1792,6 +1795,27 @@ mod tests { ); } + #[test] + fn ignore_matcher_does_not_ignore_taurignore_root() { + let temp_dir = tempfile::tempdir().unwrap(); + let dir = temp_dir.path(); + fs::create_dir_all(dir.join("src")).unwrap(); + fs::create_dir_all(dir.join("assets")).unwrap(); + fs::write(dir.join("src/main.rs"), "").unwrap(); + fs::write(dir.join("Cargo.toml"), "").unwrap(); + fs::write(dir.join("README.md"), "").unwrap(); + fs::write(dir.join(".taurignore"), "/*\n!/*.toml\n!/*.rs\n!/src\n").unwrap(); + + let ignore_matcher = build_ignore_matcher(dir); + + assert!(!ignore_matcher.is_ignore(dir, true)); + assert!(!ignore_matcher.is_ignore(&dir.join("src"), true)); + assert!(!ignore_matcher.is_ignore(&dir.join("src/main.rs"), false)); + assert!(!ignore_matcher.is_ignore(&dir.join("Cargo.toml"), false)); + assert!(ignore_matcher.is_ignore(&dir.join("README.md"), false)); + assert!(ignore_matcher.is_ignore(&dir.join("assets"), true)); + } + #[test] fn parse_cargo_option() { let args = [ From db4552f06dbea03faa20466305d81d2175ed0545 Mon Sep 17 00:00:00 2001 From: Ashok Ram <347905169+ashokram-si@users.noreply.github.com> Date: Mon, 26 Oct 2026 19:56:17 +0530 Subject: [PATCH 2/2] fix(cli): keep watching folders matched by .taurignore, filter entries and events Walk every watch folder even when an ignore pattern such as `/*` matches the folder itself, and apply the ignore rules to its entries and to change events. This replaces the root special case in IgnoreMatcher::is_ignore. --- .changes/fix-taurignore-root.md | 2 +- crates/tauri-cli/src/interface/rust.rs | 74 ++++++++++++++++++-------- 2 files changed, 52 insertions(+), 24 deletions(-) diff --git a/.changes/fix-taurignore-root.md b/.changes/fix-taurignore-root.md index dee6c905e26c..52b0fb77c77c 100644 --- a/.changes/fix-taurignore-root.md +++ b/.changes/fix-taurignore-root.md @@ -3,4 +3,4 @@ "@tauri-apps/cli": "patch:bug" --- -Fix `tauri dev` not watching the app at all when its `.taurignore` contains a pattern like `/*` that matches every entry at the top level, even if other entries are re-included with `!` negations. A `.taurignore` no longer ignores the directory it is in, which matches how `.gitignore` works. +Fix `tauri dev` not watching the app at all when its `.taurignore` contains a pattern like `/*` that matches every entry at the top level, even if other entries are re-included with `!` negations. Watch folders are now always watched; ignore rules apply to their entries and to change events. diff --git a/crates/tauri-cli/src/interface/rust.rs b/crates/tauri-cli/src/interface/rust.rs index eeafae7d8df6..b13ed39eba3e 100644 --- a/crates/tauri-cli/src/interface/rust.rs +++ b/crates/tauri-cli/src/interface/rust.rs @@ -329,10 +329,7 @@ struct IgnoreMatcher(Vec); impl IgnoreMatcher { fn is_ignore(&self, path: &Path, is_dir: bool) -> bool { for gitignore in &self.0 { - // like git, an ignore file never ignores the directory it lives in, - // otherwise a pattern like `/*` would match the root itself if path.starts_with(gitignore.path()) - && path != gitignore.path() && gitignore .matched_path_or_any_parents(path, is_dir) .is_ignore() @@ -405,6 +402,26 @@ fn lookup(dir: &Path, mut f: F) { } } +/// The paths the dev watcher watches: the entries of every watch folder that the ignore files +/// don't exclude. Every folder is walked, even when a pattern such as `/*` matches the folder +/// itself; ignore rules apply to its entries here and to every change event. +fn watch_targets(watch_folders: &[PathBuf]) -> Vec<(PathBuf, RecursiveMode)> { + let mut targets = Vec::new(); + for path in watch_folders { + lookup(path, |file_type, p| { + if p != *path { + let mode = if file_type.is_dir() { + RecursiveMode::Recursive + } else { + RecursiveMode::NonRecursive + }; + targets.push((p, mode)); + } + }); + } + targets +} + fn dev_options( mobile: bool, args: &mut Vec, @@ -536,23 +553,12 @@ impl Rust { } }) .unwrap(); - for path in watch_folders { - if !ignore_matcher.is_ignore(&path, true) { - log::info!("Watching {} for changes...", display_path(&path)); - lookup(&path, |file_type, p| { - if p != path { - log::debug!("Watching {} for changes...", display_path(&p)); - let _ = watcher.watch( - &p, - if file_type.is_dir() { - RecursiveMode::Recursive - } else { - RecursiveMode::NonRecursive - }, - ); - } - }); - } + for path in &watch_folders { + log::info!("Watching {} for changes...", display_path(path)); + } + for (path, mode) in watch_targets(&watch_folders) { + log::debug!("Watching {} for changes...", display_path(&path)); + let _ = watcher.watch(&path, mode); } while let Ok(events) = rx.recv() { @@ -1795,8 +1801,7 @@ mod tests { ); } - #[test] - fn ignore_matcher_does_not_ignore_taurignore_root() { + fn taurignore_root_fixture() -> tempfile::TempDir { let temp_dir = tempfile::tempdir().unwrap(); let dir = temp_dir.path(); fs::create_dir_all(dir.join("src")).unwrap(); @@ -1805,10 +1810,33 @@ mod tests { fs::write(dir.join("Cargo.toml"), "").unwrap(); fs::write(dir.join("README.md"), "").unwrap(); fs::write(dir.join(".taurignore"), "/*\n!/*.toml\n!/*.rs\n!/src\n").unwrap(); + temp_dir + } + + #[test] + fn watch_targets_watch_a_folder_whose_taurignore_matches_it() { + let temp_dir = taurignore_root_fixture(); + let dir = temp_dir.path(); + + let mut watched: Vec = watch_targets(&[dir.to_path_buf()]) + .into_iter() + .map(|(path, _)| path.strip_prefix(dir).unwrap().to_path_buf()) + .collect(); + watched.sort(); + + assert_eq!( + watched, + vec![PathBuf::from("Cargo.toml"), PathBuf::from("src")] + ); + } + + #[test] + fn ignore_matcher_filters_events_under_a_root_wide_pattern() { + let temp_dir = taurignore_root_fixture(); + let dir = temp_dir.path(); let ignore_matcher = build_ignore_matcher(dir); - assert!(!ignore_matcher.is_ignore(dir, true)); assert!(!ignore_matcher.is_ignore(&dir.join("src"), true)); assert!(!ignore_matcher.is_ignore(&dir.join("src/main.rs"), false)); assert!(!ignore_matcher.is_ignore(&dir.join("Cargo.toml"), false));