Fix branch compare: use two-dot diff, preserve +/* display prefixes

This commit is contained in:
Levi Neely 2026-07-23 16:11:38 +02:00
parent 6e8e2845a0
commit ac5af7b6d6
1 changed files with 12 additions and 5 deletions

View File

@ -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<int, QProcess::ExitStatus>::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();