Git: added rename branch

Change-Id: I327a2bc91b871dc03797d9af52bb2d32be8e76d2
Reviewed-by: Tobias Hunger <tobias.hunger@digia.com>
This commit is contained in:
Petar Perisin
2013-04-05 14:31:58 +02:00
parent 1d580bcf9f
commit 0dee89bac1
6 changed files with 44 additions and 3 deletions

View File

@@ -64,6 +64,7 @@ BranchDialog::BranchDialog(QWidget *parent) :
connect(m_ui->addButton, SIGNAL(clicked()), this, SLOT(add()));
connect(m_ui->checkoutButton, SIGNAL(clicked()), this, SLOT(checkout()));
connect(m_ui->removeButton, SIGNAL(clicked()), this, SLOT(remove()));
connect(m_ui->renameButton, SIGNAL(clicked()), this, SLOT(rename()));
connect(m_ui->diffButton, SIGNAL(clicked()), this, SLOT(diff()));
connect(m_ui->logButton, SIGNAL(clicked()), this, SLOT(log()));
connect(m_ui->mergeButton, SIGNAL(clicked()), this, SLOT(merge()));
@@ -106,6 +107,7 @@ void BranchDialog::enableButtons()
const bool currentLocal = m_model->isLocal(m_model->currentBranch());
m_ui->removeButton->setEnabled(hasSelection && !currentSelected && isLocal && isLeaf);
m_ui->renameButton->setEnabled(hasSelection && isLocal && isLeaf);
m_ui->logButton->setEnabled(hasSelection && isLeaf);
m_ui->diffButton->setEnabled(hasSelection && isLeaf);
m_ui->checkoutButton->setEnabled(hasSelection && !currentSelected && isLeaf);
@@ -230,6 +232,36 @@ void BranchDialog::remove()
m_model->removeBranch(selected);
}
void BranchDialog::rename()
{
QModelIndex selected = selectedIndex();
QTC_CHECK(selected != m_model->currentBranch()); // otherwise the button would not be enabled!
QTC_CHECK(m_model->isLocal(selected)); // otherwise the button would not be enabled!
QString oldBranchName = m_model->branchName(selected);
QStringList localNames = m_model->localBranchNames();
QPointer<BranchAddDialog> branchAddDialog = new BranchAddDialog(this, false);
branchAddDialog->setBranchName(oldBranchName);
branchAddDialog->setTrackedBranchName(QString(), false);
branchAddDialog->exec();
if (!branchAddDialog.isNull() && branchAddDialog->result() == QDialog::Accepted && m_model) {
if (branchAddDialog->branchName() == oldBranchName)
return;
if (localNames.contains(branchAddDialog->branchName())) {
QMessageBox::critical(this, tr("Branch exists"),
tr("Local Branch \'%1\' already exists.")
.arg(branchAddDialog->branchName()));
return;
}
m_model->renameBranch(oldBranchName, branchAddDialog->branchName());
refresh();
}
enableButtons();
}
void BranchDialog::diff()
{
QString branchName = m_model->branchName(selectedIndex());