From ac5af7b6d620ee8ce66ec55aadbb4d44a4369c31 Mon Sep 17 00:00:00 2001 From: Levi Neely Date: Thu, 23 Jul 2026 16:11:38 +0200 Subject: [PATCH] Fix branch compare: use two-dot diff, preserve +/* display prefixes --- gitplusplus.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/gitplusplus.cpp b/gitplusplus.cpp index f8a9730..e29039b 100644 --- a/gitplusplus.cpp +++ b/gitplusplus.cpp @@ -1213,15 +1213,18 @@ void GitPlusPlusView::onBranchFinished(int exitCode, QProcess::ExitStatus) m_remoteBranches.clear(); QString current; + QStringList worktreeBranches; const auto lines = output.split('\n'); for (const auto &line : lines) { QString branch = QString::fromUtf8(line).trimmed(); if (branch.isEmpty()) continue; + bool isWorktree = false; if (branch.startsWith(QLatin1Char('*'))) { current = branch.mid(2); branch = branch.mid(2); } else if (branch.startsWith(QLatin1Char('+'))) { branch = branch.mid(2); + isWorktree = true; } // Skip HEAD pointer in remotes if (branch.contains(QStringLiteral(" -> "))) continue; @@ -1236,6 +1239,8 @@ void GitPlusPlusView::onBranchFinished(int exitCode, QProcess::ExitStatus) m_allBranches.append(branch); if (isRemote) m_remoteBranches.append(branch); + if (isWorktree) + worktreeBranches.append(branch); } } @@ -1250,6 +1255,8 @@ void GitPlusPlusView::onBranchFinished(int exitCode, QProcess::ExitStatus) QFont f = item->font(); f.setBold(true); item->setFont(f); + } else if (worktreeBranches.contains(b)) { + item->setText(QStringLiteral("+ ") + b); } } @@ -1657,8 +1664,8 @@ void GitPlusPlusView::compareBranch() return; } - // Run git diff and show in a new document - auto *proc = gitProcess({QStringLiteral("diff"), m_currentBranch + QStringLiteral("...") + branch}); + // Run git diff between selected branch and current branch (two-dot = direct diff) + auto *proc = gitProcess({QStringLiteral("diff"), branch + QStringLiteral("..") + m_currentBranch}); if (!proc) return; connect(proc, QOverload::of(&QProcess::finished), this, [this, proc, branch](int exitCode, QProcess::ExitStatus) { @@ -1667,9 +1674,9 @@ void GitPlusPlusView::compareBranch() if (diff.trimmed().isEmpty()) { setMessage(QStringLiteral("No differences between %1 and %2").arg(m_currentBranch, branch)); } else { - showDiffOutput(diff, QStringLiteral("Diff: %1...%2").arg(m_currentBranch, branch), - {QStringLiteral("diff"), m_currentBranch + QStringLiteral("...") + branch}); - setMessage(QStringLiteral("Comparing %1...%2").arg(m_currentBranch, branch)); + showDiffOutput(diff, QStringLiteral("Diff: %1..%2").arg(branch, m_currentBranch), + {QStringLiteral("diff"), branch + QStringLiteral("..") + m_currentBranch}); + setMessage(QStringLiteral("Comparing %1..%2").arg(branch, m_currentBranch)); } } else { QString err = QString::fromUtf8(proc->readAllStandardError()).trimmed();