From 60d86ab690ec707b1213164ef7c68337cc28e804 Mon Sep 17 00:00:00 2001 From: Levi Neely Date: Wed, 22 Jul 2026 16:59:24 +0200 Subject: [PATCH] Include remote branches in workspace create auto-completion The destination completer now lists both local and remote branches (with remote prefix stripped for convenience). Fan-out logic checks for remote tracking branches: if a branch exists on a remote but not locally, creates a local tracking branch from it. --- gitplusplus.cpp | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/gitplusplus.cpp b/gitplusplus.cpp index df44a69..84bded5 100644 --- a/gitplusplus.cpp +++ b/gitplusplus.cpp @@ -2501,11 +2501,19 @@ void GitPlusPlusView::createWorkspace() QString repoPath = src.absoluteFilePath(entry); if (QFileInfo::exists(repoPath + QStringLiteral("/.git"))) { QByteArray out = GitProcess::run(repoPath, - {QStringLiteral("for-each-ref"), QStringLiteral("--format=%(refname:short)"), QStringLiteral("refs/heads/")}); + {QStringLiteral("for-each-ref"), QStringLiteral("--format=%(refname:short)"), QStringLiteral("refs/heads/"), QStringLiteral("refs/remotes/")}); const auto lines = QString::fromUtf8(out).split(QLatin1Char('\n'), Qt::SkipEmptyParts); for (const auto &line : lines) { QString b = line.trimmed(); - if (!b.isEmpty() && !branches.contains(b)) + if (b.isEmpty()) continue; + // Strip remote prefix (e.g. "origin/feature" -> "feature") + if (b.contains(QLatin1Char('/'))) { + QString stripped = b.section(QLatin1Char('/'), 1); + if (!stripped.isEmpty() && stripped != QStringLiteral("HEAD") + && !branches.contains(stripped)) + branches.append(stripped); + } + if (!branches.contains(b)) branches.append(b); } } @@ -2614,16 +2622,30 @@ void GitPlusPlusView::createWorkspace() QString sourceRepoPath = source.absoluteFilePath(repoName); QString targetRepoPath = newWsPath + QLatin1Char('/') + repoName; - // Check if branch exists in this repo + // Check if branch exists locally QByteArray branchCheck = GitProcess::run(sourceRepoPath, {QStringLiteral("rev-parse"), QStringLiteral("--verify"), QStringLiteral("refs/heads/") + name}); bool branchExists = !branchCheck.isEmpty(); + // Check if branch exists on a remote (for tracking) + QString remoteRef; + if (!branchExists) { + QByteArray remoteCheck = GitProcess::run(sourceRepoPath, + {QStringLiteral("for-each-ref"), QStringLiteral("--format=%(refname:short)"), + QStringLiteral("refs/remotes/*/") + name}); + remoteRef = QString::fromUtf8(remoteCheck).trimmed().section(QLatin1Char('\n'), 0, 0); + } + QStringList args; args << QStringLiteral("worktree") << QStringLiteral("add"); if (branchExists) { + // Local branch exists: just check it out args << targetRepoPath << name; + } else if (!remoteRef.isEmpty()) { + // Remote branch exists: create local tracking branch + args << QStringLiteral("-b") << name << targetRepoPath << remoteRef; } else { + // No branch anywhere: create new args << QStringLiteral("-b") << name << targetRepoPath; }