From 5cec45d755a67f5fc45361c10973abd9f8724f94 Mon Sep 17 00:00:00 2001 From: Levi Neely Date: Thu, 23 Jul 2026 08:43:39 +0200 Subject: [PATCH] Remove heuristic workspace detection Workspace detection now relies solely on .kateworkspace marker files or .gitmodules. The heuristic (2+ sibling git repos) caused false positives when a standalone repo lived in a directory alongside other repos (e.g. ~/src/). --- README.md | 4 +--- gitplusplus.cpp | 32 +++----------------------------- 2 files changed, 4 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index 500613a..3f24170 100644 --- a/README.md +++ b/README.md @@ -116,9 +116,7 @@ project using git submodules. A workspace is detected automatically when: 1. A directory contains a `.kateworkspace` file, **or** -2. A directory contains two or more subdirectories that each have a `.git` - folder (heuristic detection), **or** -3. The project root contains a `.gitmodules` file (submodule monorepo) +2. The project root contains a `.gitmodules` file (submodule monorepo) The `.kateworkspace` file is an INI file with a `[workspace]` section: diff --git a/gitplusplus.cpp b/gitplusplus.cpp index 84bded5..76408c1 100644 --- a/gitplusplus.cpp +++ b/gitplusplus.cpp @@ -2269,18 +2269,6 @@ void GitPlusPlusView::detectWorkspace() wsFile = dir.absoluteFilePath(QStringLiteral(".kateworkspace")); if (QFileInfo::exists(wsFile)) { m_workspaceDir = dir.absolutePath(); - } else { - // Heuristic: parent dir has no .git but has 2+ child dirs with .git - if (!QFileInfo::exists(parent.absoluteFilePath(QStringLiteral(".git")))) { - int gitCount = 0; - const auto entries = parent.entryList(QDir::Dirs | QDir::NoDotAndDotDot); - for (const auto &entry : entries) { - if (QFileInfo::exists(parent.absoluteFilePath(entry + QStringLiteral("/.git")))) - ++gitCount; - } - if (gitCount >= 2) - m_workspaceDir = parent.absolutePath(); - } } } @@ -2406,23 +2394,9 @@ void GitPlusPlusView::refreshWorkspaces() const auto entries = parentDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name); for (const auto &entry : entries) { QString sibPath = parentDir.absoluteFilePath(entry); - // A workspace is a dir with .kateworkspace, or a dir with 2+ git repos inside - bool isWs = QFileInfo::exists(sibPath + QStringLiteral("/.kateworkspace")); - if (!isWs) { - // Heuristic: contains 2+ git repos and no .git at top level - if (!QFileInfo::exists(sibPath + QStringLiteral("/.git"))) { - int cnt = 0; - QDir sub(sibPath); - const auto subEntries = sub.entryList(QDir::Dirs | QDir::NoDotAndDotDot); - for (const auto &se : subEntries) { - if (QFileInfo::exists(sub.absoluteFilePath(se + QStringLiteral("/.git")))) - ++cnt; - } - isWs = (cnt >= 2); - } - } - - if (!isWs) continue; + // A workspace must have .kateworkspace + if (!QFileInfo::exists(sibPath + QStringLiteral("/.kateworkspace"))) + continue; // Get branch info from the first git repo inside QString branch;