From a7e7542d70f67855ce98922933479aee0fb1dcd4 Mon Sep 17 00:00:00 2001 From: Levi Neely <141506390+lneely@users.noreply.github.com> Date: Thu, 16 Jul 2026 04:24:10 +0200 Subject: [PATCH] Fix auto-refresh: re-add file watch after atomic replace QFileSystemWatcher drops watches when git replaces index/HEAD via atomic rename. Re-add the path after each fileChanged signal. Also refresh all tabs (branches, stashes, worktrees) on fs change, not just status. --- gitplusplus.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/gitplusplus.cpp b/gitplusplus.cpp index cb3843a..273ec96 100644 --- a/gitplusplus.cpp +++ b/gitplusplus.cpp @@ -430,7 +430,7 @@ GitPlusPlusView::GitPlusPlusView(GitPlusPlusPlugin *plugin, KTextEditor::MainWin // Debounce timer for filesystem changes (avoid spamming refreshes) m_fsDebounce.setSingleShot(true); m_fsDebounce.setInterval(500); - connect(&m_fsDebounce, &QTimer::timeout, this, &GitPlusPlusView::updateStatus); + connect(&m_fsDebounce, &QTimer::timeout, this, &GitPlusPlusView::refreshAll); // Initial refresh QMetaObject::invokeMethod(this, &GitPlusPlusView::updateStatus, Qt::QueuedConnection); @@ -544,7 +544,15 @@ void GitPlusPlusView::setupFileWatcher() if (!watchPaths.isEmpty()) { m_watcher->addPaths(watchPaths); - connect(m_watcher, &QFileSystemWatcher::fileChanged, this, [this](const QString &) { + connect(m_watcher, &QFileSystemWatcher::fileChanged, this, [this](const QString &path) { + // Re-add the path: QFileSystemWatcher drops watches when files are + // replaced atomically (git writes a temp file then renames over it) + if (!m_watcher->files().contains(path)) { + QTimer::singleShot(100, this, [this, path]() { + if (QFileInfo::exists(path)) + m_watcher->addPath(path); + }); + } // Debounce: multiple changes can fire rapidly m_fsDebounce.start(); });