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.
This commit is contained in:
parent
9b1de56e97
commit
60d86ab690
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue