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/).
This commit is contained in:
Levi Neely 2026-07-23 08:43:39 +02:00
parent 57895bcc48
commit 5cec45d755
2 changed files with 4 additions and 32 deletions

View File

@ -116,9 +116,7 @@ project using git submodules.
A workspace is detected automatically when: A workspace is detected automatically when:
1. A directory contains a `.kateworkspace` file, **or** 1. A directory contains a `.kateworkspace` file, **or**
2. A directory contains two or more subdirectories that each have a `.git` 2. The project root contains a `.gitmodules` file (submodule monorepo)
folder (heuristic detection), **or**
3. The project root contains a `.gitmodules` file (submodule monorepo)
The `.kateworkspace` file is an INI file with a `[workspace]` section: The `.kateworkspace` file is an INI file with a `[workspace]` section:

View File

@ -2269,18 +2269,6 @@ void GitPlusPlusView::detectWorkspace()
wsFile = dir.absoluteFilePath(QStringLiteral(".kateworkspace")); wsFile = dir.absoluteFilePath(QStringLiteral(".kateworkspace"));
if (QFileInfo::exists(wsFile)) { if (QFileInfo::exists(wsFile)) {
m_workspaceDir = dir.absolutePath(); 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); const auto entries = parentDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name);
for (const auto &entry : entries) { for (const auto &entry : entries) {
QString sibPath = parentDir.absoluteFilePath(entry); QString sibPath = parentDir.absoluteFilePath(entry);
// A workspace is a dir with .kateworkspace, or a dir with 2+ git repos inside // A workspace must have .kateworkspace
bool isWs = QFileInfo::exists(sibPath + QStringLiteral("/.kateworkspace")); if (!QFileInfo::exists(sibPath + QStringLiteral("/.kateworkspace")))
if (!isWs) { continue;
// 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;
// Get branch info from the first git repo inside // Get branch info from the first git repo inside
QString branch; QString branch;