Fix branch compare: use two-dot diff, preserve +/* display prefixes
This commit is contained in:
parent
6e8e2845a0
commit
ac5af7b6d6
|
|
@ -1213,15 +1213,18 @@ void GitPlusPlusView::onBranchFinished(int exitCode, QProcess::ExitStatus)
|
||||||
m_remoteBranches.clear();
|
m_remoteBranches.clear();
|
||||||
QString current;
|
QString current;
|
||||||
|
|
||||||
|
QStringList worktreeBranches;
|
||||||
const auto lines = output.split('\n');
|
const auto lines = output.split('\n');
|
||||||
for (const auto &line : lines) {
|
for (const auto &line : lines) {
|
||||||
QString branch = QString::fromUtf8(line).trimmed();
|
QString branch = QString::fromUtf8(line).trimmed();
|
||||||
if (branch.isEmpty()) continue;
|
if (branch.isEmpty()) continue;
|
||||||
|
bool isWorktree = false;
|
||||||
if (branch.startsWith(QLatin1Char('*'))) {
|
if (branch.startsWith(QLatin1Char('*'))) {
|
||||||
current = branch.mid(2);
|
current = branch.mid(2);
|
||||||
branch = branch.mid(2);
|
branch = branch.mid(2);
|
||||||
} else if (branch.startsWith(QLatin1Char('+'))) {
|
} else if (branch.startsWith(QLatin1Char('+'))) {
|
||||||
branch = branch.mid(2);
|
branch = branch.mid(2);
|
||||||
|
isWorktree = true;
|
||||||
}
|
}
|
||||||
// Skip HEAD pointer in remotes
|
// Skip HEAD pointer in remotes
|
||||||
if (branch.contains(QStringLiteral(" -> "))) continue;
|
if (branch.contains(QStringLiteral(" -> "))) continue;
|
||||||
|
|
@ -1236,6 +1239,8 @@ void GitPlusPlusView::onBranchFinished(int exitCode, QProcess::ExitStatus)
|
||||||
m_allBranches.append(branch);
|
m_allBranches.append(branch);
|
||||||
if (isRemote)
|
if (isRemote)
|
||||||
m_remoteBranches.append(branch);
|
m_remoteBranches.append(branch);
|
||||||
|
if (isWorktree)
|
||||||
|
worktreeBranches.append(branch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1250,6 +1255,8 @@ void GitPlusPlusView::onBranchFinished(int exitCode, QProcess::ExitStatus)
|
||||||
QFont f = item->font();
|
QFont f = item->font();
|
||||||
f.setBold(true);
|
f.setBold(true);
|
||||||
item->setFont(f);
|
item->setFont(f);
|
||||||
|
} else if (worktreeBranches.contains(b)) {
|
||||||
|
item->setText(QStringLiteral("+ ") + b);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1657,8 +1664,8 @@ void GitPlusPlusView::compareBranch()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run git diff and show in a new document
|
// Run git diff between selected branch and current branch (two-dot = direct diff)
|
||||||
auto *proc = gitProcess({QStringLiteral("diff"), m_currentBranch + QStringLiteral("...") + branch});
|
auto *proc = gitProcess({QStringLiteral("diff"), branch + QStringLiteral("..") + m_currentBranch});
|
||||||
if (!proc) return;
|
if (!proc) return;
|
||||||
connect(proc, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
|
connect(proc, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
|
||||||
this, [this, proc, branch](int exitCode, QProcess::ExitStatus) {
|
this, [this, proc, branch](int exitCode, QProcess::ExitStatus) {
|
||||||
|
|
@ -1667,9 +1674,9 @@ void GitPlusPlusView::compareBranch()
|
||||||
if (diff.trimmed().isEmpty()) {
|
if (diff.trimmed().isEmpty()) {
|
||||||
setMessage(QStringLiteral("No differences between %1 and %2").arg(m_currentBranch, branch));
|
setMessage(QStringLiteral("No differences between %1 and %2").arg(m_currentBranch, branch));
|
||||||
} else {
|
} else {
|
||||||
showDiffOutput(diff, QStringLiteral("Diff: %1...%2").arg(m_currentBranch, branch),
|
showDiffOutput(diff, QStringLiteral("Diff: %1..%2").arg(branch, m_currentBranch),
|
||||||
{QStringLiteral("diff"), m_currentBranch + QStringLiteral("...") + branch});
|
{QStringLiteral("diff"), branch + QStringLiteral("..") + m_currentBranch});
|
||||||
setMessage(QStringLiteral("Comparing %1...%2").arg(m_currentBranch, branch));
|
setMessage(QStringLiteral("Comparing %1..%2").arg(branch, m_currentBranch));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
QString err = QString::fromUtf8(proc->readAllStandardError()).trimmed();
|
QString err = QString::fromUtf8(proc->readAllStandardError()).trimmed();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue