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.
This commit is contained in:
parent
ac8980a203
commit
a7e7542d70
|
|
@ -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();
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue