Git: Support remove/rename for tags

Change-Id: I737d2405ef1a10ec451c4baceaea9a0bc194ac1e
Reviewed-by: Tobias Hunger <tobias.hunger@digia.com>
This commit is contained in:
Orgad Shaneh
2013-06-23 22:17:22 +03:00
committed by Orgad Shaneh
parent 0ae3d29a66
commit ffdd317773
5 changed files with 100 additions and 23 deletions

View File

@@ -104,10 +104,11 @@ void BranchDialog::enableButtons()
const bool currentSelected = hasSelection && idx == m_model->currentBranch();
const bool isLocal = m_model->isLocal(idx);
const bool isLeaf = m_model->isLeaf(idx);
const bool isTag = m_model->isTag(idx);
const bool hasActions = hasSelection && isLeaf;
m_ui->removeButton->setEnabled(hasActions && !currentSelected && isLocal);
m_ui->renameButton->setEnabled(hasActions && isLocal);
m_ui->removeButton->setEnabled(hasActions && !currentSelected && (isLocal || isTag));
m_ui->renameButton->setEnabled(hasActions && (isLocal || isTag));
m_ui->logButton->setEnabled(hasActions);
m_ui->diffButton->setEnabled(hasActions);
m_ui->checkoutButton->setEnabled(hasActions && !currentSelected);
@@ -227,33 +228,47 @@ void BranchDialog::remove()
if (branchName.isEmpty())
return;
QString message = tr("Would you like to delete the branch '%1'?").arg(branchName);
bool wasMerged = m_model->branchIsMerged(selected);
if (!wasMerged)
message = tr("Would you like to delete the <b>unmerged</b> branch '%1'?").arg(branchName);
const bool isTag = m_model->isTag(selected);
const bool wasMerged = isTag ? true : m_model->branchIsMerged(selected);
QString message = tr("Would you like to delete the %1 '%2'?");
if (isTag)
message = message.arg(tr("tag"));
else
message = message.arg(wasMerged ? tr("branch") : tr("<b>unmerged</b> branch"));
message = message.arg(branchName);
if (QMessageBox::question(this, tr("Delete Branch"), message, QMessageBox::Yes|QMessageBox::No,
wasMerged ? QMessageBox::Yes : QMessageBox::No) == QMessageBox::Yes)
m_model->removeBranch(selected);
if (QMessageBox::question(this, isTag ? tr("Delete Tag") : tr("Delete Branch"),
message, QMessageBox::Yes | QMessageBox::No,
wasMerged ? QMessageBox::Yes : QMessageBox::No) == QMessageBox::Yes) {
if (isTag)
m_model->removeTag(selected);
else
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!
const bool isTag = m_model->isTag(selected);
QTC_CHECK(m_model->isLocal(selected) || isTag);
QString oldBranchName = m_model->branchName(selected);
QStringList localNames = m_model->localBranchNames();
QString oldName = m_model->branchName(selected);
QStringList localNames;
if (!isTag)
localNames = m_model->localBranchNames();
BranchAddDialog branchAddDialog(false, this);
branchAddDialog.setBranchName(oldBranchName);
if (isTag)
branchAddDialog.setWindowTitle(tr("Rename Tag"));
branchAddDialog.setBranchName(oldName);
branchAddDialog.setTrackedBranchName(QString(), false);
branchAddDialog.exec();
if (branchAddDialog.result() == QDialog::Accepted && m_model) {
if (branchAddDialog.branchName() == oldBranchName)
if (branchAddDialog.branchName() == oldName)
return;
if (localNames.contains(branchAddDialog.branchName())) {
QMessageBox::critical(this, tr("Branch Exists"),
@@ -261,7 +276,10 @@ void BranchDialog::rename()
.arg(branchAddDialog.branchName()));
return;
}
m_model->renameBranch(oldBranchName, branchAddDialog.branchName());
if (isTag)
m_model->renameTag(oldName, branchAddDialog.branchName());
else
m_model->renameBranch(oldName, branchAddDialog.branchName());
refresh();
}
enableButtons();