Git: Fix wording and availability of actions for commit range

Change-Id: Ic3a038b8246e9e6b69ae18fce519f93a685dc10c
Reviewed-by: André Hartmann <aha_1980@gmx.de>
This commit is contained in:
Orgad Shaneh
2021-12-01 11:22:02 +02:00
committed by Orgad Shaneh
parent 251b47c834
commit f02d143a81

View File

@@ -3739,22 +3739,28 @@ void GitClient::addChangeActions(QMenu *menu, const QString &source, const QStri
{ {
QTC_ASSERT(!change.isEmpty(), return); QTC_ASSERT(!change.isEmpty(), return);
const FilePath &workingDir = fileWorkingDirectory(source); const FilePath &workingDir = fileWorkingDirectory(source);
menu->addAction(tr("Cherr&y-Pick Change %1").arg(change), [workingDir, change] { const bool isRange = change.contains("..");
menu->addAction(tr("Cherr&y-Pick %1").arg(change), [workingDir, change] {
m_instance->synchronousCherryPick(workingDir, change); m_instance->synchronousCherryPick(workingDir, change);
}); });
menu->addAction(tr("Re&vert Change %1").arg(change), [workingDir, change] { menu->addAction(tr("Re&vert %1").arg(change), [workingDir, change] {
m_instance->synchronousRevert(workingDir, change); m_instance->synchronousRevert(workingDir, change);
}); });
menu->addAction(tr("C&heckout Change %1").arg(change), [workingDir, change] { if (!isRange) {
menu->addAction(tr("C&heckout %1").arg(change), [workingDir, change] {
m_instance->checkout(workingDir, change); m_instance->checkout(workingDir, change);
}); });
connect(menu->addAction(tr("&Interactive Rebase from Change %1...").arg(change)), connect(menu->addAction(tr("&Interactive Rebase from %1...").arg(change)),
&QAction::triggered, [workingDir, change] { &QAction::triggered, [workingDir, change] {
GitPlugin::startRebaseFromCommit(workingDir, change); GitPlugin::startRebaseFromCommit(workingDir, change);
}); });
QAction *logAction = menu->addAction(tr("&Log for Change %1").arg(change), [workingDir, change] { }
QAction *logAction = menu->addAction(tr("&Log for %1").arg(change), [workingDir, change] {
m_instance->log(workingDir, QString(), false, {change}); m_instance->log(workingDir, QString(), false, {change});
}); });
if (isRange) {
menu->setDefaultAction(logAction);
} else {
const FilePath filePath = FilePath::fromString(source); const FilePath filePath = FilePath::fromString(source);
if (!filePath.isDir()) { if (!filePath.isDir()) {
menu->addAction(tr("Sh&ow file \"%1\" on revision %2").arg(filePath.fileName()).arg(change), menu->addAction(tr("Sh&ow file \"%1\" on revision %2").arg(filePath.fileName()).arg(change),
@@ -3762,13 +3768,10 @@ void GitClient::addChangeActions(QMenu *menu, const QString &source, const QStri
m_instance->openShowEditor(workingDir, change, source); m_instance->openShowEditor(workingDir, change, source);
}); });
} }
if (change.contains("..")) menu->addAction(tr("Add &Tag for %1...").arg(change), [workingDir, change] {
menu->setDefaultAction(logAction);
menu->addAction(tr("Add &Tag for Change %1...").arg(change), [workingDir, change] {
QString output; QString output;
QString errorMessage; QString errorMessage;
m_instance->synchronousTagCmd(workingDir, QStringList(), m_instance->synchronousTagCmd(workingDir, QStringList(), &output, &errorMessage);
&output, &errorMessage);
const QStringList tags = output.split('\n'); const QStringList tags = output.split('\n');
BranchAddDialog dialog(tags, BranchAddDialog::Type::AddTag, Core::ICore::dialogParent()); BranchAddDialog dialog(tags, BranchAddDialog::Type::AddTag, Core::ICore::dialogParent());
@@ -3776,8 +3779,7 @@ void GitClient::addChangeActions(QMenu *menu, const QString &source, const QStri
if (dialog.exec() == QDialog::Rejected) if (dialog.exec() == QDialog::Rejected)
return; return;
m_instance->synchronousTagCmd(workingDir, m_instance->synchronousTagCmd(workingDir, {dialog.branchName(), change},
{dialog.branchName(), change},
&output, &errorMessage); &output, &errorMessage);
VcsOutputWindow::append(output); VcsOutputWindow::append(output);
if (!errorMessage.isEmpty()) if (!errorMessage.isEmpty())
@@ -3785,19 +3787,20 @@ void GitClient::addChangeActions(QMenu *menu, const QString &source, const QStri
}); });
auto resetChange = [workingDir, change](const QByteArray &resetType) { auto resetChange = [workingDir, change](const QByteArray &resetType) {
m_instance->reset( m_instance->reset(workingDir, QLatin1String("--" + resetType), change);
workingDir, QLatin1String("--" + resetType), change);
}; };
auto resetMenu = new QMenu(tr("&Reset to Change %1").arg(change), menu); auto resetMenu = new QMenu(tr("&Reset to Change %1").arg(change), menu);
resetMenu->addAction(tr("&Hard"), std::bind(resetChange, "hard")); resetMenu->addAction(tr("&Hard"), std::bind(resetChange, "hard"));
resetMenu->addAction(tr("&Mixed"), std::bind(resetChange, "mixed")); resetMenu->addAction(tr("&Mixed"), std::bind(resetChange, "mixed"));
resetMenu->addAction(tr("&Soft"), std::bind(resetChange, "soft")); resetMenu->addAction(tr("&Soft"), std::bind(resetChange, "soft"));
menu->addMenu(resetMenu); menu->addMenu(resetMenu);
}
menu->addAction(tr("Di&ff Against %1").arg(change), menu->addAction((isRange ? tr("Di&ff %1") : tr("Di&ff Against %1")).arg(change),
[workingDir, change] { [workingDir, change] {
m_instance->diffRepository(workingDir, change, {}); m_instance->diffRepository(workingDir, change, {});
}); });
if (!isRange) {
if (!m_instance->m_diffCommit.isEmpty()) { if (!m_instance->m_diffCommit.isEmpty()) {
menu->addAction(tr("Diff &Against Saved %1").arg(m_instance->m_diffCommit), menu->addAction(tr("Diff &Against Saved %1").arg(m_instance->m_diffCommit),
[workingDir, change] { [workingDir, change] {
@@ -3809,6 +3812,7 @@ void GitClient::addChangeActions(QMenu *menu, const QString &source, const QStri
m_instance->m_diffCommit = change; m_instance->m_diffCommit = change;
}); });
} }
}
FilePath GitClient::fileWorkingDirectory(const QString &file) FilePath GitClient::fileWorkingDirectory(const QString &file)
{ {