diff --git a/src/plugins/git/branchadddialog.cpp b/src/plugins/git/branchadddialog.cpp
index bcb16b39255..1beab9c93b2 100644
--- a/src/plugins/git/branchadddialog.cpp
+++ b/src/plugins/git/branchadddialog.cpp
@@ -95,11 +95,12 @@ private:
};
-BranchAddDialog::BranchAddDialog(QWidget *parent) :
+BranchAddDialog::BranchAddDialog(QWidget *parent, bool addBranch) :
QDialog(parent),
m_ui(new Ui::BranchAddDialog)
{
m_ui->setupUi(this);
+ setWindowTitle(addBranch ? tr("Add Branch") : tr("Rename Branch"));
m_ui->branchNameEdit->setValidator(new BranchNameValidator(this));
connect(m_ui->branchNameEdit, SIGNAL(textChanged(QString)), this, SLOT(updateButtonStatus()));
}
diff --git a/src/plugins/git/branchadddialog.h b/src/plugins/git/branchadddialog.h
index ef1088795ed..7c50d80c2a4 100644
--- a/src/plugins/git/branchadddialog.h
+++ b/src/plugins/git/branchadddialog.h
@@ -45,7 +45,7 @@ class BranchAddDialog : public QDialog
Q_OBJECT
public:
- explicit BranchAddDialog(QWidget *parent = 0);
+ explicit BranchAddDialog(QWidget *parent = 0, bool addBranch = true);
~BranchAddDialog();
void setBranchName(const QString &);
diff --git a/src/plugins/git/branchadddialog.ui b/src/plugins/git/branchadddialog.ui
index b891a7d4efe..d319d79afba 100644
--- a/src/plugins/git/branchadddialog.ui
+++ b/src/plugins/git/branchadddialog.ui
@@ -11,7 +11,7 @@
- Add Branch
+
-
diff --git a/src/plugins/git/branchdialog.cpp b/src/plugins/git/branchdialog.cpp
index e902223734e..99d315dd003 100644
--- a/src/plugins/git/branchdialog.cpp
+++ b/src/plugins/git/branchdialog.cpp
@@ -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 = 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());
diff --git a/src/plugins/git/branchdialog.h b/src/plugins/git/branchdialog.h
index 0725d00dfc5..34afa8aa559 100644
--- a/src/plugins/git/branchdialog.h
+++ b/src/plugins/git/branchdialog.h
@@ -68,6 +68,7 @@ private slots:
void add();
void checkout();
void remove();
+ void rename();
void diff();
void log();
void merge();
diff --git a/src/plugins/git/branchdialog.ui b/src/plugins/git/branchdialog.ui
index 5c9f1fd462f..e23889a3424 100644
--- a/src/plugins/git/branchdialog.ui
+++ b/src/plugins/git/branchdialog.ui
@@ -95,6 +95,13 @@
+ -
+
+
+ Re&name
+
+
+
-