From 2548a80e34f7c3038d0d852cb303ba110dcbb208 Mon Sep 17 00:00:00 2001 From: lucaronin Date: Tue, 3 Mar 2026 19:34:11 +0100 Subject: [PATCH] fix: use git ls-files --unmerged for reliable conflict detection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git diff --name-only --diff-filter=U only works during an active merge (while MERGE_HEAD exists). When the vault has stale conflict state — e.g. after a reboot — git diff returns empty, causing conflictFiles=[] and making the StatusBar click handler, command palette entry, and conflict resolver modal all non-functional. Switch to git ls-files --unmerged which reads unmerged index entries directly and works regardless of MERGE_HEAD state. Co-Authored-By: Claude Opus 4.6 --- src-tauri/src/git.rs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src-tauri/src/git.rs b/src-tauri/src/git.rs index 416a2039..cc41b031 100644 --- a/src-tauri/src/git.rs +++ b/src-tauri/src/git.rs @@ -427,20 +427,28 @@ pub fn git_pull(vault_path: &str) -> Result { } /// List files with merge conflicts (unmerged paths). +/// +/// Uses `git ls-files --unmerged` instead of `git diff --diff-filter=U` because +/// ls-files reliably detects unmerged index entries even when the merge state is +/// stale (e.g. after a reboot or when MERGE_HEAD is missing). pub fn get_conflict_files(vault_path: &str) -> Result, String> { let vault = Path::new(vault_path); let output = Command::new("git") - .args(["diff", "--name-only", "--diff-filter=U"]) + .args(["ls-files", "--unmerged"]) .current_dir(vault) .output() .map_err(|e| format!("Failed to check conflicts: {}", e))?; let stdout = String::from_utf8_lossy(&output.stdout); - Ok(stdout + // Each unmerged file appears multiple times (once per stage: base/ours/theirs). + // Format: " \t" + let mut files: Vec = stdout .lines() - .filter(|l| !l.is_empty()) - .map(|l| l.to_string()) - .collect()) + .filter_map(|line| line.split('\t').nth(1).map(|s| s.to_string())) + .collect(); + files.sort(); + files.dedup(); + Ok(files) } /// Parse `git pull` output to extract updated file paths.