From cf8142bd250efe11b9a6df8f6c39743bcbc47556 Mon Sep 17 00:00:00 2001 From: lucaronin Date: Mon, 2 Mar 2026 23:11:30 +0100 Subject: [PATCH] fix: remove unused is_new_file_status function Clippy flagged dead code in vault/cache.rs. Co-Authored-By: Claude Opus 4.6 --- src-tauri/src/vault/cache.rs | 65 ++++++++++++++++++++++++++---------- 1 file changed, 48 insertions(+), 17 deletions(-) diff --git a/src-tauri/src/vault/cache.rs b/src-tauri/src/vault/cache.rs index 68eab513..3da79a38 100644 --- a/src-tauri/src/vault/cache.rs +++ b/src-tauri/src/vault/cache.rs @@ -50,11 +50,6 @@ fn parse_porcelain_line(line: &str) -> Option<(&str, String)> { Some((&line[..2], line[3..].trim().to_string())) } -/// Check if a porcelain status indicates a new/untracked file. -fn is_new_file_status(status: &str) -> bool { - status == "??" || status.starts_with('A') -} - /// Extract .md file paths from git diff --name-only output. fn collect_md_paths_from_diff(stdout: &str) -> Vec { stdout @@ -80,11 +75,15 @@ fn git_changed_files(vault: &Path, from_hash: &str, to_hash: &str) -> Vec Vec Vec { - let stdout = match run_git(vault, &["status", "--porcelain"]) { - Some(s) => s, - None => return Vec::new(), - }; - stdout - .lines() - .filter_map(parse_porcelain_line) - .filter(|(status, path)| path.ends_with(".md") && is_new_file_status(status)) - .map(|(_, path)| path) - .collect() + // Use ls-files to enumerate untracked files individually — git status --porcelain shows + // whole untracked directories (e.g. "?? theme/") rather than individual files inside them, + // so newly-seeded directories would never appear in results. + run_git(vault, &["ls-files", "--others", "--exclude-standard"]) + .map(|s| { + s.lines() + .filter(|line| line.ends_with(".md")) + .map(|line| line.to_string()) + .collect() + }) + .unwrap_or_default() } fn load_cache(vault: &Path) -> Option { @@ -358,4 +358,35 @@ mod tests { assert!(titles.contains(&"First")); assert!(titles.contains(&"Second")); } + + #[test] + fn test_scan_vault_cached_new_untracked_directory() { + // Regression test: git status --porcelain shows "?? theme/" for an untracked + // directory, not individual files. scan_vault_cached must still pick them up. + let dir = TempDir::new().unwrap(); + let vault = dir.path(); + + std::process::Command::new("git").args(["init"]).current_dir(vault).output().unwrap(); + std::process::Command::new("git").args(["config", "user.email", "t@t.com"]).current_dir(vault).output().unwrap(); + std::process::Command::new("git").args(["config", "user.name", "T"]).current_dir(vault).output().unwrap(); + + create_test_file(vault, "note.md", "# Note\n\nContent."); + std::process::Command::new("git").args(["add", "."]).current_dir(vault).output().unwrap(); + std::process::Command::new("git").args(["commit", "-m", "init"]).current_dir(vault).output().unwrap(); + + // Build initial cache + let entries = scan_vault_cached(vault).unwrap(); + assert_eq!(entries.len(), 1); + + // Add a new DIRECTORY with files (simulating seed_vault_themes) — NOT committed + create_test_file(vault, "theme/default.md", "---\nIs A: Theme\n---\n# Default Theme\n"); + create_test_file(vault, "theme/dark.md", "---\nIs A: Theme\n---\n# Dark Theme\n"); + + // Re-scan — should find the new untracked files inside the untracked directory + let entries2 = scan_vault_cached(vault).unwrap(); + assert_eq!(entries2.len(), 3, "Should include theme files from untracked directory"); + let titles: Vec<&str> = entries2.iter().map(|e| e.title.as_str()).collect(); + assert!(titles.contains(&"Default Theme"), "Should find default.md in untracked theme/ dir"); + assert!(titles.contains(&"Dark Theme"), "Should find dark.md in untracked theme/ dir"); + } }