Git: Add tags from log window

Fixes: QTCREATORBUG-22202
Change-Id: Id6cbaf036d25fe5e9e8fcf2fe4d131649746e128
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
Andre Hartmann
2019-03-28 21:57:37 +01:00
committed by André Hartmann
parent 9dd05ec341
commit 0161729c23
5 changed files with 52 additions and 9 deletions

View File

@@ -105,14 +105,31 @@ QWidget *BranchValidationDelegate::createEditor(QWidget *parent,
return lineEdit;
}
BranchAddDialog::BranchAddDialog(const QStringList &localBranches, bool addBranch, QWidget *parent) :
BranchAddDialog::BranchAddDialog(const QStringList &localBranches, Type type, QWidget *parent) :
QDialog(parent),
m_ui(new Ui::BranchAddDialog)
{
m_ui->setupUi(this);
m_ui->trackingCheckBox->setVisible(false);
setCheckoutVisible(false);
setWindowTitle(addBranch ? tr("Add Branch") : tr("Rename Branch"));
switch (type) {
case BranchAddDialog::AddBranch:
setWindowTitle(tr("Add Branch"));
break;
case BranchAddDialog::RenameBranch:
setWindowTitle(tr("Rename Branch"));
break;
case BranchAddDialog::AddTag:
setWindowTitle(tr("Add Tag"));
m_ui->branchNameLabel->setText(tr("Tag name:"));
break;
case BranchAddDialog::RenameTag:
setWindowTitle(tr("Rename Tag"));
m_ui->branchNameLabel->setText(tr("Tag name:"));
break;
}
m_ui->branchNameEdit->setValidator(new BranchNameValidator(localBranches, this));
connect(m_ui->branchNameEdit, &QLineEdit::textChanged, this, &BranchAddDialog::updateButtonStatus);
}

View File

@@ -51,7 +51,14 @@ class BranchAddDialog : public QDialog
Q_OBJECT
public:
BranchAddDialog(const QStringList &localBranches, bool addBranch, QWidget *parent);
enum Type {
AddBranch,
RenameBranch,
AddTag,
RenameTag
};
BranchAddDialog(const QStringList &localBranches, Type type, QWidget *parent);
~BranchAddDialog() override;
void setBranchName(const QString &);

View File

@@ -313,7 +313,7 @@ bool BranchView::add()
}
}
BranchAddDialog branchAddDialog(localNames, true, this);
BranchAddDialog branchAddDialog(localNames, BranchAddDialog::Type::AddBranch, this);
branchAddDialog.setBranchName(suggestedName);
branchAddDialog.setTrackedBranchName(isTracked ? trackedBranch : QString(), !isLocal);
branchAddDialog.setCheckoutVisible(true);
@@ -444,11 +444,10 @@ bool BranchView::rename()
if (!isTag)
localNames = m_model->localBranchNames();
BranchAddDialog branchAddDialog(localNames, false, this);
if (isTag)
branchAddDialog.setWindowTitle(tr("Rename Tag"));
const BranchAddDialog::Type type = isTag ? BranchAddDialog::Type::RenameTag
: BranchAddDialog::Type::RenameBranch;
BranchAddDialog branchAddDialog(localNames, type, this);
branchAddDialog.setBranchName(oldName);
branchAddDialog.setTrackedBranchName(QString(), false);
branchAddDialog.exec();

View File

@@ -1186,7 +1186,7 @@ QStringList GitClient::setupCheckoutArguments(const QString &workingDirectory,
}
}
BranchAddDialog branchAddDialog(localBranches, true, ICore::dialogParent());
BranchAddDialog branchAddDialog(localBranches, BranchAddDialog::Type::AddBranch, ICore::dialogParent());
branchAddDialog.setTrackedBranchName(remoteBranch, true);
if (branchAddDialog.exec() != QDialog::Accepted)

View File

@@ -26,6 +26,7 @@
#include "giteditor.h"
#include "annotationhighlighter.h"
#include "branchadddialog.h"
#include "gitplugin.h"
#include "gitclient.h"
#include "gitsettings.h"
@@ -305,6 +306,25 @@ void GitEditorWidget::addChangeActions(QMenu *menu, const QString &change)
menu->addAction(tr("&Log for Change %1").arg(change), this, [this] {
GitPlugin::client()->log(sourceWorkingDirectory(), QString(), false, {m_currentChange});
});
menu->addAction(tr("Add &Tag for Change %1...").arg(change), this, [this] {
QString output;
QString errorMessage;
GitPlugin::client()->synchronousTagCmd(sourceWorkingDirectory(), QStringList(),
&output, &errorMessage);
const QStringList tags = output.split('\n');
BranchAddDialog dialog(tags, BranchAddDialog::Type::AddTag, nullptr);
if (dialog.exec() == QDialog::Rejected)
return;
GitPlugin::client()->synchronousTagCmd(sourceWorkingDirectory(),
{dialog.branchName(), m_currentChange},
&output, &errorMessage);
VcsOutputWindow::append(output);
if (!errorMessage.isEmpty())
VcsOutputWindow::append(errorMessage, VcsOutputWindow::MessageStyle::Error);
});
auto resetMenu = new QMenu(tr("&Reset to Change %1").arg(change), menu);
resetMenu->addAction(tr("&Hard"), this, [this] { resetChange("hard"); });